@new-knowledge/logger

Standardizing logging for NK

Stats

StarsIssuesVersionUpdatedCreatedSize
@new-knowledge/logger
1.2.34 years ago4 years agoMinified + gzip package size for @new-knowledge/logger in KB

Readme

New Knowledge Node Logger

A way to standardize logs for our node services.

Usage

nk-logger includes a pre-configured logger that is a Winston v3 logger and a pre-configured loggingMiddleware that a wrapper for Morgan.

Configuration

Logger is configurable by 3 env vars:

NODE_ENV: sets console and file logging levels if there is not a more specific env var set.

CONSOLE_LOGGER_LEVEL: sets logging levels to be sent to the console.

FILE_LOGGER_LEVEL: sets logging levels to be written to /logs/all-logs.log.

Logger

logger should replace console.log.

  • Logs for debugging should be logger.debug.
  • Logs that are meaningful should be logger.info
  • Logs that are warning (deprecation warning, etc.) should be logger.warn
  • Handled errors can be logged with logger.error

logger will console.log any log-level given `process.env.NODE_ENV !== 'production'.

logger keeps a rotating log of logs-level "info" or greater and errors in ./logs/all-logs.log and ./logs/errors.log respectively.

Be sure to create a ./logs directory to store logs in, and add logs/* to your .gitignore

Ex:

const { logger } = require('@new-knowledge/logger');

logger.info('This is an info log');
logger.warn('This is a warn log');
logger.debug('This is a debug log');
logger.silly('This is a silly log');

Logging Middleware

loggingMiddleware can be used just like "morgan middleware" for express.

Ex:

const express = require('express');
const { loggingMiddleware } = require('@new-knowledge/logger');

const app = express();

app.use(loggingMiddleware);

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.