@vercube/logger 0.0.48 → 1.0.0-beta.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/README.md +4 -3
- package/dist/Toolkit.d.mts +1 -0
- package/dist/Toolkit.mjs +2 -0
- package/dist/index.d.mts +125 -56
- package/dist/index.mjs +107 -76
- package/package.json +13 -5
- package/dist/Drivers/ConsoleProvider.d.mts +0 -21
- package/dist/Drivers/ConsoleProvider.mjs +0 -24
- package/dist/Drivers/JsonProvider.d.mts +0 -22
- package/dist/Drivers/JsonProvider.mjs +0 -26
- package/dist/LoggerProvider-6Hyw8mz_.mjs +0 -11
- package/dist/LoggerProvider-BcdoeL8E.d.mts +0 -57
- package/dist/Utils-DZA2B0cS.mjs +0 -38
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
&labelColor=%23000&color=%232f2f2f>)
|
|
13
13
|
&labelColor=%23000&color=%232f2f2f>)
|
|
14
14
|
|
|
15
|
-
**Structured logging
|
|
15
|
+
**Structured wide-event logging powered by [evlog](https://evlog.dev) - pretty in dev, JSON in production, with sampling, redaction and pluggable drains. Just inject `Logger` and go.**
|
|
16
16
|
|
|
17
17
|
[Website](https://vercube.dev) • [Documentation](https://vercube.dev/docs/getting-started)
|
|
18
18
|
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
|
|
21
21
|
## ✨ Features
|
|
22
22
|
|
|
23
|
-
- **
|
|
23
|
+
- **Powered by evlog** - structured, wide-event logging under a simple `Logger` API
|
|
24
24
|
- **Log levels** - debug, info, warn, error
|
|
25
|
-
- **
|
|
25
|
+
- **Wide events** - accumulate context with `set()` / `child()` and `emit()` once
|
|
26
|
+
- **Drains & adapters** - ship logs to Axiom, OTLP, Sentry, Datadog and more
|
|
26
27
|
- **DI integration** - just `@Inject(Logger)` wherever you need it
|
|
27
28
|
|
|
28
29
|
## 📦 Installation
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "evlog/toolkit";
|
package/dist/Toolkit.mjs
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -1,108 +1,177 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DrainContext, DrainFn, EnvironmentContext, ErrorOptions, EvlogError, Log, LogLevel, LogLevel as LogLevel$1, LoggerConfig, LoggerConfig as LoggerConfig$1, RedactConfig, RequestLogger, RequestLoggerOptions, SamplingConfig, WideEvent, createError, createLogger, createRequestLogger, defineError, defineErrorCatalog, initLogger, log, parseError } from "evlog";
|
|
2
2
|
|
|
3
|
+
//#region src/Types/LoggerTypes.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Types for the evlog-backed Vercube logger.
|
|
6
|
+
*
|
|
7
|
+
* @see https://evlog.dev
|
|
8
|
+
*/
|
|
9
|
+
declare namespace LoggerTypes {
|
|
10
|
+
/**
|
|
11
|
+
* Supported severity levels, aligned with evlog.
|
|
12
|
+
* Order: debug < info < warn < error.
|
|
13
|
+
*/
|
|
14
|
+
type Level = LogLevel$1;
|
|
15
|
+
/**
|
|
16
|
+
* Any value accepted by the logger methods.
|
|
17
|
+
*/
|
|
18
|
+
type Arg = unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Structured context merged into emitted (wide) events.
|
|
21
|
+
*/
|
|
22
|
+
type Context = Record<string, unknown>;
|
|
23
|
+
/**
|
|
24
|
+
* Logger configuration.
|
|
25
|
+
*
|
|
26
|
+
* Mirrors evlog's {@link LoggerConfig} and adds `logLevel` as a framework-level
|
|
27
|
+
* alias for evlog's `minLevel`.
|
|
28
|
+
*/
|
|
29
|
+
interface Options extends LoggerConfig$1 {
|
|
30
|
+
/**
|
|
31
|
+
* Minimum severity for the simple log API.
|
|
32
|
+
* Alias for evlog's `minLevel`; takes precedence when both are provided.
|
|
33
|
+
*/
|
|
34
|
+
logLevel?: Level;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
3
38
|
//#region src/Common/Logger.d.ts
|
|
4
39
|
/**
|
|
5
|
-
* Abstract base class for
|
|
6
|
-
*
|
|
7
|
-
*
|
|
40
|
+
* Abstract base class for the Vercube logger.
|
|
41
|
+
*
|
|
42
|
+
* Defines the dependency-injection contract used across the framework. The
|
|
43
|
+
* default implementation ({@link BaseLogger}) is backed by evlog
|
|
44
|
+
* (https://evlog.dev) and forwards calls to evlog's logging API.
|
|
8
45
|
*/
|
|
9
46
|
declare abstract class Logger {
|
|
10
47
|
/**
|
|
11
|
-
* Configures the logger
|
|
12
|
-
*
|
|
48
|
+
* Configures the underlying logger.
|
|
49
|
+
* Maps to evlog's `initLogger` under the hood.
|
|
50
|
+
*
|
|
13
51
|
* @param options - Configuration options for the logger
|
|
14
|
-
* @returns void or Promise<void> if configuration is asynchronous
|
|
15
52
|
*/
|
|
16
53
|
abstract configure(options: LoggerTypes.Options): void;
|
|
17
54
|
/**
|
|
18
|
-
* Logs a message
|
|
19
|
-
* @param args -
|
|
20
|
-
* @returns A value determined by the implementing class
|
|
55
|
+
* Logs a debug message.
|
|
56
|
+
* @param args - Values to log (strings, objects, errors)
|
|
21
57
|
*/
|
|
22
58
|
abstract debug(...args: LoggerTypes.Arg[]): void;
|
|
23
59
|
/**
|
|
24
60
|
* Logs an informational message.
|
|
25
|
-
* @param args -
|
|
26
|
-
* @returns A value determined by the implementing class
|
|
61
|
+
* @param args - Values to log (strings, objects, errors)
|
|
27
62
|
*/
|
|
28
63
|
abstract info(...args: LoggerTypes.Arg[]): void;
|
|
29
64
|
/**
|
|
30
65
|
* Logs a warning message.
|
|
31
|
-
* @param args -
|
|
32
|
-
* @returns A value determined by the implementing class
|
|
66
|
+
* @param args - Values to log (strings, objects, errors)
|
|
33
67
|
*/
|
|
34
68
|
abstract warn(...args: LoggerTypes.Arg[]): void;
|
|
35
69
|
/**
|
|
36
70
|
* Logs an error message.
|
|
37
|
-
* @param args -
|
|
38
|
-
* @returns A value determined by the implementing class
|
|
71
|
+
* @param args - Values to log (strings, objects, errors)
|
|
39
72
|
*/
|
|
40
73
|
abstract error(...args: LoggerTypes.Arg[]): void;
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/Service/BaseLogger.d.ts
|
|
44
|
-
declare class BaseLogger implements Logger {
|
|
45
|
-
private gContainer;
|
|
46
74
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
75
|
+
* Merges structured context into every subsequent event emitted by this logger.
|
|
76
|
+
* Enables wide-event style logging without a request lifecycle.
|
|
77
|
+
*
|
|
78
|
+
* @param context - Structured fields to attach
|
|
79
|
+
*/
|
|
80
|
+
abstract set(context: LoggerTypes.Context): void;
|
|
81
|
+
/**
|
|
82
|
+
* Returns a shallow copy of the context accumulated on this logger.
|
|
83
|
+
*/
|
|
84
|
+
abstract getContext(): LoggerTypes.Context;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a derived logger inheriting this logger's context, merged with
|
|
87
|
+
* the provided additional context.
|
|
88
|
+
*
|
|
89
|
+
* @param context - Extra context for the child logger
|
|
49
90
|
*/
|
|
50
|
-
|
|
91
|
+
abstract child(context: LoggerTypes.Context): Logger;
|
|
51
92
|
/**
|
|
52
|
-
*
|
|
93
|
+
* Emits the accumulated context as a single consolidated wide event, then
|
|
94
|
+
* resets it.
|
|
95
|
+
*
|
|
96
|
+
* @param overrides - Additional fields merged into the emitted event
|
|
53
97
|
*/
|
|
54
|
-
|
|
98
|
+
abstract emit(overrides?: LoggerTypes.Context): void;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/Service/BaseLogger.d.ts
|
|
102
|
+
/**
|
|
103
|
+
* Default {@link Logger} implementation backed by evlog (https://evlog.dev).
|
|
104
|
+
*
|
|
105
|
+
* `debug` / `info` / `warn` / `error` forward to evlog's simple `log` API
|
|
106
|
+
* (fire-and-forget, one event per call). Structured context registered via
|
|
107
|
+
* {@link BaseLogger.set} or {@link BaseLogger.child} is merged into every
|
|
108
|
+
* emitted event, providing wide-event style logging without a request
|
|
109
|
+
* lifecycle. For request-scoped wide events use the evlog toolkit
|
|
110
|
+
* (`@vercube/logger/toolkit`) together with the framework's request middleware.
|
|
111
|
+
*/
|
|
112
|
+
declare class BaseLogger extends Logger {
|
|
55
113
|
/**
|
|
56
|
-
*
|
|
114
|
+
* Accumulated structured context merged into every emitted event.
|
|
57
115
|
*/
|
|
58
|
-
private
|
|
116
|
+
private fContext;
|
|
59
117
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param options
|
|
118
|
+
* Configures the underlying evlog logger.
|
|
119
|
+
* @param options - Configuration options
|
|
62
120
|
*/
|
|
63
121
|
configure(options: LoggerTypes.Options): void;
|
|
64
122
|
/**
|
|
65
|
-
* Logs
|
|
66
|
-
* @param args -
|
|
67
|
-
* @returns A value determined by the implementing class
|
|
123
|
+
* Logs a debug message.
|
|
124
|
+
* @param args - Values to log
|
|
68
125
|
*/
|
|
69
126
|
debug(...args: LoggerTypes.Arg[]): void;
|
|
70
127
|
/**
|
|
71
128
|
* Logs an informational message.
|
|
72
|
-
* @param args -
|
|
73
|
-
* @returns A value determined by the implementing class
|
|
129
|
+
* @param args - Values to log
|
|
74
130
|
*/
|
|
75
131
|
info(...args: LoggerTypes.Arg[]): void;
|
|
76
132
|
/**
|
|
77
133
|
* Logs a warning message.
|
|
78
|
-
* @param args -
|
|
79
|
-
* @returns A value determined by the implementing class
|
|
134
|
+
* @param args - Values to log
|
|
80
135
|
*/
|
|
81
136
|
warn(...args: LoggerTypes.Arg[]): void;
|
|
82
137
|
/**
|
|
83
138
|
* Logs an error message.
|
|
84
|
-
* @param args -
|
|
85
|
-
* @returns A value determined by the implementing class
|
|
139
|
+
* @param args - Values to log
|
|
86
140
|
*/
|
|
87
141
|
error(...args: LoggerTypes.Arg[]): void;
|
|
88
142
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
143
|
+
* Merges structured context into every subsequent event.
|
|
144
|
+
* @param context - Structured fields to attach
|
|
145
|
+
*/
|
|
146
|
+
set(context: LoggerTypes.Context): void;
|
|
147
|
+
/**
|
|
148
|
+
* Returns a shallow copy of the accumulated context.
|
|
94
149
|
*/
|
|
95
|
-
|
|
150
|
+
getContext(): LoggerTypes.Context;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a derived logger inheriting this logger's context plus extra context.
|
|
153
|
+
* @param context - Extra context for the child logger
|
|
154
|
+
*/
|
|
155
|
+
child(context: LoggerTypes.Context): Logger;
|
|
156
|
+
/**
|
|
157
|
+
* Emits the accumulated context as a single wide event, then resets it.
|
|
158
|
+
* @param overrides - Additional fields merged into the emitted event
|
|
159
|
+
*/
|
|
160
|
+
emit(overrides?: LoggerTypes.Context): void;
|
|
161
|
+
/**
|
|
162
|
+
* Translates the framework's variadic logging calls into evlog events.
|
|
163
|
+
*
|
|
164
|
+
* Supported call shapes (mirroring the previous @vercube/logger behaviour):
|
|
165
|
+
* - `('tag', 'message')` → tagged log
|
|
166
|
+
* - `('message')` → message-only event
|
|
167
|
+
* - `(error)` / `('tag', error)` → structured error event
|
|
168
|
+
* - `('tag', { ...fields })` → wide event with extra fields
|
|
169
|
+
* - any mix of strings, objects and errors
|
|
170
|
+
*
|
|
171
|
+
* @param level - The severity level
|
|
172
|
+
* @param args - The raw arguments passed to the log method
|
|
173
|
+
*/
|
|
174
|
+
private dispatch;
|
|
96
175
|
}
|
|
97
176
|
//#endregion
|
|
98
|
-
|
|
99
|
-
type ColorTextFn = (text: string) => string;
|
|
100
|
-
/**
|
|
101
|
-
* Checks if target level is enabled.
|
|
102
|
-
* @param targetLevel target level
|
|
103
|
-
* @param logLevels array of enabled log levels
|
|
104
|
-
*/
|
|
105
|
-
declare function isLogLevelEnabled(targetLevel: LoggerTypes.Level, currentLevel: LoggerTypes.Level): boolean;
|
|
106
|
-
declare const colors: Record<string, ColorTextFn>;
|
|
107
|
-
//#endregion
|
|
108
|
-
export { BaseLogger, Logger, LoggerTypes, colors, isLogLevelEnabled };
|
|
177
|
+
export { BaseLogger, type DrainContext, type DrainFn, type EnvironmentContext, type ErrorOptions, EvlogError, type Log, type LogLevel, Logger, type LoggerConfig, LoggerTypes, type RedactConfig, type RequestLogger, type RequestLoggerOptions, type SamplingConfig, type WideEvent, createError, createLogger, createRequestLogger, defineError, defineErrorCatalog, initLogger, log, parseError };
|
package/dist/index.mjs
CHANGED
|
@@ -1,112 +1,143 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Container, Inject } from "@vercube/di";
|
|
1
|
+
import { EvlogError, createError, createLogger, createRequestLogger, defineError, defineErrorCatalog, initLogger, initLogger as initLogger$1, log, log as log$1, parseError } from "evlog";
|
|
3
2
|
//#region src/Common/Logger.ts
|
|
4
3
|
/**
|
|
5
|
-
* Abstract base class for
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Abstract base class for the Vercube logger.
|
|
5
|
+
*
|
|
6
|
+
* Defines the dependency-injection contract used across the framework. The
|
|
7
|
+
* default implementation ({@link BaseLogger}) is backed by evlog
|
|
8
|
+
* (https://evlog.dev) and forwards calls to evlog's logging API.
|
|
8
9
|
*/
|
|
9
10
|
var Logger = class {};
|
|
10
11
|
//#endregion
|
|
11
|
-
//#region \0@oxc-project+runtime@0.130.0/helpers/decorate.js
|
|
12
|
-
function __decorate(decorators, target, key, desc) {
|
|
13
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
16
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
12
|
//#region src/Service/BaseLogger.ts
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Default {@link Logger} implementation backed by evlog (https://evlog.dev).
|
|
15
|
+
*
|
|
16
|
+
* `debug` / `info` / `warn` / `error` forward to evlog's simple `log` API
|
|
17
|
+
* (fire-and-forget, one event per call). Structured context registered via
|
|
18
|
+
* {@link BaseLogger.set} or {@link BaseLogger.child} is merged into every
|
|
19
|
+
* emitted event, providing wide-event style logging without a request
|
|
20
|
+
* lifecycle. For request-scoped wide events use the evlog toolkit
|
|
21
|
+
* (`@vercube/logger/toolkit`) together with the framework's request middleware.
|
|
22
|
+
*/
|
|
23
|
+
var BaseLogger = class BaseLogger extends Logger {
|
|
31
24
|
/**
|
|
32
|
-
*
|
|
25
|
+
* Accumulated structured context merged into every emitted event.
|
|
33
26
|
*/
|
|
34
|
-
|
|
27
|
+
fContext = {};
|
|
35
28
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @param options
|
|
29
|
+
* Configures the underlying evlog logger.
|
|
30
|
+
* @param options - Configuration options
|
|
38
31
|
*/
|
|
39
32
|
configure(options) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
provider.initialize(logger.options);
|
|
46
|
-
this.fProviders.set(logger.name, provider);
|
|
47
|
-
this.fProvidersLevel.set(logger.name, logger.logLevel ?? this.fLogLevel);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error(`Failed to initialize logger provider: ${logger.provider.name}`, error);
|
|
50
|
-
}
|
|
33
|
+
const { logLevel, ...config } = options ?? {};
|
|
34
|
+
initLogger$1({
|
|
35
|
+
...config,
|
|
36
|
+
minLevel: logLevel ?? config.minLevel
|
|
37
|
+
});
|
|
51
38
|
}
|
|
52
39
|
/**
|
|
53
|
-
* Logs
|
|
54
|
-
* @param args -
|
|
55
|
-
* @returns A value determined by the implementing class
|
|
40
|
+
* Logs a debug message.
|
|
41
|
+
* @param args - Values to log
|
|
56
42
|
*/
|
|
57
43
|
debug(...args) {
|
|
58
|
-
this.
|
|
59
|
-
level: "debug",
|
|
60
|
-
args
|
|
61
|
-
});
|
|
44
|
+
this.dispatch("debug", args);
|
|
62
45
|
}
|
|
63
46
|
/**
|
|
64
47
|
* Logs an informational message.
|
|
65
|
-
* @param args -
|
|
66
|
-
* @returns A value determined by the implementing class
|
|
48
|
+
* @param args - Values to log
|
|
67
49
|
*/
|
|
68
50
|
info(...args) {
|
|
69
|
-
this.
|
|
70
|
-
level: "info",
|
|
71
|
-
args
|
|
72
|
-
});
|
|
51
|
+
this.dispatch("info", args);
|
|
73
52
|
}
|
|
74
53
|
/**
|
|
75
54
|
* Logs a warning message.
|
|
76
|
-
* @param args -
|
|
77
|
-
* @returns A value determined by the implementing class
|
|
55
|
+
* @param args - Values to log
|
|
78
56
|
*/
|
|
79
57
|
warn(...args) {
|
|
80
|
-
this.
|
|
81
|
-
level: "warn",
|
|
82
|
-
args
|
|
83
|
-
});
|
|
58
|
+
this.dispatch("warn", args);
|
|
84
59
|
}
|
|
85
60
|
/**
|
|
86
61
|
* Logs an error message.
|
|
87
|
-
* @param args -
|
|
88
|
-
* @returns A value determined by the implementing class
|
|
62
|
+
* @param args - Values to log
|
|
89
63
|
*/
|
|
90
64
|
error(...args) {
|
|
91
|
-
this.
|
|
92
|
-
level: "error",
|
|
93
|
-
args
|
|
94
|
-
});
|
|
65
|
+
this.dispatch("error", args);
|
|
95
66
|
}
|
|
96
67
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @param message - The log message object containing level, tag, and arguments
|
|
100
|
-
* @throws {Error} When called directly on BaseLogger (must be implemented by subclass)
|
|
101
|
-
* @protected
|
|
68
|
+
* Merges structured context into every subsequent event.
|
|
69
|
+
* @param context - Structured fields to attach
|
|
102
70
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
71
|
+
set(context) {
|
|
72
|
+
Object.assign(this.fContext, context);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns a shallow copy of the accumulated context.
|
|
76
|
+
*/
|
|
77
|
+
getContext() {
|
|
78
|
+
return { ...this.fContext };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a derived logger inheriting this logger's context plus extra context.
|
|
82
|
+
* @param context - Extra context for the child logger
|
|
83
|
+
*/
|
|
84
|
+
child(context) {
|
|
85
|
+
const child = new BaseLogger();
|
|
86
|
+
child.fContext = {
|
|
87
|
+
...this.fContext,
|
|
88
|
+
...context
|
|
89
|
+
};
|
|
90
|
+
return child;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Emits the accumulated context as a single wide event, then resets it.
|
|
94
|
+
* @param overrides - Additional fields merged into the emitted event
|
|
95
|
+
*/
|
|
96
|
+
emit(overrides = {}) {
|
|
97
|
+
const event = {
|
|
98
|
+
...this.fContext,
|
|
99
|
+
...overrides
|
|
100
|
+
};
|
|
101
|
+
if (Object.keys(event).length === 0) return;
|
|
102
|
+
log$1.info(event);
|
|
103
|
+
this.fContext = {};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Translates the framework's variadic logging calls into evlog events.
|
|
107
|
+
*
|
|
108
|
+
* Supported call shapes (mirroring the previous @vercube/logger behaviour):
|
|
109
|
+
* - `('tag', 'message')` → tagged log
|
|
110
|
+
* - `('message')` → message-only event
|
|
111
|
+
* - `(error)` / `('tag', error)` → structured error event
|
|
112
|
+
* - `('tag', { ...fields })` → wide event with extra fields
|
|
113
|
+
* - any mix of strings, objects and errors
|
|
114
|
+
*
|
|
115
|
+
* @param level - The severity level
|
|
116
|
+
* @param args - The raw arguments passed to the log method
|
|
117
|
+
*/
|
|
118
|
+
dispatch(level, args) {
|
|
119
|
+
if (!(Object.keys(this.fContext).length > 0) && args.length === 2 && typeof args[0] === "string" && typeof args[1] === "string") {
|
|
120
|
+
log$1[level](args[0], args[1]);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const event = { ...this.fContext };
|
|
124
|
+
const messageParts = [];
|
|
125
|
+
let tag;
|
|
126
|
+
for (const arg of args) if (arg instanceof Error) event.error = {
|
|
127
|
+
name: arg.name,
|
|
128
|
+
message: arg.message,
|
|
129
|
+
stack: arg.stack
|
|
130
|
+
};
|
|
131
|
+
else if (arg !== null && typeof arg === "object") Object.assign(event, arg);
|
|
132
|
+
else if (typeof arg === "string" && tag === void 0) tag = arg;
|
|
133
|
+
else messageParts.push(String(arg));
|
|
134
|
+
if (tag !== void 0 && messageParts.length === 0) event.message = tag;
|
|
135
|
+
else {
|
|
136
|
+
if (tag !== void 0) event.tag = tag;
|
|
137
|
+
if (messageParts.length > 0) event.message = messageParts.join(" ");
|
|
138
|
+
}
|
|
139
|
+
log$1[level](event);
|
|
108
140
|
}
|
|
109
141
|
};
|
|
110
|
-
__decorate([Inject(Container)], BaseLogger.prototype, "gContainer", void 0);
|
|
111
142
|
//#endregion
|
|
112
|
-
export { BaseLogger, Logger,
|
|
143
|
+
export { BaseLogger, EvlogError, Logger, createError, createLogger, createRequestLogger, defineError, defineErrorCatalog, initLogger, log, parseError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercube/logger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
4
|
"description": "Logger module for Vercube framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,9 +13,16 @@
|
|
|
13
13
|
"main": "./dist/index.mjs",
|
|
14
14
|
"module": "./dist/index.mjs",
|
|
15
15
|
"exports": {
|
|
16
|
-
".":
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"./toolkit": {
|
|
22
|
+
"types": "./dist/Toolkit.d.mts",
|
|
23
|
+
"import": "./dist/Toolkit.mjs",
|
|
24
|
+
"default": "./dist/Toolkit.mjs"
|
|
25
|
+
},
|
|
19
26
|
"./package.json": "./package.json"
|
|
20
27
|
},
|
|
21
28
|
"types": "./dist/index.d.mts",
|
|
@@ -24,7 +31,8 @@
|
|
|
24
31
|
"README.md"
|
|
25
32
|
],
|
|
26
33
|
"dependencies": {
|
|
27
|
-
"
|
|
34
|
+
"evlog": "^2.19.0",
|
|
35
|
+
"@vercube/di": "1.0.0-beta.1"
|
|
28
36
|
},
|
|
29
37
|
"publishConfig": {
|
|
30
38
|
"access": "public"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { n as LoggerTypes, t as LoggerProvider } from "../LoggerProvider-BcdoeL8E.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/Drivers/ConsoleProvider.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* ConsoleProvider class for logging messages to the console.
|
|
6
|
-
*/
|
|
7
|
-
declare class ConsoleProvider extends LoggerProvider {
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the appender with the provided options.
|
|
10
|
-
* This method should be called before using the appender to process messages.
|
|
11
|
-
*/
|
|
12
|
-
initialize(): void;
|
|
13
|
-
/**
|
|
14
|
-
* Prints a log message according to the specified format and level.
|
|
15
|
-
* @param message - The log message object containing level, tag, and arguments
|
|
16
|
-
* @protected
|
|
17
|
-
*/
|
|
18
|
-
processMessage(message: LoggerTypes.Message): void;
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { ConsoleProvider };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { t as LoggerProvider } from "../LoggerProvider-6Hyw8mz_.mjs";
|
|
2
|
-
import { t as LOG_LEVEL_COLORS } from "../Utils-DZA2B0cS.mjs";
|
|
3
|
-
//#region src/Drivers/ConsoleProvider.ts
|
|
4
|
-
/**
|
|
5
|
-
* ConsoleProvider class for logging messages to the console.
|
|
6
|
-
*/
|
|
7
|
-
var ConsoleProvider = class extends LoggerProvider {
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the appender with the provided options.
|
|
10
|
-
* This method should be called before using the appender to process messages.
|
|
11
|
-
*/
|
|
12
|
-
initialize() {}
|
|
13
|
-
/**
|
|
14
|
-
* Prints a log message according to the specified format and level.
|
|
15
|
-
* @param message - The log message object containing level, tag, and arguments
|
|
16
|
-
* @protected
|
|
17
|
-
*/
|
|
18
|
-
processMessage(message) {
|
|
19
|
-
const date = message.timestamp ? new Date(message.timestamp) : /* @__PURE__ */ new Date();
|
|
20
|
-
console[message.level](`%s%s${message?.tag ? "%s" : ""} %s`, LOG_LEVEL_COLORS[message.level](`[${date.toISOString().split("T")[1]?.replace("Z", "")}]`), LOG_LEVEL_COLORS[message.level](`[${message.level.toUpperCase().padEnd(5, " ")}]`), message?.tag ? LOG_LEVEL_COLORS[message.level](`[${message.tag}]`) : "", ...message.args);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
24
|
-
export { ConsoleProvider };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { n as LoggerTypes, t as LoggerProvider } from "../LoggerProvider-BcdoeL8E.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/Drivers/JsonProvider.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* A logger implementation that formats log messages as JSON.
|
|
6
|
-
*/
|
|
7
|
-
declare class JSONProvider extends LoggerProvider {
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the appender with the provided options.
|
|
10
|
-
* This method should be called before using the appender to process messages.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
initialize(): void;
|
|
14
|
-
/**
|
|
15
|
-
* Prints a log message according to the specified format and level.
|
|
16
|
-
* @param message - The log message object containing level, tag, and arguments
|
|
17
|
-
* @protected
|
|
18
|
-
*/
|
|
19
|
-
processMessage(message: LoggerTypes.Message): void;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { JSONProvider };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { t as LoggerProvider } from "../LoggerProvider-6Hyw8mz_.mjs";
|
|
2
|
-
//#region src/Drivers/JsonProvider.ts
|
|
3
|
-
/**
|
|
4
|
-
* A logger implementation that formats log messages as JSON.
|
|
5
|
-
*/
|
|
6
|
-
var JSONProvider = class extends LoggerProvider {
|
|
7
|
-
/**
|
|
8
|
-
* Initializes the appender with the provided options.
|
|
9
|
-
* This method should be called before using the appender to process messages.
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
initialize() {}
|
|
13
|
-
/**
|
|
14
|
-
* Prints a log message according to the specified format and level.
|
|
15
|
-
* @param message - The log message object containing level, tag, and arguments
|
|
16
|
-
* @protected
|
|
17
|
-
*/
|
|
18
|
-
processMessage(message) {
|
|
19
|
-
console.log(JSON.stringify({
|
|
20
|
-
type: message?.type ?? "application_log",
|
|
21
|
-
...message
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//#endregion
|
|
26
|
-
export { JSONProvider };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/Common/LoggerProvider.ts
|
|
2
|
-
/**
|
|
3
|
-
* Abstract base class for implementing log provider.
|
|
4
|
-
* Providers are responsible for processing and outputting log messages to various destinations.
|
|
5
|
-
* Each appender can be initialized with custom options and handles message processing according to its implementation.
|
|
6
|
-
*
|
|
7
|
-
* @template T - The type of options used to initialize the appender
|
|
8
|
-
*/
|
|
9
|
-
var LoggerProvider = class {};
|
|
10
|
-
//#endregion
|
|
11
|
-
export { LoggerProvider as t };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { IOC } from "@vercube/di";
|
|
2
|
-
|
|
3
|
-
//#region src/Types/LoggerTypes.d.ts
|
|
4
|
-
declare namespace LoggerTypes {
|
|
5
|
-
type Level = 'debug' | 'info' | 'warn' | 'error';
|
|
6
|
-
type Arg = any;
|
|
7
|
-
interface Message {
|
|
8
|
-
level: Level;
|
|
9
|
-
args: Arg[];
|
|
10
|
-
tag?: string;
|
|
11
|
-
pid?: number;
|
|
12
|
-
type?: 'access_log' | 'application_log';
|
|
13
|
-
timestamp?: number;
|
|
14
|
-
}
|
|
15
|
-
type LogProviderOptions<T extends IOC.Newable<LoggerProvider>> = Parameters<InstanceType<T>['initialize']>[0] & {
|
|
16
|
-
logLevel?: Level;
|
|
17
|
-
};
|
|
18
|
-
interface LogAppender<T extends IOC.Newable<LoggerProvider>> {
|
|
19
|
-
name: string;
|
|
20
|
-
provider: T;
|
|
21
|
-
logLevel?: Level;
|
|
22
|
-
options?: LogProviderOptions<T>;
|
|
23
|
-
}
|
|
24
|
-
interface Options {
|
|
25
|
-
logLevel?: Level;
|
|
26
|
-
providers?: LogAppender<any>[];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/Common/LoggerProvider.d.ts
|
|
31
|
-
/**
|
|
32
|
-
* Abstract base class for implementing log provider.
|
|
33
|
-
* Providers are responsible for processing and outputting log messages to various destinations.
|
|
34
|
-
* Each appender can be initialized with custom options and handles message processing according to its implementation.
|
|
35
|
-
*
|
|
36
|
-
* @template T - The type of options used to initialize the appender
|
|
37
|
-
*/
|
|
38
|
-
declare abstract class LoggerProvider<T = unknown> {
|
|
39
|
-
/**
|
|
40
|
-
* Initializes the appender with the provided options.
|
|
41
|
-
* This method should be called before using the appender to process messages.
|
|
42
|
-
*
|
|
43
|
-
* @param options - Configuration options for the appender
|
|
44
|
-
* @returns void or Promise<void> if initialization is asynchronous
|
|
45
|
-
*/
|
|
46
|
-
abstract initialize(options: T): void | Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Processes a log message according to the appender's implementation.
|
|
49
|
-
* This method handles the actual logging logic specific to each appender type.
|
|
50
|
-
*
|
|
51
|
-
* @param message - The log message to process, containing level, tag, and other metadata
|
|
52
|
-
* @returns void or Promise<void> if processing is asynchronous
|
|
53
|
-
*/
|
|
54
|
-
abstract processMessage(message: LoggerTypes.Message): void | Promise<void>;
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { LoggerTypes as n, LoggerProvider as t };
|
package/dist/Utils-DZA2B0cS.mjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//#region src/Utils/Utils.ts
|
|
2
|
-
const LOG_LEVEL_VALUES = {
|
|
3
|
-
debug: 1,
|
|
4
|
-
info: 2,
|
|
5
|
-
warn: 3,
|
|
6
|
-
error: 4
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Checks if target level is enabled.
|
|
10
|
-
* @param targetLevel target level
|
|
11
|
-
* @param logLevels array of enabled log levels
|
|
12
|
-
*/
|
|
13
|
-
function isLogLevelEnabled(targetLevel, currentLevel) {
|
|
14
|
-
return LOG_LEVEL_VALUES[targetLevel] >= LOG_LEVEL_VALUES[currentLevel];
|
|
15
|
-
}
|
|
16
|
-
const isColorAllowed = () => !process.env.NO_COLOR;
|
|
17
|
-
const colorIfAllowed = (colorFn) => {
|
|
18
|
-
const wrappedFn = (text) => {
|
|
19
|
-
return isColorAllowed() ? colorFn(text) : text;
|
|
20
|
-
};
|
|
21
|
-
return wrappedFn;
|
|
22
|
-
};
|
|
23
|
-
const colors = {
|
|
24
|
-
bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
|
|
25
|
-
green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
|
|
26
|
-
yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
|
|
27
|
-
red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
|
|
28
|
-
magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
|
|
29
|
-
cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
|
|
30
|
-
};
|
|
31
|
-
const LOG_LEVEL_COLORS = {
|
|
32
|
-
debug: colors.green,
|
|
33
|
-
info: colors.bold,
|
|
34
|
-
warn: colors.yellow,
|
|
35
|
-
error: colors.red
|
|
36
|
-
};
|
|
37
|
-
//#endregion
|
|
38
|
-
export { colors as n, isLogLevelEnabled as r, LOG_LEVEL_COLORS as t };
|