just-enough-logger
Minimal logger for nodejs
Installation
npm install just-enough-logger
or
yarn add just-enough-logger
Usage
const Logger = ;// or// [DEPRECATED] const Logger = require("just-enough-logger").default;// Default export is available for backward compatibility. It'll be removed in next version. let log = ; // let log = new Logger(options?); // Check options // By default, prints to a file and console// Default file is current_directory/log.log// Check the options for more details log;// 10/2/2019, 12:57:14 AM : [INFO] : this is info message log;// 10/2/2019, 12:57:14 AM : [WARN] : this is warn message log;// 10/2/2019, 12:57:14 AM : [ERROR] : this is error message
Options
Pass the options object to Logger constructor.
transports
- Where to print log message
- Type: Array
- Valid Values:
["file", "console"]
- Default:
["file", "console"]
Example:
let log = transports: "console" // Only prints on console;
file
- Path of log file
- Type: Path String
- Valid Values:
/path/to/log.log
- Default:
[current_directory]/log.log
Example:
let log = file: path;
formatter
- Custom formatter
- Type: Function
- Signature:
(message: string, level: "info" | "warn" | "error") => string
- Default: Returns log in format
${new Date().toLocaleString()} : [${level.toUpperCase()}] : ${message}
Example:
let log = { return ` `; };
Methods
Methods work on instance of Logger
getLogFilePath()
- Returns the path of log file.
let logger = ;console; // c:\Programming\my-project\log.log
getLogStream()
- Returns
WriteStream
of log file or null if file transports is not present.
let logger = ;console;