# @lengoo/logger

> Small winston wrapper tailored to lengoo needs

Latest version **3.0.3** (published 2020-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @lengoo/logger
pnpm add @lengoo/logger
yarn add @lengoo/logger
bun add @lengoo/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 | 3.0.3 |
| Published | 2020-09-14 |
| First published | 2019-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lengoo GmbH |
| Maintainers | belzee92, mpedroc90, dejimenez, rodrigoterminus, daemyn, bretanac.93, lengoo_npm |
| Keywords | logger |

## Links

- npm: https://www.npmjs.com/package/@lengoo/logger
- Repository: https://github.com/lengoo/logger
- Homepage: https://github.com/lengoo/logger#readme
- Issues: https://github.com/lengoo/logger/issues
- npm.io page: https://npm.io/package/@lengoo/logger

## Dependencies (1)

- [winston](https://npm.io/package/winston.md) ^3.2.1

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 3.0.3 (latest) — 2020-09-14
- 3.0.2 — 2020-09-14
- 3.0.0 — 2020-03-03
- 2.1.3 — 2020-01-22
- 2.1.2 — 2019-11-26
- 2.1.1 — 2019-10-09
- 2.0.1 — 2019-07-08
- 2.0.0 — 2019-07-08
- 1.1.3 — 2019-02-08
- 1.1.2 — 2019-02-07
- 1.1.1 — 2019-02-06
- 1.1.0 — 2019-02-06

## README

# Lengoo logger

![Publish to NPM](https://github.com/lengoo/logger/workflows/Publish%20to%20NPM/badge.svg)

Lengoo logger is a small wrapper of [winston logger](https://github.com/winstonjs/winston) tailored to the team needs.

By default when used in development, it logs the defined events to the standard output, in production or staging, it can be connected to an APM agent and also write KPIs about the service.

## Installation
To install this package is enough to execute:
```bash
npm install --save @lengoo/logger
```
Or for yarn users:
```bash
yarn add @lengoo/logger
```

## Configuration
In order to make APM works, some configuration has to be provided in the form of environment variables, an example is as following:

```bash
APM_SERVER="http://localhost:8200"
APP_NAME="boilerplate"
```

If `APM_SERVER` is not defined in the environment, the logger will only print out to the stdout, will not write any kpi to the APM agent.

## Handling environment variables
As mentioned before, all the configuration is managed by environment variables, there are some optionals and some other mandatories for the correct working of the library:

```bash
NODE_ENV=development
APP_NAME=<app_name> # mandatory, will define the name of the logs in the index.
APM_SERVER="http://localhost:8200" # optional, if not defined, will not connect to an APM server.
```

## Usage
In order to use this library, you should import it first:
```javascript
const Logger = require('@lengoo/logger');
```
There are different levels of logging that are defined by the severity of the event you want to log, in this package, the severity levels are being kept from winston, and are the following:
```javascript
const levels = { 
  error: 0, 
  warn: 1, 
  info: 2, 
  verbose: 3, 
  debug: 4
};
```
Being each key a method in the package, you can log by calling them:
```javascript
Logger.error('This is a message');
```

## Structure
Each method contained by the package accepts either a string or an object, so it is possible to do something like:

```javascript
Logger.error('This is an error message');
// or
Logger.error({
  code: 'not-found',
  message: 'Not Found',
  trace: err.stack.toString(),
})
```
In the first case, the resulting log will contain the following structure:

```json
{
  "@timestamp": "2019-01-16T11:32:03.555Z",
  "message": "This is an error message",
  "severity": "error",
}
```

In the second case, you will have a little bit more complex structure:

```json
{
  "@timestamp": "2019-01-16T11:32:03.555Z",
    "message": "Not found",
    "severity": "error",
    "fields": {
      "metadata": {
        "code": "not-found",
        "trace": "at hello_world.js line 1",
        "timestamp": "2019-01-16T11:32:03.552Z"
      }
    }
}
```

If you notice, you will always have consistency with `timestamp`, `message` and `severity` in the resulting log structure, and if you need to add extra data to the log, you can do it and this will be stored in a `metadata` field located inside `fields` object, this is meant for elasticsearch to keep consistency accross indices.

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