@teliagen/logger
v0.4.2
Published
Logging utility for Teliagen Framework
Readme
@teliagen/logger
Logging utility for the Teliagen Framework.
Overview
@teliagen/logger provides a lightweight, colorful logging utility with:
- Log Levels – Debug, Info, Warn, Error
- Colorized Output – Easy-to-read console output
- Context Tags – Module/component prefixes
- Symbols – Visual indicators for status
- Environment-Aware – Auto-adjusts based on NODE_ENV
Installation
npm install @teliagen/logger
# or
pnpm add @teliagen/loggerQuick Start
import { Logger } from '@teliagen/logger';
Logger.info('Server', 'Server started on port 3000');
Logger.debug('Database', 'Connected to PostgreSQL');
Logger.warn('Auth', 'Token expires in 5 minutes');
Logger.error('Payment', 'Payment processing failed', new Error('Timeout'));API
Log Methods
// Info - General information
Logger.info(context: string, message: string, ...args: any[]);
// Debug - Development/debugging information
Logger.debug(context: string, message: string, ...args: any[]);
// Warn - Warning messages
Logger.warn(context: string, message: string, ...args: any[]);
// Error - Error messages
Logger.error(context: string, message: string, error?: Error);Examples
import { Logger } from '@teliagen/logger';
// Basic usage
Logger.info('App', 'Application started');
// [App] Application started
Logger.debug('DB', 'Query executed', { table: 'users', rows: 42 });
// [DB] Query executed { table: 'users', rows: 42 }
Logger.warn('Cache', 'Cache miss for key: user-123');
// [Cache] ⚠ Cache miss for key: user-123
Logger.error('API', 'Request failed', new Error('Network error'));
// [API] ✖ Request failed
// Error: Network error
// at ...Symbols
Logger.symbols = {
SUCCESS: '✔',
ERROR: '✖',
WARNING: '⚠',
INFO: 'ℹ',
ARROW: '→',
BULLET: '•'
};
// Use in messages
Logger.info('Plugin', `${Logger.symbols.SUCCESS} Plugin installed successfully`);
Logger.error('Auth', `${Logger.symbols.ERROR} Authentication failed`);Log Level Control
// Set minimum log level
Logger.setLevel('info'); // Options: 'debug', 'info', 'warn', 'error', 'silent'
// Debug logs will be hidden
Logger.debug('Test', 'This will not show');
Logger.info('Test', 'This will show');
// Disable all logging
Logger.setLevel('silent');Environment Detection
// Automatically adjusts based on NODE_ENV
// - development: debug level, full colors
// - production: info level, simplified output
// - test: warn level, minimal output
// Override with environment variable
// LOG_LEVEL=debug node app.jsUsage in Teliagen
The Logger is used throughout the Teliagen framework:
import { Logger } from '@teliagen/logger';
// In plugins
class MyPlugin {
install(app) {
Logger.info('MyPlugin', 'Installing plugin...');
// ...
Logger.info('MyPlugin', `${Logger.symbols.SUCCESS} Plugin installed`);
}
}
// In actions
class UserActions {
async createUser(input) {
Logger.debug('UserActions', 'Creating user', { email: input.email });
const user = await User.create(input);
Logger.info('UserActions', `User created: ${user.id}`);
return user;
}
}
// In middleware/hooks
app.registerGlobalHook('before', async (ctx) => {
Logger.debug('Hook', `${Logger.symbols.ARROW} ${ctx.actionName}`);
});Output Format
[Context] Message
[Context] ✔ Success message
[Context] ⚠ Warning message
[Context] ✖ Error messageWith colors:
- Context: Cyan
- Info: Default
- Debug: Gray
- Warn: Yellow
- Error: Red
Requirements
- Node.js >= 18.0.0
Documentation
For full documentation, visit docs.teliagen.org.
License
Apache-2.0
