Skip to content

Commit

Permalink
📝 update README
Browse files Browse the repository at this point in the history
  • Loading branch information
laendoor committed Jul 18, 2021
1 parent a343870 commit a54ea2e
Showing 1 changed file with 79 additions and 9 deletions.
88 changes: 79 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,29 @@

[![NPM](https://nodei.co/npm/winston-ready.png)](https://nodei.co/npm/winston-ready/)

This is a ready-to-use [Winston logger](https://github.com/winstonjs/winston) with the default configuration.
This is a ready-to-use [winston logger][winston] and [winston-daily-rotate-file][winston-daily-rotate-file] with the default configuration.

> ## Motivation
>
> Sometimes you have a few projects and you want to keep consistency between them.
> Maybe you are tired of copying & pasting the same logger configuration over and over.
> This project was born to avoid having to repeat this process on every new Node project.
> Almost every time I start a new _Node.js_ project usually I need a logger. So I go to a previous
> project and copy `logger.js` definition with all my transports and configurations.
> I don't like to keep a lot of copies of the same code over and over.
> I create this library to avoid that.
**About this ready-to-use default configurations:**

All definitions and transport configurations were chosen for my personal preference and workflow.
All definitions, transports and configurations were chosen for my personal preference and workflow.

If they don't suit you, you should use winston and define your custom configuration.
You could customize this logger adding your own transports, but if you
need a considerable different configuration you should use [winston][winston] and define at your own.

## Installation

```sh
npm install winston-ready
```

## Usage
## Basic Usage

```js
const logger = require('winston-ready');
Expand All @@ -39,7 +41,75 @@ logger.error("Show me the money!");

This package is configured using (optional) environment variables:

* `LOG_NAME` (default _app_)
* `LOG_STYLE` (posible values: _single_, _rotate_, _both_; default _rotate_)
* `LOG_LEVEL` (default _info_)
* `LOG_PATH` (default _logs/_)
* `LOG_NAME` (default _my-project_)
* `DEV_LOG_LEVEL` (only for Console transport, default _LOG\_LEVEL_ || _debug_)
* `LOG_DAYS` (default _180d_)
* `LOG_DATE_PATTERN` (default _YYYY-MM-DD_)
* `LOG_CONSOLE` (default _on_)
* `LOG_CONSOLE_LEVEL` (default _debug_)

With `LOG_STYLE` you can define if log using daily _rotate_ files, just a _single_ file or _both_.

`LOG_LEVEL` and `LOG_CONSOLE_LEVEL` use common [level values][levels].

If you set `NODE_ENV=development` or `LOG_CONSOLE=on` logger will display information at console.
Otherwise only at files. It is recommended that you **turn off** `LOG_CONSOLE` on **production**.

## Extended Usage (replacing default)

```js
// my-logger.js
const { container, winston } = require('winston-ready/container');

container.close('default');

container.add('my-own', {
level: 'warning',
format: winston.format.json(),
transports: [new winston.transports.File({ filename: 'my-own.log' })],
});

module.exports = container.get('my-own');
```

```js
// your-module.js
const logger = require('my-logger.js')

logger.error("This is my own logger error!");
```

## Extended Usage (adding another container)

```js
// my-logger.js
const { container, winston } = require('winston-ready/container');

container.add('morgan', {
level: 'verbose',
transports: [
new winston.transports.File({
filename: 'access.log',
format: winston.format.json()
})],
});

module.exports = {
logger: container.get('default'),
morgan: container.get('morgan'),
};
```

```js
// your-module.js
const { logger, morgan } = require('my-logger.js')

logger.error("Show me the money!");
morgan.info("HTTP access");
```

[winston]: https://github.com/winstonjs/winston
[levels]: https://github.com/winstonjs/winston#logging-levels
[winston-daily-rotate-file]: https://github.com/winstonjs/winston-daily-rotate-file

0 comments on commit a54ea2e

Please sign in to comment.