Powerful and colorful logging for Node.js — console or file-based!
npm install logginglogimport logginglog from 'logginglog';
const logger = logginglog.createLogger();
logger.log('Hello world!');
logger.info('Information');
logger.warn('Warning');
logger.error('Error message');const custom = logginglog.customLogger('MyLogger', {
color: 'blue',
styles: ['bold', 'underline']
});
custom('A custom log line');For regular Chalk colors:
bolditalicunderlinedim
All colors provided by chalk-extra, including:
redgreenbluecyanyellowmagentarainbowzebratraprandom
The rainbow, zebra, trap, and random styles do not apply additional styles such as bold or italic.
Logging to a file is handled through createLogger().
const logger = logginglog.createLogger({
file: true,
filePath: './mylogs.txt'
});
logger.log('This line goes to the console and file.');
logger.info('Information');
logger.warn('Warning');
logger.error('Error');const fileLogger = logginglog.createLogger({
console: false,
file: true,
filePath: './mylogs.txt'
});
fileLogger.log('This line will only be written to the file.');File logs contain timestamps and are written without ANSI color codes.
createLogger() accepts the following options:
| Option | Type | Default | Description |
|---|---|---|---|
underline |
boolean |
true |
Underlines log messages |
console |
boolean |
true |
Enables console logging |
file |
boolean |
false |
Enables file logging |
filePath |
string |
'log.txt' |
Path to the log file |
Logger methods accept strings, objects, and Error objects.
logger.info({
message: 'Object logging works',
value: 42
});
logger.error(new Error('Something went wrong'));Objects are serialized as JSON, while Error objects log their message without the stack trace.
GNU General Public License v3.0