@ncoderz/log-m8 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# log-m8
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
A fast, small, flexible and extensible logging system for TypeScript and JavaScript applications.
|
|
4
9
|
|
|
5
|
-
[](LICENSE)
|
|
6
|
-
[](https://www.npmjs.com/package/log-m8)
|
|
7
10
|
|
|
8
11
|
## Features
|
|
9
12
|
|
|
@@ -19,13 +22,13 @@ A flexible, extensible logging system for TypeScript and JavaScript applications
|
|
|
19
22
|
## Installation
|
|
20
23
|
|
|
21
24
|
```bash
|
|
22
|
-
npm install log-m8
|
|
25
|
+
npm install @ncoderz/log-m8
|
|
23
26
|
```
|
|
24
27
|
|
|
25
28
|
## Quick Start
|
|
26
29
|
|
|
27
30
|
```typescript
|
|
28
|
-
import { LogM8 } from 'log-m8';
|
|
31
|
+
import { LogM8 } from '@ncoderz/log-m8';
|
|
29
32
|
|
|
30
33
|
// Configure the logging system
|
|
31
34
|
LogM8.init();
|
|
@@ -160,6 +163,18 @@ Writes log events to a file, one line per event.
|
|
|
160
163
|
|
|
161
164
|
Formatters transform log events into output formats suitable for different appenders.
|
|
162
165
|
|
|
166
|
+
### Supported Formatter Tokens
|
|
167
|
+
|
|
168
|
+
- `{timestamp}`: Formatted timestamp
|
|
169
|
+
- `{LEVEL}`: Uppercase level label (with optional colorization)
|
|
170
|
+
- `{level}`: Lowercase level name
|
|
171
|
+
- `{logger}`: Logger name
|
|
172
|
+
- `{message}`: Primary log message
|
|
173
|
+
- `{data}`: Additional data arguments
|
|
174
|
+
- `{context.*}`: Nested context properties
|
|
175
|
+
|
|
176
|
+
All tokens support accessing nested items with `data[0].property` like notation.
|
|
177
|
+
|
|
163
178
|
### Built-in Formatters
|
|
164
179
|
|
|
165
180
|
#### Default Formatter
|
|
@@ -170,7 +185,7 @@ A human-readable text formatter with customizable templates and optional coloriz
|
|
|
170
185
|
{
|
|
171
186
|
name: 'default-formatter',
|
|
172
187
|
// Optional: custom format with token placeholders
|
|
173
|
-
format: '{timestamp} {LEVEL} [{logger}] {message} {data}',
|
|
188
|
+
format: ['{timestamp} {LEVEL} [{logger}]', '{message}', '{data}'],
|
|
174
189
|
// Optional: timestamp format ('iso', 'locale', or custom pattern)
|
|
175
190
|
timestampFormat: 'hh:mm:ss.SSS',
|
|
176
191
|
// Optional: colorize level labels
|
|
@@ -178,14 +193,6 @@ A human-readable text formatter with customizable templates and optional coloriz
|
|
|
178
193
|
}
|
|
179
194
|
```
|
|
180
195
|
|
|
181
|
-
Supported tokens:
|
|
182
|
-
- `{timestamp}`: Formatted timestamp
|
|
183
|
-
- `{LEVEL}`: Uppercase level label (with optional colorization)
|
|
184
|
-
- `{level}`: Lowercase level name
|
|
185
|
-
- `{logger}`: Logger name
|
|
186
|
-
- `{message}`: Primary log message
|
|
187
|
-
- `{data}`: Additional data arguments
|
|
188
|
-
- `{context.*}`: Nested context properties
|
|
189
196
|
|
|
190
197
|
#### JSON Formatter
|
|
191
198
|
|
|
@@ -195,7 +202,9 @@ Formats log events as JSON objects, useful for machine processing and log aggreg
|
|
|
195
202
|
{
|
|
196
203
|
name: 'json-formatter',
|
|
197
204
|
// Optional fields to include
|
|
198
|
-
|
|
205
|
+
format: ['timestamp', 'level', 'logger', 'message', 'data', 'context'],
|
|
206
|
+
// Pretty print
|
|
207
|
+
pretty: true
|
|
199
208
|
}
|
|
200
209
|
```
|
|
201
210
|
|
|
@@ -203,6 +212,10 @@ Formats log events as JSON objects, useful for machine processing and log aggreg
|
|
|
203
212
|
|
|
204
213
|
Filters control which log events are processed by appenders.
|
|
205
214
|
|
|
215
|
+
### Supported Filter Tokens
|
|
216
|
+
|
|
217
|
+
See Supported Formatter Tokens.
|
|
218
|
+
|
|
206
219
|
### Built-in Filters
|
|
207
220
|
|
|
208
221
|
#### Match Filter
|
|
@@ -236,16 +249,22 @@ LogM8.disableAppender('console');
|
|
|
236
249
|
// Enable file appender
|
|
237
250
|
LogM8.enableAppender('file');
|
|
238
251
|
|
|
252
|
+
// Flush all appenders
|
|
253
|
+
LogM8.flushAppenders();
|
|
254
|
+
|
|
239
255
|
// Disable a filter for a specific appender
|
|
240
256
|
LogM8.disableFilter('sensitive-data', 'console');
|
|
241
257
|
|
|
242
|
-
//
|
|
243
|
-
LogM8.
|
|
258
|
+
// Enable a filter for a specific appender
|
|
259
|
+
LogM8.enableFilter('sensitive-data', 'console');
|
|
260
|
+
|
|
244
261
|
```
|
|
245
262
|
|
|
246
263
|
## Extending with Custom Plugins
|
|
247
264
|
|
|
248
|
-
You can extend log-m8 with custom appenders, formatters, and filters
|
|
265
|
+
You can extend log-m8 with custom appenders, formatters, and filters.
|
|
266
|
+
|
|
267
|
+
For example:
|
|
249
268
|
|
|
250
269
|
```typescript
|
|
251
270
|
class SlackAppenderFactory implements PluginFactory {
|