1.0.1 • Published 2 years ago
@nems.org/file-logger v1.0.1
File Logger
Purpose
Provider a standard logging for file logging. Provides a daily rotating log to make parsing logs fast.
Use/API
- Create a logger using the
createLogger()
function. The function has a few defaults but you may choose to change them. - There are 5 methods for logging to correspond to severity of the level
error, warn, info, verbose, debug
. You may also silence logging with thesilent
option.
Options
When creating a logger there are a few options to configure:
name | values | default | notes |
---|---|---|---|
logDirectory | Path like string | ./log | This is the path where files will be stored |
consoleLevel | The level where to print out to the stout/sterr | info | |
logLevel | The level where to generate a file to log to | info | For custom logging types verbose needs to be set |
colors | An object that defined the level color when printing to stout/sterr | None | Example: {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" }