You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Drop winston in favour of creating a simple logger that allows extracting error object properties (including message) while keeping the log message.
BREAKING CHANGE: The logger do not allow using winston's API anymore as we dropped winston
The logger generator accepts the following options:
23
+
The logger can optionally be customised using the following environment variables:
46
24
47
-
### simple
25
+
-`LOGS_FORMAT`: if set to `json`, the logger will log messages in json format instead of pretty messages (default behaviour).
26
+
-`LOGS_LEVEL`: minimum logging level, by default it will be `debug`. Accepted values are `'debug'`, `'info'`, `'warn'`, and `'error'`
27
+
-`TAG`: release tag (e.g. docker image tag) to be added to the log messages
48
28
49
-
This boolean value specifies whether we should log pretty dev-friendly messages instead of JSON or not.
50
-
By default, simple will be false.
29
+
## Logging levels
51
30
52
-
Example:
53
-
```javascript
54
-
const {getLogger} =require('@5app/logger');
31
+
Logging levels are (from lower to higher priority): `'debug'`, `'info'`, `'warn'`, and `'error'`.
32
+
The logger provides the logging functions with the following signatures: `logger.<level>(message, objectOrError)`
55
33
56
-
// This logger will log dev-friendly messages
57
-
constlogger=getLogger({
58
-
simple:true,
59
-
});
34
+
Here is an example of how the logger can be used:
60
35
```
61
-
62
-
The default logger uses the environment variable `LOGS_FORMAT` to determine if the logs are going to be generated in json (`json`) or simple console logs (any other value other than `json`).
63
-
64
-
### metadata
65
-
66
-
Metadata is an object containing service metadata like the release tag or the A/B testing experiment we are running.
67
-
This object will be added to each log entry when using the JSON mode.
68
-
69
-
Example:
70
-
```javascript
71
-
const {getLogger} =require('@5app/logger');
72
-
73
-
// This logger will add details about the current release and A/B experiment to every log line
74
-
constlogger=getLogger({
75
-
metadata: {
76
-
release:'1.2.3',
77
-
experiment:12345,
78
-
},
79
-
});
80
-
```
81
-
82
-
### level
83
-
84
-
You can specify a minimum logging level using the `level` parameter or using the `LOGS_LEVEL` environment variable.
85
-
By default, the logging level will be [debug (npm)](https://github.com/winstonjs/winston#logging-levels).
86
-
87
-
Example:
88
-
```javascript
89
-
const {getLogger} =require('@5app/logger');
90
-
91
-
// This logger will add details about the current release and A/B experiment to every log line
92
-
constlogger=getLogger({
93
-
level:'warn',
94
-
});
95
-
96
-
logger.info('this message will not be logged');
97
-
logger.warn('you will see this message');
36
+
logger.error('An error happened', new ApiError('The api call failed', 404)); // will log the message, the error message, the stack trace, and the statusCode error property
0 commit comments