1.0.1 • Published 2 years ago

@nems.org/file-logger v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

File Logger

Purpose

Provider a standard logging for file logging. Provides a daily rotating log to make parsing logs fast.

Use/API

  1. Create a logger using the createLogger() function. The function has a few defaults but you may choose to change them.
  2. There are 5 methods for logging to correspond to severity of the level error, warn, info, verbose, debug. You may also silence logging with the silent option.

Options

When creating a logger there are a few options to configure:

namevaluesdefaultnotes
logDirectoryPath like string./logThis is the path where files will be stored
consoleLevelThe level where to print out to the stout/sterrinfo
logLevelThe level where to generate a file to log toinfoFor custom logging types verbose needs to be set
colorsAn object that defined the level color when printing to stout/sterrNoneExample: {error: "red", debug: "blue"}

Example

TypeScript

import createLogger from "@nems.org/file-logger";

const Logger = createLogger();

Logger.info("Hello World %s", "Scott");
// Will generate a daily YYYY-MM-DD-INFO.log file in the ./log directory
// [2022-01-01T13:30:00-07:00] - INFO - Hello World Scott
let body = { patient: "123" };
Logger.log("request", "http://localhost:8080 %O", body);
// Will generate a daily YYYY-MM-DD-REQUEST.log file in the ./log directory
// [2022-01-01T13:30:00-07:00] - REQUEST - http://localhost:8080 { "patient": "123" }