# chpr-logger

> Logger for NodeJS application stack

Latest version **3.3.0** (published 2020-06-23) · MIT license · 0 weekly downloads

## Install

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

## 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 | 3.3.0 |
| Published | 2020-06-23 |
| First published | 2016-05-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.11.1 |
| Dependencies | 6 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| Author | Chauffeur-Privé |
| Maintainers | cptechadmin |
| Keywords | logger |

## Links

- npm: https://www.npmjs.com/package/chpr-logger
- npm.io page: https://npm.io/package/chpr-logger

## Dependencies (6)

- [raven](https://npm.io/package/raven.md) 2.2.1
- [bunyan](https://npm.io/package/bunyan.md) 1.8.12
- [lodash](https://npm.io/package/lodash.md) 4.17.11
- [@types/bunyan](https://npm.io/package/@types/bunyan.md) 1.8.4
- [bunyan-prettystream](https://npm.io/package/bunyan-prettystream.md) 0.1.3
- [bunyan-sentry-stream](https://npm.io/package/bunyan-sentry-stream.md) 1.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.3.0 (latest) — 2020-06-23
- 3.2.0 — 2019-03-20
- 3.1.0 — 2019-01-04
- 3.0.0 — 2019-01-03
- 2.9.1 — 2018-12-18
- 2.9.0 — 2018-11-13
- 2.8.0 — 2018-09-25
- 2.7.0 — 2018-09-13
- 2.6.1 — 2017-11-29
- 2.6.0 — 2017-11-16
- 2.5.0 — 2017-11-05
- 2.4.1 — 2016-12-28
- 2.4.0 — 2016-11-27
- 2.3.1 — 2016-09-08
- 2.3.0 — 2016-07-25
- … 5 more at https://npm.io/package/chpr-logger/versions

## README

# Logger for NodeJS

This utility library implements our standard Bunyan + Sentry configuration

<!-- TOC depthFrom:2 -->

- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Use](#use)
- [Sensitive Data](#sensitive-data)

<!-- /TOC -->

## Requirements

Minimum Node.js version: 4

## Installation

```bash
npm install --save chpr-logger
```

## Configuration

| Key                      | Required | Description                                                                                                                                                                       |
|--------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `LOGGER_NAME`              | yes      | Sets the name of the logger.                                                                                                                                                      |
| `LOGGER_LEVEL`             | yes      | Set the minimum level of logs.                                                                                                                                                    |
| `SENTRY_DSN`               | no       | Sets the Sentry stream. ([bunyan-sentry-stream](https://www.npmjs.com/package/bunyan-sentry-stream))                                                                              |
| `SENTRY_ENVIRONMENT`       | no       | Sets the Sentry Environment.                                                                                                                                                      |
| `USE_BUNYAN_PRETTY_STREAM` | no       | Outputs the logs on stdout with the pretty formatting from Bunyan. Must be set to `true` to be active. ([bunyan-prettystream](https://www.npmjs.com/package/bunyan-prettystream)) |
| `LOGGER_USE_SENSITIVE_DATA_STREAM` | no       | Use the sensitive data stream to remove any possible sensitive data from the logs (enabled by default, `false` to use the `process.stdout` stream). |
| `LOGGER_SENSITIVE_DATA_PATTERN` | no       | Pattern fragments to match sensitive keys (default is `(mdp|password|authorization|token|pwd|auth)`). |

## Use

```javascript
'use strict';

const logger = require('chpr-logger');

/* The signature is logger[level](context, message) where:
- context is an object containing all info to be logged
- context may be passed an `err` property that is an error and will be used by
  sentry to regroup errors and capture proper stacktraces
- message is just a string explaining what the log is

As in bunyan, context is optional and logger[level](message) can also work.
*/

// Log a fatal error message:
logger.fatal({ err: new Error('Fatal'), field: 'additional info' }, 'fatal message');

// Log an error message:
logger.error({ err: new Error('Error'), anotherField: 'extra context' }, 'error message');

// Log a warning message:
logger.warn({ err: new Error('Warn'), userId:'1e7b8d', age: 17 }, 'User is under 18');

// Log an informational message:
logger.info({ field: 1 }, 'info message');

// Log a debug message:
logger.debug({ user }, 'debug message');

// Log a trace message:
logger.trace({ fields: [1, 2, 66]] }, 'trace message');

```

## Sensitive Data

`chpr-logger` can filter sensitive data based on specific keys and replace the
values by `__SENSITIVE_DATA__` string. This feature is enabled by default but
you can skip this (not recommanded) by setting the environment variable
`LOGGER_USE_SENSITIVE_DATA_STREAM` to `false`.

In addition, you can update the pattern on which to make the match with the
environment variable `LOGGER_SENSITIVE_DATA_PATTERN`. Its value must represent
a valid [capturing regular expression](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/RegExp#group_back).

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