0.0.2 • Published 6 months ago

@chtsinc/ch-logger v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

README.md md Copy Edit

ch-logger

A reusable, Winston-based logging utility for Node.js/TypeScript packages at CH. Supports:

  • Console logging by default
  • Optional file logging via environment variables
  • Log level control via LOG_LEVEL
  • Custom logger injection for full flexibility

šŸš€ Installation

npm install ch-logger

šŸ“¦ Usage
āœ… Default Logger (Console)
ts
import { getLogger } from 'ch-logger';
const logger = getLogger();
logger.info('Hello from ch-logger!');

šŸ” Custom Logger Injection
ts

import winston from 'winston';
import { getLogger } from 'ch-logger';

const custom = winston.createLogger({
  level: 'debug',
  transports: [new winston.transports.Console()]
});

const logger = getLogger(custom);
logger.debug('Using injected logger');
āš™ļø Environment Variables
You can control logging behavior using .env or process.env:

Variable	Description	Example
LOG_LEVEL	Sets log level (debug, info, etc.)	LOG_LEVEL=debug
LOG_TO_FILE	Enables file logging (true or false)	LOG_TO_FILE=true
LOG_FILE	Log file path (default: app.log)	LOG_FILE=logs/app.log
šŸ“ Output Example

2025-04-16T13:45:33.125Z [INFO] Starting ch-uploader...
2025-04-16T13:45:34.456Z [DEBUG] Uploading file: invoice.pdf
.