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
Then, generate a logger in your app and use it to log messages.
11
11
12
12
```javascript
13
-
constgetLogger=require('@5app/logger');
13
+
const {logger} =require('@5app/logger');
14
+
15
+
logger.info('An email was sent', {
16
+
email:'customer@5app.com',
17
+
template:'template1',
18
+
});
19
+
20
+
logger.error(newError('Unknown playlist 123'));
21
+
```
22
+
23
+
Alternatively, you can create a new instance of logger where you can specify the metadata, logging level, and whether you want simple logs or not:
24
+
25
+
```javascript
26
+
const {getLogger} =require('@5app/logger');
14
27
15
28
constlogger=getLogger({
16
29
simple:process.env.NODE_ENV==='development',
@@ -38,29 +51,48 @@ By default, simple will be false.
38
51
39
52
Example:
40
53
```javascript
41
-
constgetLogger=require('@5app/logger');
54
+
const{getLogger}=require('@5app/logger');
42
55
43
56
// This logger will log dev-friendly messages
44
57
constlogger=getLogger({
45
58
simple:true,
46
59
});
47
60
```
48
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
+
49
64
### metadata
50
65
51
66
Metadata is an object containing service metadata like the release tag or the A/B testing experiment we are running.
52
67
This object will be added to each log entry when using the JSON mode.
53
68
54
69
Example:
55
70
```javascript
56
-
constgetLogger=require('@5app/logger');
71
+
const{getLogger}=require('@5app/logger');
57
72
58
73
// This logger will add details about the current release and A/B experiment to every log line
59
-
constgetLogger=require('@5app/logger');
60
74
constlogger=getLogger({
61
75
metadata: {
62
76
release:'1.2.3',
63
77
experiment:12345,
64
78
},
65
79
});
66
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
0 commit comments