Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
/ logger Public archive

A wrapper for Winston which eases logging.

Notifications You must be signed in to change notification settings

iqz-systems/logger

Repository files navigation

IQZ Logger

A wrapper for WinstonJS with lots of configuration headaches already taken care of.

Installation

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.

Usage

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' });