Abstraction over using console.log with priority levels
This module is distributed via github npm registry (GitHub Packages) which is bundled with node and
should be installed as one of your project's dependencies. See more about work with Github Packages and installing a package:
npm install @bipboys/logger
You can use logger functions directly without creating an instance. By default, all log levels are enabled:
import {error, info, warn, debug, verbose, log, trace} from '@bipboys/logger';
error('test error');
info('test info');
verbose('test verbose');
warn('test warn');
log('test log');
debug('test debug');
trace('test trace');-------------------------------
Priority - DEFAULT
-------------------------------
[ERROR] 52:02.40 default test error
[INFO] 52:02.40 default test info
[VERBOSE] 52:02.40 default test verbose
[WARN] 52:02.40 default test warn
[INFO] 52:02.40 default test log
[DEBUG] 52:02.40 default test debug
[TRACE] 52:02.41 default test traceYou can create named logger instances for different parts of your application:
import {make, error, info, warn} from '@bipboys/logger';
// Create a logger with specific name and log level
const logger = make('MyApp', 'DEBUG');
// The logger instance contains name and level information
console.log(logger); // { name: 'MyApp', level: 'DEBUG' }This is useful when you want to differentiate log output from different components in your application.
The logger supports 6 priority levels from lowest to highest:
- VERBOSE - Most verbose output
- DEBUG - Debugging information
- INFO - General information
- WARN - Warning messages
- ERROR - Error messages
- TRACE - Tracing information
Only messages with priority equal to or higher than the configured level will be displayed.
TypeScript types are automatically generated from ReScript code. Import types from the generated file:
import type {logLevel, consoleLoggerType} from '@bipboys/logger';
import {make, error, info, warn} from '@bipboys/logger';
const logger: consoleLoggerType = make('MyApp', 'DEBUG');
error('test error');
info('test info');See the example file for a complete usage example.