A professional, cross-platform logger for Node.js and Browser environments. It supports service-based context, colors, and log levels.
- Cross-Platform: Works in Node.js (via
chalk) and Browsers (usingconsolestyling). - Context-Aware: Easily attach service names and method names to logs.
- Color-Coded: distinct colors for different services and log levels.
- TypeScript Support: First-class type definitions included.
- Configurable: Enable/disable debug mode, override colors.
npm install @joseberna/logger
# or
yarn add @joseberna/loggerimport logger from '@joseberna/logger';
// Simple log
logger.info('Server started');
// Log with Context
logger.info('Processing transaction', {
service: 'PaymentService',
method: 'processCharge',
txHash: '0x123...'
});
// Error log
logger.error('Database connection failed', { service: 'Database' });
// Success log
logger.success('Deployment successful');info: General informational messages.error: Error messages.warn: Warning messages.success: Success messages.debug: Debug messages (only visible ifdebugModeis true orNODE_ENVis not production).
You can configure the logger instance:
import logger from '@joseberna/logger';
// Enable debug mode explicitly
logger.setConfig({ debugMode: true });
// Override service colors
logger.setConfig({
serviceColors: {
'MyCustomService': '#FF0000'
}
});You can import the Logger class to create separate instances.
import { Logger } from '@joseberna/logger';
const myLogger = new Logger({
debugMode: true
});When bundled for the browser (e.g., via Vite, Webpack), the package automatically swaps the implementation to use browser console methods with CSS styling, avoiding any Node.js dependencies like chalk.