A wrapper for WinstonJS with lots of configuration headaches already taken care of.
npm install -S @iqz/logger
Logger includes TypeScript type definitions within the package, so you don't have to install anything in addition to the above.
Import the logger
import { LogLevel, AppLogger } from '@iqz/logger';
Create a string to hold the path where you want your logs to be created. Logger will create a logs folder underneath the path.
import * as path from 'path';
let currentDir = path.join('/', 'home', 'rajshrimohanks', 'Documents', 'works', 'test-proj');
Initialize your logger. You only need to do this once in your application.
AppLogger.Log.init({
console: { // Optional. Remove if you don't want logging to console.
level: LogLevel.SILLY // Log level from which the content should be logged to the console.
},
file: { // Optional. Remove if you don't want logging to file.
path: currentDir, // Directory where the 'logs' folder should be created.
level: LogLevel.SILLY, // Log level from which the content should be logged to the log file.
logAsJson: true, // Should the output be logged as JSON or plain text. true - JSON; false - plain text
maxFileCount: 5 // Maximum number of log files to be retained. Logger creates a new file for every individual day.
}
});
Log your message!
AppLogger.Log.error("This is an error message", { msg: 'hello' });