@gratheon/log-lib 1.0.0 → 1.0.1
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/dist/logger.js +14 -12
- package/dist/types.d.ts +7 -7
- package/package.json +1 -1
- package/src/logger.ts +14 -12
- package/src/types.ts +7 -7
package/dist/logger.js
CHANGED
|
@@ -128,33 +128,35 @@ function createLogger(config) {
|
|
|
128
128
|
};
|
|
129
129
|
const fastifyLogger = {
|
|
130
130
|
// Stringify potential objects passed to info/warn
|
|
131
|
-
info: (msg) => {
|
|
131
|
+
info: (msg, ...args) => {
|
|
132
132
|
const messageString = typeof msg === 'object' ? (0, fast_safe_stringify_1.default)(msg) : String(msg);
|
|
133
133
|
log("info", messageString);
|
|
134
134
|
// storeInDB("info", messageString); // Keep commented out as original
|
|
135
135
|
},
|
|
136
|
-
error: (
|
|
137
|
-
const errorMessage = (
|
|
136
|
+
error: (msg, ...args) => {
|
|
137
|
+
const errorMessage = (msg && msg.message) ? msg.message : String(msg);
|
|
138
|
+
const meta = args.length > 0 ? args[0] : undefined;
|
|
138
139
|
log("error", errorMessage, meta);
|
|
139
140
|
// Ensure string is passed to storeInDB
|
|
140
|
-
storeInDB("error", typeof
|
|
141
|
+
storeInDB("error", typeof msg === 'object' ? (0, fast_safe_stringify_1.default)(msg) : errorMessage, meta);
|
|
141
142
|
},
|
|
142
|
-
warn: (msg) => {
|
|
143
|
+
warn: (msg, ...args) => {
|
|
143
144
|
const messageString = typeof msg === 'object' ? (0, fast_safe_stringify_1.default)(msg) : String(msg);
|
|
144
145
|
log("warn", messageString);
|
|
145
146
|
storeInDB("warn", messageString); // Pass stringified message
|
|
146
147
|
},
|
|
147
148
|
// do not store debug logs in DB
|
|
148
|
-
debug: (msg) => {
|
|
149
|
-
log("debug", msg);
|
|
149
|
+
debug: (msg, ...args) => {
|
|
150
|
+
log("debug", String(msg));
|
|
150
151
|
},
|
|
151
|
-
fatal: (msg) => {
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
fatal: (msg, ...args) => {
|
|
153
|
+
const messageString = typeof msg === 'object' ? (0, fast_safe_stringify_1.default)(msg) : String(msg);
|
|
154
|
+
log("error", messageString);
|
|
155
|
+
storeInDB("error", messageString);
|
|
154
156
|
process.exit(1);
|
|
155
157
|
},
|
|
156
|
-
trace: (msg) => { },
|
|
157
|
-
child: (
|
|
158
|
+
trace: (msg, ...args) => { },
|
|
159
|
+
child: (bindings) => {
|
|
158
160
|
return fastifyLogger;
|
|
159
161
|
},
|
|
160
162
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ export interface Logger {
|
|
|
18
18
|
debug: (message: string, meta?: LogMetadata) => void;
|
|
19
19
|
}
|
|
20
20
|
export interface FastifyLogger {
|
|
21
|
-
info: (msg: any) => void;
|
|
22
|
-
error: (
|
|
23
|
-
warn: (msg: any) => void;
|
|
24
|
-
debug: (msg: any) => void;
|
|
25
|
-
fatal: (msg: any) => void;
|
|
26
|
-
trace: (msg: any) => void;
|
|
27
|
-
child: (
|
|
21
|
+
info: (msg: any, ...args: any[]) => void;
|
|
22
|
+
error: (msg: any, ...args: any[]) => void;
|
|
23
|
+
warn: (msg: any, ...args: any[]) => void;
|
|
24
|
+
debug: (msg: any, ...args: any[]) => void;
|
|
25
|
+
fatal: (msg: any, ...args: any[]) => void;
|
|
26
|
+
trace: (msg: any, ...args: any[]) => void;
|
|
27
|
+
child: (bindings: any) => FastifyLogger;
|
|
28
28
|
}
|
package/package.json
CHANGED
package/src/logger.ts
CHANGED
|
@@ -110,36 +110,38 @@ export function createLogger(config: LoggerConfig): { logger: Logger; fastifyLog
|
|
|
110
110
|
|
|
111
111
|
const fastifyLogger: FastifyLogger = {
|
|
112
112
|
// Stringify potential objects passed to info/warn
|
|
113
|
-
info: (msg) => {
|
|
113
|
+
info: (msg: any, ...args: any[]) => {
|
|
114
114
|
const messageString = typeof msg === 'object' ? jsonStringify(msg) : String(msg);
|
|
115
115
|
log("info", messageString);
|
|
116
116
|
// storeInDB("info", messageString); // Keep commented out as original
|
|
117
117
|
},
|
|
118
|
-
error: (
|
|
119
|
-
const errorMessage = (
|
|
118
|
+
error: (msg: any, ...args: any[]) => {
|
|
119
|
+
const errorMessage = (msg && msg.message) ? msg.message : String(msg);
|
|
120
|
+
const meta = args.length > 0 ? args[0] : undefined;
|
|
120
121
|
log("error", errorMessage, meta);
|
|
121
122
|
// Ensure string is passed to storeInDB
|
|
122
|
-
storeInDB("error", typeof
|
|
123
|
+
storeInDB("error", typeof msg === 'object' ? jsonStringify(msg) : errorMessage, meta);
|
|
123
124
|
},
|
|
124
|
-
warn: (msg) => {
|
|
125
|
+
warn: (msg: any, ...args: any[]) => {
|
|
125
126
|
const messageString = typeof msg === 'object' ? jsonStringify(msg) : String(msg);
|
|
126
127
|
log("warn", messageString);
|
|
127
128
|
storeInDB("warn", messageString); // Pass stringified message
|
|
128
129
|
},
|
|
129
130
|
|
|
130
131
|
// do not store debug logs in DB
|
|
131
|
-
debug: (msg) => {
|
|
132
|
-
log("debug", msg);
|
|
132
|
+
debug: (msg: any, ...args: any[]) => {
|
|
133
|
+
log("debug", String(msg));
|
|
133
134
|
},
|
|
134
135
|
|
|
135
|
-
fatal: (msg) => {
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
fatal: (msg: any, ...args: any[]) => {
|
|
137
|
+
const messageString = typeof msg === 'object' ? jsonStringify(msg) : String(msg);
|
|
138
|
+
log("error", messageString);
|
|
139
|
+
storeInDB("error", messageString);
|
|
138
140
|
process.exit(1);
|
|
139
141
|
},
|
|
140
142
|
|
|
141
|
-
trace: (msg) => {},
|
|
142
|
-
child: (
|
|
143
|
+
trace: (msg: any, ...args: any[]) => {},
|
|
144
|
+
child: (bindings: any) => {
|
|
143
145
|
return fastifyLogger;
|
|
144
146
|
},
|
|
145
147
|
};
|
package/src/types.ts
CHANGED
|
@@ -21,11 +21,11 @@ export interface Logger {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface FastifyLogger {
|
|
24
|
-
info: (msg: any) => void;
|
|
25
|
-
error: (
|
|
26
|
-
warn: (msg: any) => void;
|
|
27
|
-
debug: (msg: any) => void;
|
|
28
|
-
fatal: (msg: any) => void;
|
|
29
|
-
trace: (msg: any) => void;
|
|
30
|
-
child: (
|
|
24
|
+
info: (msg: any, ...args: any[]) => void;
|
|
25
|
+
error: (msg: any, ...args: any[]) => void;
|
|
26
|
+
warn: (msg: any, ...args: any[]) => void;
|
|
27
|
+
debug: (msg: any, ...args: any[]) => void;
|
|
28
|
+
fatal: (msg: any, ...args: any[]) => void;
|
|
29
|
+
trace: (msg: any, ...args: any[]) => void;
|
|
30
|
+
child: (bindings: any) => FastifyLogger;
|
|
31
31
|
}
|