@yyberi/logger
A lightweight wrapper around pino for structured, level-based logging in both development and production environments.
Installation
npm install @yyberi/logger
Features
- Root & child loggers keyed by service or module name
- Automatic environment detection (
NODE_ENV) for console pretty-printing in development and file-based logging in production
- Customizable log levels via the
LogLevel enum
- ISO timestamps in production logs
- Configurable log directory via the
LOG_DIR environment variable
Usage
import getLogger, { LogLevel } from '@yyberi/logger';
const logger = getLogger();
const customLogger = getLogger('my-service');
logger.setLogLevel(LogLevel.INFO);
logger.info('Application started');
const authLogger = logger.child({ name: 'auth' });
authLogger.debug('Checking user credentials');
Configuration
API Reference
getLogger(serviceName?) | Get or create a root logger |
logger.child(bindings) | Create a child logger with metadata |
logger.setLogLevel(lvl) | Dynamically adjust log level |
logger.fatal(...), error, warn, info, debug | Log at the specified level |
Environment Variables
LOG_DIR — Directory where app.log will be stored (defaults to ./logs)
NODE_ENV — Determines production vs development behavior
npm_package_version — Automatically picked up from your package.json for metadata
Tips & Caveats
- The
logs directory will be created automatically if it does not exist.
- Production logs are written asynchronously; buffered logs may be lost if the process exits abruptly.
- The timestamp override yields ISO-formatted strings; no further configuration needed.
Keywords
log, logging, logger, pino, pino-pretty
License
This project is licensed under the MIT License. Feel free to use and modify as needed.