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
Copy file name to clipboardExpand all lines: README.md
+73-1Lines changed: 73 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,8 +32,80 @@ You must add the following to the list of appenders in your `log4js.json` file:
32
32
}
33
33
}
34
34
```
35
+
You may substitute `INFO` with your own level above (for ex: `WARN`, `ERROR`, etc). Please check [log4js](https://www.npmjs.com/package/log4js) documentation for level based filtering since there might be some differences between versions.
35
36
36
-
You may substitute `INFO` with your own level above (for ex: `WARN`, `ERROR`, etc)
37
+
To use custom fields to send logmet, you should define `eventMap` object under `options`. If it is not defined then default mapping is used.
38
+
39
+
Default Event object (object sending to Logmet) consists of `component`, `host-ip`, `instance-id`, `loglevel`, `logtime`, `message` values.
40
+
41
+
For custom fields, values can be map are given below:
42
+
-`component`: The name of your component / service.
43
+
-`host-ip`: The cloudfoundary ip defined as environmental variable CF_INSTANCE_IP
44
+
-`instance-id`: The cloudfounrday index defined as environmental variable CF_INSTANCE_INDEX
-`logtime`: Logging time as ISO string format (exp. 2011-10-05T14:48:00.000Z)
47
+
-`message`: Log message based on log4js configuration. If log data is multiple string, then is is merged with ` | ` delimiter.
48
+
-`process.*` : To reach variables from `process` within two layer. (exp. process.pid, process.env.USER)
49
+
-`data.*` : To reach variables from optional `object` type from log data within two layer. This is useful, if you want to pass a custom object and use the value in your logs withing a custom field. (exp. You can pass `{clientId: '123'}` object to log and map it as `CLIENT_ID: data.clientId`)
50
+
51
+
Example `log4js.json` file given below (for log4js version 0.6.38 and below).
52
+
```
53
+
{
54
+
"appenders": [
55
+
{
56
+
"type": "console",
57
+
"layout": { "type": "coloured" }
58
+
},
59
+
{
60
+
"type": "logLevelFilter",
61
+
"level": "INFO",
62
+
"appender": {
63
+
"type": "log4js-logmet-appender",
64
+
"options": {
65
+
"eventMap": {
66
+
"TIMESTAMP": "logtime",
67
+
"PRIORITY": "loglevel",
68
+
"MESSAGE": "message",
69
+
"SERVICE": "component",
70
+
"_PID": "process.pid",
71
+
"USER": "process.env.USER",
72
+
"CUSTOM_ENV": "process.env.CUSTOM_VARIABLE"
73
+
"TEST": "data.test",
74
+
"TEST12": "data.test1.test2"
75
+
}
76
+
}
77
+
}
78
+
}
79
+
],
80
+
"replaceConsole": true
81
+
}
82
+
```
83
+
And example `debug` logging call;
84
+
```
85
+
var log4js = require('log4js');
86
+
log4js.configure('/path/to/log4js.json');
87
+
var logger = log4js.getLogger();
88
+
logger.level = 'debug';
89
+
const objectToTest = { test: 'test 1 is good', test1: { test2: 'test 2 is better' } };
0 commit comments