# lightweight-logger

> Lightweight logger for nodejs application

Latest version **5.1.0** (published 2018-06-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install lightweight-logger
pnpm add lightweight-logger
yarn add lightweight-logger
bun add lightweight-logger
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2018-06-10 |
| First published | 2018-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Milan Gatyas |
| Maintainers | mgjam |

## Links

- npm: https://www.npmjs.com/package/lightweight-logger
- Repository: https://github.com/mgjam/nodejs-modules-lightweight-logger
- Homepage: https://github.com/mgjam/nodejs-modules-lightweight-logger#readme
- Issues: https://github.com/mgjam/nodejs-modules-lightweight-logger/issues
- npm.io page: https://npm.io/package/lightweight-logger

## Dependencies (1)

- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.11

## Recent versions

- 5.1.0 (latest) — 2018-06-10
- 5.0.0 — 2018-06-10
- 4.0.0 — 2018-06-10
- 3.0.0 — 2018-06-09
- 2.1.0 — 2018-06-09
- 2.0.1 — 2018-06-09
- 2.0.0 — 2018-06-09
- 1.1.0 — 2018-06-02
- 1.0.2 — 2018-06-02
- 1.0.1 — 2018-06-02
- 1.0.0 — 2018-06-02

## README

# 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
```sh
npm install lightweight-logger
```

## Usage [JS]
```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"}
 * /
```

---
_Source: https://npm.io/package/lightweight-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
