1.2.3 • Published 6 years ago

@new-knowledge/logger v1.2.3

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

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

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago