Thanks to visit codestin.com
Credit goes to github.com

Skip to content

joseberna/Logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@joseberna/logger

A professional, cross-platform logger for Node.js and Browser environments. It supports service-based context, colors, and log levels.

Features

  • Cross-Platform: Works in Node.js (via chalk) and Browsers (using console styling).
  • 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.

Installation

npm install @joseberna/logger
# or
yarn add @joseberna/logger

Usage

Basic Usage

import 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');

Log Levels

  • info: General informational messages.
  • error: Error messages.
  • warn: Warning messages.
  • success: Success messages.
  • debug: Debug messages (only visible if debugMode is true or NODE_ENV is not production).

Configuration

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'
  }
});

Extending / Multiple Instances

You can import the Logger class to create separate instances.

import { Logger } from '@joseberna/logger';

const myLogger = new Logger({
  debugMode: true
});

Browser Support

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.

About

Cross-platform logger for backend and frontend with service context and colors

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published