A simple Winston wrapper that provides a pre-configured singleton logger with console and file transports.
NODE_ENV !== 'production'addLog()format, transports, and Winston exports for advanced useyarn add @gibme/logger
or
npm install @gibme/logger
import Logger from '@gibme/logger';
Logger.info('Application started');
Logger.debug('Debug details here');
Logger.warn('Something looks off');
Logger.error('Something went wrong');
File logging is disabled by default. Enable it at runtime or via environment variable:
// Enable the default file transport at runtime
Logger.enableDefaultLog();
// Disable it again
Logger.disableDefaultLog();
// Add a custom log file with a specific level
Logger.addLog('errors.log', 'error');
// Specify a custom path
Logger.addLog('audit.log', 'info', '/var/log/myapp');
Configuration is handled through environment variables (with dotenv support):
| Variable | Default | Description |
|---|---|---|
NODE_ENV |
— | When set to production, console output is limited to info level and above |
ENABLE_DEFAULT_LOG |
false |
Set to true to enable the default file transport on startup |
LOG_PATH |
./logs/ |
Directory for log files |
LOG_FILENAME |
info.log |
Filename for the default file transport |
LOG_CREATE_PATH |
true |
Set to false to skip automatic creation of the log directory |
| Property | Type | Description |
|---|---|---|
Logger.path |
string |
The resolved default log directory path |
Logger.defaultFilename |
string |
The default log filename |
Logger.defaultFilenamePath |
string |
The full resolved path to the default log file |
The package re-exports Winston internals for advanced configuration:
import Logger, { Winston, transports, format } from '@gibme/logger';
Full API documentation is available at https://gibme-npm.github.io/logger/.
MIT - see LICENSE for details.