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