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
+11-13Lines changed: 11 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ yarn add @nolawnchairs/logger
16
16
17
17
As opposed to v2, there is more boilerplate to configure, since we now provide multiple logging environments that can each write to multiple output streams.
18
18
19
-
Set up your logging environments using the `init` method. The `providers.globalLoggers` object must contain one object where the key is any unique name you like (it's how the internal registry identifies it), and the value is a function that returns the configuration for this logger:
19
+
Set up your logging environments using the `init` method. The `providers.globalLoggers` object must contain at least one object that defines the function providing the configuration for this logger:
20
20
21
21
```javascript
22
22
Log.init({
@@ -35,9 +35,7 @@ Log.init({
35
35
})
36
36
```
37
37
38
-
In the above example, we define a single `globalLogger`. The name we give this logger is `development`, and it returns a `LoggerConfigInstance` object. Here, the `enabled` key is set based on whether or not we're in development mode, we set the `level` to `DEBUG`, set a serialization strategy (which dictates how non-scalar values are treated when printing), and an array of `LogWriter` instances that define where the logging output goes.
39
-
40
-
To log, we simply call the desired level with a message:
38
+
In the above example, we define a single `globalLogger`. The name we give this logger is `development`, and it returns a `LoggerInstanceConfig` object. Here, the `enabled` key is set based on whether or not we're in development mode, we set the `level` to `DEBUG`, set a serialization strategy (which dictates how non-scalar values are treated when printing), and an array of `LogWriter` instances that define where the logging output goes.
41
39
42
40
43
41
@@ -72,7 +70,7 @@ Log.init({
72
70
})
73
71
```
74
72
75
-
In this example, we set `enabled` to true, but set the `level` dependent on the `NODE_ENV` value. Instead of a single `LogWriter`, we specify two - one for the console, and one that logs to a file. Note that we're using a `formatProvider` to write monochrome, since we don't normally want ANSI colors present in our disk logs.
73
+
In this example, we set `enabled` to true, but set the `level` dependent on the `NODE_ENV` value. Instead of a single `LogWriter`, we specify two - one for the console, and one that logs to a file. Note that we're using a `formatProvider` to write monochrome, since we normally don't want ANSI colors present in our disk logs.
76
74
77
75
Creating a Feature Logger is simple. We call the `forFeature` method on the main `Log` interface as such:
78
76
@@ -117,10 +115,10 @@ Configuration is set in the `Log.init()` method, and has the following structure
117
115
global: LoggerGlobalConfig
118
116
providers: {
119
117
globalLoggers: {
120
-
yourLoggername: () => LoggerConfigInstance
121
-
anotherLogger: () => LoggerConfigInstance
118
+
yourLoggername: () => LoggerInstanceConfig
119
+
anotherLogger: () => LoggerInstanceConfig
122
120
}
123
-
featureLogger: () => LoggerConfigInstance
121
+
featureLogger: () => LoggerInstanceConfig
124
122
}
125
123
}
126
124
```
@@ -135,23 +133,23 @@ The following values can be set to the `global` object, and will provide default
135
133
|`serializationStrategy`|`ObjectSerializationStrategy`| How non-scalar values will be printed. Defaults to `INSPECT`||
136
134
|`inspectionDepth`| number | The depth of serialization when using the `INSPECT` strategy. Defaults to `3`||
137
135
|`inspectionColor`| boolean | Used in the `INSPECT` strategy, governs whether or not to color the inspected object ||
138
-
|`formatter`|`FormatProvider`| Defines a custom formatter for all`LogWriters`for this logger. Note that writers can override this setting with their own formatting||
136
+
|`formatter`|`FormatProvider`| Defines a custom formatter for each`LogWriters`attached this logger. Note that writers may override this with their own formatter||
139
137
140
138
141
139
---
142
140
143
-
### `interface`LoggerConfigInstance
141
+
### `interface`LoggerInstanceConfig
144
142
145
143
Each individial logger you define must be configured with the following properties.
|`enabled`| boolean | Whether this logger will produce data | ✔️ |
151
-
|`level`|`LogLevel or number`| The level this logger will adhere to. Use a `LogLevel` enum value or an or'ed mask of multiple levels to use in unison<sup>1</sup> | ✔️ |
152
-
|`writers`|`LogWriter[]`| An array of `LogWriter` instances to use with this logger |✔️|
149
+
|`level`|`LogLevel`| The level to which this logger will adhere. Use a `LogLevel` enum value or an `or`'ed bitmask of multiple levels to use in unison<sup>1</sup> | ✔️ |
150
+
|`writers`|`LogWriter[]`| An array of `LogWriter` instances this logger will use|✔️|
153
151
154
-
In addition to the above properties, the `LoggerConfigInstance` will accept any of the properties defined in `LoggerGlobalConfig`, which will override any default values you set in `global`.
152
+
In addition to the above properties, the `LoggerInstanceConfig` will accept any of the properties defined in `LoggerGlobalConfig`, which will override any default values you set in `global`.
0 commit comments