# lib-logging

> A node.js logging implementation.

Latest version **1.2.0** (published 2021-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install lib-logging
pnpm add lib-logging
yarn add lib-logging
bun add lib-logging
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-02-07 |
| First published | 2021-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | syr0s |
| Maintainers | syr0s |

## Links

- npm: https://www.npmjs.com/package/lib-logging
- Repository: https://github.com/cira-cloud/lib-logging
- Homepage: https://github.com/cira-cloud/lib-logging#readme
- Issues: https://github.com/cira-cloud/lib-logging/issues
- npm.io page: https://npm.io/package/lib-logging

## Dependencies (1)

- [caller-id](https://npm.io/package/caller-id.md) ^0.1.0

## Recent versions

- 1.2.0 (latest) — 2021-02-07
- 1.1.0 — 2021-02-06
- 1.0.2 — 2021-02-05
- 1.0.1 — 2021-02-05
- 1.0.0 — 2021-02-05

## README

# lib-logging
![Test](https://github.com/cira-cloud/lib-logging/workflows/Test/badge.svg)
![Publish](https://github.com/cira-cloud/lib-logging/workflows/Publish/badge.svg)


A node.js logging implementation.

## Installation
```
npm install --save lib-logging
```

## Usage
**Example**
```javascript
const logging = require('lib-logging')
logging.log(1, 'server', 'Hello World')
// will log in console (and file):
// [NOTE - SERVER | Thu Feb 04 2021 21:13:16 GMT+0100 ] Hello World
```
If you would like to log also the origin of the message you can use:
```javascript
const logging = require('lib-logging')
logging.log(1, 'server', 'Hello World', true)
// will log in console (and file):
// [NOTE - SERVER | Thu Feb 04 2021 21:13:16 GMT+0100 ] (/my/path:35 - myFunction) Hello World
```
By default `lib-logging` will store all loggings in `./logs/lib-logging.log`. You can disable this feature by using the `addOptions()` function (see configuration for more details).

## Possible parameters
The log() function takes four arguments. 
1. `level`: The log level as number (1: Note, 2: Warning, 3: Error)
2. `service`: The corresponding service triggering the log function, by default `['server', 'cors', 'redis', 'lifesign', 'mariadb']` are possible values
3. `msg`: The message string to log
4. `caller`: Boolean value (default false) which provides additional information about the origin

## Configuration
To modify the default values of `lib-logging` you can use the `addOptions(options)` function. 
```javascript
const options = {
  enableLogging: false,
  logToFile: {
    note: false
  },
  level: {
    debug: 4
  },
  services: ['my service'],
  globalCaller: false
};
log.addOptions(options);
```
By default all events will be loged in the file `./logs/lib-logging.log`. You can disable this feature for each loglevel individual, by setting the property in `logToFile` to `false` or disable the whole feature globally by setting `enableLogging` to `false`.
```javascript
// disable on loglevel
logging.addOptions({
  logToFile: {
    note: false
  }
});
// disabled on NOTE events
```
```javascript
// disable globally, good idea by using lib-logging in a browser application
logging.addOptions({
  enableLogging: false
});
```
For debugging purposes, you can set the `globalCaller` property to `true`. This will ptovide the additional caller information on all log events.

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