Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit be85c0f

Browse files
committed
Merge branch 'change/add-pino-options' into 'master'
Add options.config See merge request Backend/ackee-node-logger!1
2 parents 7cb2a80 + 0bc162b commit be85c0f

4 files changed

Lines changed: 53 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [0.2.1] - 2018-06-08
2+
3+
### Added
4+
5+
- `options.config` for configuring underlying logger instance
6+
- "Tips" section to README
7+
8+
19
## [0.1.1] - 2018-05-29
210

311
### Added

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ First step is to create a root logger. Its configuration can be specified on cre
88

99
```js
1010
const logger = require('ackee-node-logger');
11-
// of
11+
// or
1212
const logger = require('ackee-node-logger')();
1313
```
1414

1515
### Create root logger with custom configuration
1616

1717
```js
18-
const logger = require('ackee-node-logger)({
18+
const logger = require('ackee-node-logger')({
1919
disableFields: ['error.stack'],
2020
enableFields: ['req.protocol']
2121
});
@@ -38,12 +38,12 @@ The only difference between root logger and a child logger is that the child log
3838
Logger itself is an enhanced and specifically configured `pino` instance, so you may use all basic `pino` log methods
3939

4040
```js
41-
pino.info('hello world')
42-
pino.error('this is at error level')
43-
pino.info('the answer is %d', 42)
44-
pino.info({ obj: 42 }, 'hello world')
45-
pino.info({ obj: 42, b: 2 }, 'hello world')
46-
pino.info({ obj: { aa: 'bbb' } }, 'another')
41+
logger.info('hello world')
42+
logger.error('this is at error level')
43+
logger.info('the answer is %d', 42)
44+
logger.info({ obj: 42 }, 'hello world')
45+
logger.info({ obj: 42, b: 2 }, 'hello world')
46+
logger.info({ obj: { aa: 'bbb' } }, 'another')
4747
```
4848

4949
All `pino` levels are supported and additionaly there is a `warning` level which is equivalent to `warn` level.
@@ -88,11 +88,8 @@ All those log messages will contain request and possibly response, error, time f
8888
### Testing
8989
If the `NODE_ENV` environment variable is set to `test`, all logs are turned off (minimal loglevel is set to `silent` which effectively turns logging off).
9090

91-
### Production
92-
If the `NODE_ENV` environment variable is set to `production`, [standard pino log](https://github.com/pinojs/pino#usage) is used.
93-
9491
### Otherwise
95-
In other cases, minimal loglevel is set to `debug` and [pino pretty human-readable logs](https://github.com/pinojs/pino/blob/master/docs/API.md#pretty) are used.
92+
[Standard pino log](https://github.com/pinojs/pino#usage) is used and it's optimized for Google Stackdriver logging. That means that default log level is `debug`, pretty print is turned off and [pino's `messageKey` option](https://github.com/pinojs/pino/blob/master/docs/API.md#pinooptions-stream) is set to `message`.
9693

9794
## Options
9895
Options override both default logger configuration and environment-specific configuration. However, do not forget to specify it during the **first** `ackee-node-logger`. During it, root logger is created and it cannot be changed later.
@@ -101,7 +98,8 @@ Options override both default logger configuration and environment-specific conf
10198
- `disableFields` - list of paths which will be omitted from the objects being logged (if any)
10299
- `enableFields` - list of paths which will not be omitted by default serializers from objects being logged
103100
- `streams` - list of stream objects, which will be passed directly to [pino-multistream's multistream function](https://github.com/pinojs/pino-multi-stream#pinomsmultistreamstreams) instead of default `ackee-node-logger` stream
104-
- `pretty` - if set to `true`, logger will use pretty print. This option can be overriden by `streams`
101+
- `pretty` - if set to `true`, logger will use [pino pretty human-readable logs](https://github.com/pinojs/pino/blob/master/docs/API.md#pretty). This option can be overriden by `streams`
102+
- `config` - object, which will be passed to underlying logger object. Right now, underlying logger is [pino](https://github.com/pinojs/pino), so for available options see [pino API docs](https://github.com/pinojs/pino/blob/master/docs/API.md#pinooptions-stream)
105103

106104
## Default serializers
107105
`ackee-node-logger` defines some [pino serializers](https://github.com/pinojs/pino/blob/master/docs/API.md#constructor) on its own
@@ -110,3 +108,24 @@ Options override both default logger configuration and environment-specific conf
110108
- `processEnv` - logs `NODE_PATH` and `NODE_ENV`
111109
- `req` - logs `body`, `query`, `url`, `method` and omits `password` and `passwordCheck` from `body` and `query`
112110
- `res` - logs `out` and `time`
111+
112+
113+
## Tips
114+
115+
### VS Code debugging not showing log messages
116+
117+
This problem is caused by a way VS Code handles console output. Therefore it appears in Winston and pino (underlying library of ackee-node-logger) as well.
118+
119+
However, it can be easily solved by adding eithe
120+
121+
```js
122+
"console": "integratedTerminal",
123+
```
124+
125+
or
126+
127+
```js
128+
"outputCapture": "std"
129+
```
130+
131+
to the debug configuration in your `launch.json` file.

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ const defaultLogger = (options = {}) => {
6262
}
6363

6464
let streams;
65+
let defaultMessageKey = 'message'; // best option for Google Stackdriver
6566
if (options.streams) {
6667
streams = options.streams;
6768
} else if (options.pretty) {
6869
streams = [
6970
{ level: defaultLevel, stream: pretty, maxLevel: levels.warn },
7071
{ level: levels.warn, stream: prettyErr },
7172
];
73+
defaultMessageKey = 'msg'; // default pino - best option for pretty print
7274
} else {
7375
streams = [
7476
{ level: defaultLevel, stream: process.stdout, maxLevel: levels.warn },
@@ -77,7 +79,16 @@ const defaultLogger = (options = {}) => {
7779
}
7880

7981
const logger = pino(
80-
{ level: defaultLevel, timestamp: false, base: {}, serializers: serializers.serializers },
82+
_.merge(
83+
{
84+
level: defaultLevel,
85+
timestamp: false,
86+
base: {},
87+
serializers: serializers.serializers,
88+
messageKey: defaultMessageKey,
89+
},
90+
options.config
91+
),
8192
multistream(streams)
8293
);
8394
logger.warning = logger.warn;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ackee-node-logger",
3-
"version": "0.1.1",
3+
"version": "0.2.1",
44
"description": "Ackee Node Logger",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)