# @hmcts/nodejs-logging

> [![Greenkeeper badge](https://badges.greenkeeper.io/hmcts/nodejs-logging.svg)](https://greenkeeper.io/)

Latest version **4.0.4** (published 2022-07-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hmcts/nodejs-logging
pnpm add @hmcts/nodejs-logging
yarn add @hmcts/nodejs-logging
bun add @hmcts/nodejs-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 | 4.0.4 |
| Published | 2022-07-07 |
| First published | 2017-06-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | HMCTS |
| Maintainers | bendiggle, ellie-harrison, adrianc, hemantt, adamsilver, trevorsaint, timja-hmcts, dharmendrak, robertparkinson, pragnesh, damdun, p.jar, sabah.irfan, jenkins-reform-hmcts, andrewwa-kainos, timja |

## Links

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

## Dependencies (3)

- [moment](https://npm.io/package/moment.md) ^2.29.4
- [winston](https://npm.io/package/winston.md) ^2.4.5
- [on-finished](https://npm.io/package/on-finished.md) ^2.3.0

## Recent versions

- 4.0.4 (latest) — 2022-07-07
- 4.0.3 — 2022-07-07
- 4.0.2 — 2022-05-23
- 4.0.1 — 2022-04-20
- 4.0.0 — 2022-04-19
- 3.0.4 — 2021-09-15
- 3.0.2 — 2020-08-21
- 3.0.1 — 2019-08-21
- 3.0.0 — 2018-04-12
- 2.2.0 — 2017-12-19
- 2.1.0 — 2017-12-18
- 2.0.0 — 2017-12-13
- 1.4.3 — 2017-12-04
- 1.4.2 — 2017-11-02
- 1.4.1 — 2017-11-02
- … 7 more at https://npm.io/package/@hmcts/nodejs-logging/versions

## README

# Node.js Logging

[![Greenkeeper badge](https://badges.greenkeeper.io/hmcts/nodejs-logging.svg)](https://greenkeeper.io/)

A logging component used by Reform's Node.js applications.

**This is not compatible with Reform tactical logging spec. Logger 2.x should be used for tactical applications.**

Some background info:
* there are 6 log levels: `silly` (5), `debug` (4), `verbose` (3), `info` (2), `warn` (1) and `error` (0).
* log level can be set via an environment variable `LOG_LEVEL`, the default is `info`.
* logging output in JSON format can be enabled by setting environment variable `JSON_PRINT` to `true`, the default is `false`:
* by default logging is turned off when running the unit tests.

## Usage

Add it as your project's dependency:

```bash
yarn add @hmcts/nodejs-logging
```

Require it:

```javascript
const { Logger } = require('@hmcts/nodejs-logging')
```

Then you can create a logger instance and use it to log information:

```javascript
const logger = Logger.getLogger('app.js') // app.js is just an example, can be anything that's meaningful to you
```

Usage are:

```
logger.info({
  message: 'Yay, logging!'
})
```

or

```
logger.log({
  level: 'info',
  message: 'What time is the testing at?'
});
```

Above will result in the following log printed (if JSON format is enabled).

```
{ level: 'info',
  message: 'What time is the testing at?',
  label: 'app.js',
  timestamp: '2017-09-30T03:57:26.875Z' }
```

### Access logging for Express applications 

Optionally you can use the built-in Express access logger:

```javascript
const { Express } = require('@hmcts/nodejs-logging')

app.use(Express.accessLogger())
```

## Units Tests

Just do

```
yarn test
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

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