5.1.0 • Published 6 years ago

lightweight-logger v5.1.0

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

lightweight-logger

Lightweight logger for nodejs application

Features

Logs are serialized as JSON objects

Possibility to extend log object with custom properties via injection

Installation

npm install lightweight-logger

Usage JS

const lib = require("lightweight-logger");

lib.configure({
    // extend log object with given field
    logExtensionFunc: (log, data) => {
        log["correlationId"] = data.correlationId;
        return log;
    },
    consoleLoggerOptions: {
        // Use console logger
        useConsoleLogger: true
    },
    fileLoggerOptions: {
        // Use file logger. New log file per hour is created automatically
        useFileLogger: true,
        // Write to given path (path must exist!)
        logPath: "C:/Log"
    }
});

const logger = lib.createLogger({correlationId: "xyz"});

for (let i = 0; i < 2; i++)
    logger.i(i.toString());

logger.e({message: "log message", data: {foo: "bar"}}, new Error("error message"));

/*
 * Output: C:/Log/2018_6_10_6.log
 * 
 * {"message":"0","timeStamp":"2018-06-10T06:30:45.548Z","severity":"Info","correlationId":"xyz"}
 * {"message":"1","timeStamp":"2018-06-10T06:30:45.548Z","severity":"Info","correlationId":"xyz"}
 * {"message":"log message","data":{"foo":"bar"},"timeStamp":"2018-06-10T06:30:45.548Z","severity":"Error","error":{"stack":"<intentionally removed>","message":"error message"},"correlationId":"xyz"}
 * /
5.1.0

6 years ago

5.0.0

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago