1.0.2 • Published 3 years ago

@mazeltov/logger v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

General Logger

console.log is okay for playing around, but a serious logger provides:

  • Log levels (error, warn, info, debug)
  • Multiple transports (stdout, file)
  • File rotation
  • Clear indications where the logger printed

So this is a lot to set up per project which is why a re-usable catch all was made

Basic Usage

// load .env file. See Configuration
require('dotenv').config();

const loggerLib = require('@mazeltov/logger');

// then multiple loggers can be produced for each file
const logger = loggerLib('distinct log identifier');

// then elsewhere in another file
const logger2 = loggerLib('different identifier');

Configuring

This logger depends on your project using dotenv.

In .env file (these are default values)

LOG_LEVEL=info

# comma separated list. stdout, file
LOG_TRANSPORTS=stdout

# will only log to file if file is included as transport
LOG_DIR='./log'

# See Tabbing
LOG_TAB_CHAR='..'
LOG_MAX_TAB=4

# Default is pipe delimited but JSON format can be used
LOG_FORMAT=json

Tabbing

Something unique about this wrapper is that you can 'tab' and 'untab' your log output.

That way you don't have to prepend everything with \\t. Just be sure to untab with shiftTab

logger.info('Diving into the code:');
logger.tab();
logger.info('This code is indented');
logger.info('So is this code');
// do not forget this!
logger.shiftTab();

Roadmap

TODO

  • Logger may need some performance tweaks
  • Logger does not have remote transports (like logging to syslogd or a service)