A lightweight wrapper around pino for structured, level-based logging in both development and production environments.
npm install @yyberi/logger- 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
LogLevelenum - ISO timestamps in production logs
- Configurable log directory via the
LOG_DIRenvironment variable
import getLogger, { LogLevel } from '@yyberi/logger';
// Root logger (defaults to service name '@yyberi/logger')
const logger = getLogger();
// Optionally set a specific service name:
const customLogger = getLogger('my-service');
// Set global log level
logger.setLogLevel(LogLevel.INFO);
logger.info('Application started');
// Create a module-specific child logger
const authLogger = logger.child({ name: 'auth' });
authLogger.debug('Checking user credentials');-
NODE_ENV=production- Logs to file at
$LOG_DIR/app.log(defaults to./logs/app.log) with levelinfoand above - Outputs JSON with fields:
timestamp,env,version,service, plus the logmessage
- Logs to file at
-
NODE_ENVnot set or anything else- Logs to console with colors and single-line pretty printing
- Ignores
serviceandmodulefields in pretty output (shown as prefix)
| Method | Description |
|---|---|
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 |
LOG_DIR— Directory whereapp.logwill be stored (defaults to./logs)NODE_ENV— Determines production vs development behaviornpm_package_version— Automatically picked up from yourpackage.jsonfor metadata
- The
logsdirectory 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.
log, logging, logger, pino, pino-pretty
This project is licensed under the MIT License. Feel free to use and modify as needed.