@akadenia/logger
A flexible and extensible logging library for TypeScript applications, part of the Akadenia ecosystem.
Features
- Multiple Logging Levels: Trace, Debug, Info, Warn, Error with configurable minimum levels
- Extensible Adapter System: Support for different logging backends and services
- Built-in Console Logging: Configurable console output with level filtering
- Predefined Events: Common logging scenarios like Login, Share, AppOpen, Search
- Exception Handling: Automatic stack trace capture and error logging
- Metadata Support: Rich context with extra data and metadata
- Multiple Adapters: Built-in support for Sentry, SignOz, Azure Functions, and Firebase
- TypeScript Support: Full type definitions and type safety
Table of Contents
- Installation
- Quick Start
- Configuration
- Logging Levels
- Predefined Events
- Adapters
- Development
- Contributing
- License
Installation
npm install @akadenia/loggerQuick Start
import { Logger, Severity } from '@akadenia/logger';
// Create a logger instance
const logger = new Logger({
consoleEnabled: true,
consoleMinimumLogLevel: Severity.Info
});
// Basic logging
logger.info('Application started');
logger.error('An error occurred');
// Logging with extra data
logger.debug('User action', { extraData: { userId: '123', action: 'click' } });
// Exception logging
try {
// Some code that might throw
} catch (error) {
logger.exception('Failed to process request', error as Error);
}Configuration
The logger can be configured with the following options:
type Config = {
consoleEnabled?: boolean; // Enable/disable console logging
consoleMinimumLogLevel?: Severity; // Minimum level for console output
}Logging Levels
The logger supports the following severity levels (in ascending order):
Trace- Most detailed loggingDebug- Detailed information for debuggingInfo- General information about application flowWarn- Warning messages for potential issuesError- Error messages for actual problems
Predefined Events
The logger includes predefined events for common scenarios:
enum PredefinedLogEvents {
Login = "LOGIN",
Share = "SHARE",
AppOpen = "APP_OPEN",
Search = "SEARCH"
}Example usage:
logger.predefinedEvent({
type: PredefinedLogEvents.Login,
extraData: { userId: '123' }
});
logger.predefinedEvent({
type: PredefinedLogEvents.Search,
extraData: { searchTerm: 'query' }
});Adapters
Sentry Adapter
For error tracking and monitoring:
import { SentryAdapter } from '@akadenia/logger/adapters';
const sentryAdapter = new SentryAdapter({
dsn: 'your-sentry-dsn'
});
logger.addLogger(sentryAdapter);SignOz Adapter
For application monitoring:
import { SignOzAdapter } from '@akadenia/logger/adapters';
const signOzAdapter = new SignOzAdapter({
// SignOz configuration
});
logger.addLogger(signOzAdapter);Azure Functions Adapter
For Azure Functions logging:
import { AzureFunctionsAdapter } from '@akadenia/logger/adapters';
const azureAdapter = new AzureFunctionsAdapter(context);
logger.addLogger(azureAdapter);Firebase Adapter
For Firebase logging:
import { FirebaseAdapter } from '@akadenia/logger/adapters';
const firebaseAdapter = new FirebaseAdapter({
// Firebase configuration
});
logger.addLogger(firebaseAdapter);Development
Building
npm run buildTesting
npm testFormatting
npm run formatLinting
npm run lintContributing
We welcome contributions! Please feel free to submit a Pull Request.
Development Setup
git clone https://github.com/akadenia/AkadeniaLogger.git
cd AkadeniaLogger
npm install
npm run build
npm testCommit Message Guidelines
We follow Conventional Commits for our semantic release process. We prefer commit messages to include a scope in parentheses for better categorization and changelog generation.
Preferred Format
type(scope): description
[optional body]
[optional footer]
Examples
## ✅ Preferred - with scope
feat(adapters): add new Sentry adapter configuration
fix(logger): resolve exception handling issue
docs(readme): add troubleshooting section
chore(deps): update dependencies
## ❌ Less preferred - without scope
feat: add new Sentry adapter configuration
fix: resolve exception handling issue
docs: add troubleshooting section
chore: update dependenciesCommon Scopes
logger- Core logger functionalityadapters- Adapter implementationsevents- Predefined event handlingdocs- Documentation updatesdeps- Dependency updatestest- Test-related changesbuild- Build and build toolingci- CI/CD configuration
Commit Types
feat- New featuresfix- Bug fixesdocs- Documentation changesstyle- Code style changes (formatting, etc.)refactor- Code refactoringtest- Adding or updating testschore- Maintenance tasks
License
Support
For support, please open an issue on GitHub.