UNPKG

1.66 kBMarkdownView Raw
1# Logasm
2
3## Installation
4```
5 npm install --save logasm
6```
7
8## Preprocessors
9
10Preprocessors allow modification of log messages, prior to sending of the message to the configured logger(s).
11
12### Blacklist
13
14Excludes or masks defined fields of the passed hash object.
15You can specify the name of the field and which action to take on it.
16Nested hashes of any level are preprocessed as well.
17
18Available actions:
19
20* exclude(`default`) - fully excludes the field and its value from the hash.
21* mask - replaces every character from the original value with `*`. In case of `array`, `hash` or `boolean` value is replaced with one `*`.
22
23#### Configuration
24
25```yaml
26preprocessors:
27 blacklist:
28 fields:
29 - key: password
30 - key: phone
31 action: mask
32```
33
34#### Usage
35
36```javascript
37
38logger = Logasm.build(application_name, logger_config, preprocessors)
39
40input = {password: 'password', info: {phone: '+12055555555'}}
41
42logger.debug("Received request", input)
43```
44
45Logger output:
46
47```
48Received request {"info":{"phone":"************"}}
49```
50
51### Whitelist
52
53Masks all the fields except those whitelisted in the configuration using [JSON Pointer](https://tools.ietf.org/html/rfc6901).
54Only simple values(`string`, `number`, `boolean`) can be whitelisted.
55
56#### Configuration
57
58```yaml
59preprocessors:
60 whitelist:
61 pointers: ['/info/phone']
62```
63
64#### Usage
65
66```javascript
67logger = Logasm.build(application_name, logger_config, preprocessors)
68
69input = {password: 'password', info: {phone: '+12055555555'}}
70
71logger.debug("Received request", input)
72```
73
74Logger output:
75
76```
77Received request {password: "********", "info":{"phone":"+12055555555"}}
78```