@jacraig/woodchuck 1.5.30 → 1.5.31

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.
Files changed (2) hide show
  1. package/README.md +26 -40
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -35,28 +35,20 @@ Logger.verbose("This is a verbose message: {key}", { key: "value" });
35
35
  Logger.debug("This is a debug message: {key}", { key: "value" });
36
36
  Logger.information("This is an information message: {key}", { key: "value" });
37
37
  Logger.warning("This is a warning message: {key}", { key: "value" });
38
- Logger.error(
39
- "This is an error message: {key}",
40
- { key: "value" },
41
- new Error("This is an error")
42
- );
43
- Logger.fatal(
44
- "This is a fatal message: {key}",
45
- { key: "value" },
46
- new Error("This is a fatal error")
47
- );
38
+ Logger.error("This is an error message: {key}", { key: "value" }, new Error("This is an error"));
39
+ Logger.fatal("This is a fatal message: {key}", { key: "value" }, new Error("This is a fatal error"));
48
40
  ```
49
41
 
50
42
  3. Customize the logger with plugins:
51
43
 
52
44
  ```typescript
53
45
  Logger.configure()
54
- .enrichWith(new UserAgentEnricher())
55
- .enrichWith(new UrlEnricher())
56
- .enrichWith(new CallerEnricher())
57
- .formatUsing(new DefaultFormatter())
58
- .minimumLevel("Information")
59
- .writeTo(new ConsoleSink());
46
+ .enrichWith(new UserAgentEnricher())
47
+ .enrichWith(new UrlEnricher())
48
+ .enrichWith(new CallerEnricher())
49
+ .formatUsing(new DefaultFormatter())
50
+ .minimumLevel("Information")
51
+ .writeTo(new ConsoleSink());
60
52
  ```
61
53
 
62
54
  4. Or build your own plugins:
@@ -65,10 +57,9 @@ Logger.configure()
65
57
  import { LogEventEnricher, LogEvent } from "@jacraig/woodchuck";
66
58
 
67
59
  export class MyCustomPlugin implements LogEventEnricher {
68
- public enrich(logEvent: LogEvent): void {
69
- logEvent.properties["myProperty"] =
70
- "Something, something, something, dark side";
71
- }
60
+ public enrich(logEvent: LogEvent): void {
61
+ logEvent.properties["myProperty"] = "Something, something, something, dark side";
62
+ }
72
63
  }
73
64
  ```
74
65
 
@@ -77,17 +68,12 @@ export class MyCustomPlugin implements LogEventEnricher {
77
68
  ## Multiple Sinks
78
69
 
79
70
  ```typescript
80
- import {
81
- Logger,
82
- ConsoleSink,
83
- BatchedSink,
84
- BatchedSinkOptions,
85
- } from "@jacraig/woodchuck";
71
+ import { Logger, ConsoleSink, BatchedSink, BatchedSinkOptions } from "@jacraig/woodchuck";
86
72
 
87
73
  Logger.configure()
88
- .minimumLevel("Debug")
89
- .writeTo(new ConsoleSink())
90
- .writeTo(new BatchedSink(new ConsoleSink(), new BatchedSinkOptions()));
74
+ .minimumLevel("Debug")
75
+ .writeTo(new ConsoleSink())
76
+ .writeTo(new BatchedSink(new ConsoleSink(), new BatchedSinkOptions()));
91
77
  ```
92
78
 
93
79
  ## Async Sinks
@@ -98,11 +84,11 @@ Example (pseudo HTTP sink):
98
84
 
99
85
  ```typescript
100
86
  class HttpSink {
101
- constructor(private url: string) {}
102
- public write(event) {
103
- // return a Promise so this sink runs asynchronously
104
- return fetch(this.url, { method: "POST", body: JSON.stringify(event) });
105
- }
87
+ constructor(private url: string) {}
88
+ public write(event) {
89
+ // return a Promise so this sink runs asynchronously
90
+ return fetch(this.url, { method: "POST", body: JSON.stringify(event) });
91
+ }
106
92
  }
107
93
 
108
94
  Logger.configure().writeTo(new HttpSink("https://logs.example.com/ingest"));
@@ -116,9 +102,9 @@ When using `BatchedSink`, you can call `flush()` or `close()` to ensure buffered
116
102
  import { Logger, LogEventEnricher } from "@jacraig/woodchuck";
117
103
 
118
104
  class MyEnricher implements LogEventEnricher {
119
- enrich(event) {
120
- event.properties["custom"] = "myValue";
121
- }
105
+ enrich(event) {
106
+ event.properties["custom"] = "myValue";
107
+ }
122
108
  }
123
109
 
124
110
  Logger.configure().enrichWith(new MyEnricher()).writeTo(new ConsoleSink());
@@ -132,9 +118,9 @@ Logger.debug("With custom property");
132
118
  import { Logger, LogFilter } from "@jacraig/woodchuck";
133
119
 
134
120
  class OnlyErrorsFilter implements LogFilter {
135
- filter(event) {
136
- return event.level === "Error";
137
- }
121
+ filter(event) {
122
+ return event.level === "Error";
123
+ }
138
124
  }
139
125
 
140
126
  Logger.configure().filter(new OnlyErrorsFilter()).writeTo(new ConsoleSink());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacraig/woodchuck",
3
- "version": "1.5.30",
3
+ "version": "1.5.31",
4
4
  "description": "A simple logging library.",
5
5
  "main": "lib/Logger.cjs.js",
6
6
  "module": "lib/Logger.esm.js",