# @mirekpluta/jg-logger

> Preconfigured winston logger

Latest version **1.0.8** (published 2019-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mirekpluta/jg-logger
pnpm add @mirekpluta/jg-logger
yarn add @mirekpluta/jg-logger
bun add @mirekpluta/jg-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 | 1.0.8 |
| Published | 2019-11-25 |
| First published | 2019-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mirekpluta |

## Links

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

## Dependencies (4)

- [config](https://npm.io/package/config.md) ^3.0.1
- [winston](https://npm.io/package/winston.md) ^3.2.1
- [fast-safe-stringify](https://npm.io/package/fast-safe-stringify.md) ^2.0.6
- [express-async-errors](https://npm.io/package/express-async-errors.md) ^3.1.1

## Recent versions

- 1.0.8 (latest) — 2019-11-25
- 1.0.7 — 2019-11-25
- 1.0.6 — 2019-11-25
- 1.0.5 — 2019-11-25
- 1.0.4 — 2019-11-25
- 1.0.3 — 2019-09-10
- 1.0.2 — 2019-03-28
- 1.0.1 — 2019-03-28
- 1.0.0 — 2019-03-28

## README

# jg-logger
Small utility providing logger that configures **winston** logger for usage on local (dev) environment where readability of logs is critical as well as production, dockerized environments where logs are being processed by tools. 

# Installation
Simply execute
```
npm install @mirekpluta/jg-logger
```

# Configuration
Logger is being configured with **config** npm package, therefore it requires json config files to be present in `config` directory.

Example config file:
```json
{
  "logger": {
    "logLevel": "debug",
    "format": "pretty",
    "defaultMeta": {
        "serviceName": "test"
    }
  }
}
```
Explanation
* **logLevel** - log level as specified in `winston` library (error, warn, info, verbose, debug, silly)
* **format**
  * *pretty* - to be used when running locally, it displays colorized log with timestamps, padded levels and json stringified metadata + potential stacktrace in case of logged exception
  * *json* - it'll display each log entry as json object including timestamp and stacktrace in case of errors
* **defaultMeta** - default metadata that will be included to all logs from the project

# Functionality
* both human friendly (pretty) and tools friendly (json) logs format (see Configuration above).
* catches and logs all uncought errors (it will prevent application from exiting)
* provides **errorLoggingMiddleware** express middleware to be registered at the very end with express app, that logs all rejected promises
* uses [express-async-errors](https://www.npmjs.com/package/express-async-errors) package that will handle all rejected promises from middleware async functions
* adds **logger** property to **global** object for easy access throughout entire application

# Usage
**Import early:** - logger should be imported as early in the project as possible, so that it can be initialized

**logger.errorLoggingMiddleware** - express middleware that should be registered to express app as the last one

**use like you would use winston logger** - configured logger is just **winston** logger, so entire functionality of it is available.

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