Skip to content

About

Powerful and colorful logging for Node.js — console or file-based!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Logginglog

Powerful and colorful logging for Node.js — console or file-based!

Installation

npm install logginglog

Usage

import logginglog from 'logginglog';

const logger = logginglog.createLogger();

logger.log('Hello world!');
logger.info('Information');
logger.warn('Warning');
logger.error('Error message');

Custom logger with color and styles

const custom = logginglog.customLogger('MyLogger', {
  color: 'blue',
  styles: ['bold', 'underline']
});

custom('A custom log line');

Supported styles

For regular Chalk colors:

  • bold
  • italic
  • underline
  • dim

Supported colors

All colors provided by chalk-extra, including:

  • red
  • green
  • blue
  • cyan
  • yellow
  • magenta
  • rainbow
  • zebra
  • trap
  • random

The rainbow, zebra, trap, and random styles do not apply additional styles such as bold or italic.

Log to file

Logging to a file is handled through createLogger().

Console and file

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');

File only

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.

Options

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

Logging values

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.

License

GNU General Public License v3.0

About

Powerful and colorful logging for Node.js — console or file-based!

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages