@rawnodes/logger 1.9.1 → 2.0.0
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/index.d.mts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.js +488 -328
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +487 -326
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
declare const LOG_LEVELS: {
|
|
@@ -47,6 +47,7 @@ interface HttpTransportBaseConfig {
|
|
|
47
47
|
}
|
|
48
48
|
interface DiscordConfig extends HttpTransportBaseConfig {
|
|
49
49
|
webhookUrl: string;
|
|
50
|
+
format?: 'embed' | 'markdown';
|
|
50
51
|
username?: string;
|
|
51
52
|
avatarUrl?: string;
|
|
52
53
|
embedColors?: Partial<Record<LogLevel, number>>;
|
|
@@ -104,6 +105,7 @@ declare class LoggerStore<TContext extends LoggerContext = LoggerContext> {
|
|
|
104
105
|
declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
105
106
|
private state;
|
|
106
107
|
private context;
|
|
108
|
+
private profileTimers;
|
|
107
109
|
private constructor();
|
|
108
110
|
static create<TContext extends LoggerContext = LoggerContext>(config: LoggerConfig, store?: LoggerStore<TContext>): Logger<TContext>;
|
|
109
111
|
for(context: string): Logger<TContext>;
|
|
@@ -113,7 +115,7 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
|
113
115
|
clearLevelOverrides(): void;
|
|
114
116
|
getLevelOverrides(): LevelOverride<TContext>[];
|
|
115
117
|
profile(id: string, meta?: object): void;
|
|
116
|
-
error(
|
|
118
|
+
error(errorOrMessage: Error | string, messageOrMeta?: string | Meta, meta?: Meta): void;
|
|
117
119
|
warn(message: string, meta?: Meta): void;
|
|
118
120
|
info(message: string, meta?: Meta): void;
|
|
119
121
|
http(message: string, meta?: Meta): void;
|
|
@@ -121,6 +123,7 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
|
121
123
|
debug(message: string, meta?: Meta): void;
|
|
122
124
|
silly(message: string, meta?: Meta): void;
|
|
123
125
|
private log;
|
|
126
|
+
private getPinoMethod;
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
interface SingletonLogger<TContext extends LoggerContext> {
|
|
@@ -176,7 +179,7 @@ interface BaseHttpTransportOptions {
|
|
|
176
179
|
maxRetries?: number;
|
|
177
180
|
retryDelay?: number;
|
|
178
181
|
}
|
|
179
|
-
declare abstract class BaseHttpTransport extends
|
|
182
|
+
declare abstract class BaseHttpTransport extends EventEmitter {
|
|
180
183
|
protected buffer: MessageBuffer;
|
|
181
184
|
constructor(opts?: BaseHttpTransportOptions);
|
|
182
185
|
log(info: Record<string, unknown>, callback: () => void): void;
|
|
@@ -190,6 +193,10 @@ declare class DiscordTransport extends BaseHttpTransport {
|
|
|
190
193
|
private config;
|
|
191
194
|
constructor(config: DiscordConfig);
|
|
192
195
|
protected sendBatch(messages: BufferedMessage[]): Promise<void>;
|
|
196
|
+
private sendEmbedBatch;
|
|
197
|
+
private sendMarkdownBatch;
|
|
198
|
+
private formatMarkdown;
|
|
199
|
+
private splitContent;
|
|
193
200
|
private createEmbed;
|
|
194
201
|
private metaToFields;
|
|
195
202
|
private sendWebhook;
|
|
@@ -272,8 +279,22 @@ declare const TelegramConfigSchema: z.ZodType<TelegramConfig>;
|
|
|
272
279
|
declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
|
|
273
280
|
declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
|
|
274
281
|
declare const LevelConfigSchema: z.ZodType<LevelConfig>;
|
|
275
|
-
declare const LoggerConfigSchema: z.
|
|
282
|
+
declare const LoggerConfigSchema: z.ZodObject<{
|
|
283
|
+
level: z.ZodType<LevelConfig, unknown, z.core.$ZodTypeInternals<LevelConfig, unknown>>;
|
|
284
|
+
console: z.ZodType<ConsoleConfig, unknown, z.core.$ZodTypeInternals<ConsoleConfig, unknown>>;
|
|
285
|
+
file: z.ZodOptional<z.ZodType<FileConfig, unknown, z.core.$ZodTypeInternals<FileConfig, unknown>>>;
|
|
286
|
+
discord: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>, z.ZodArray<z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>>]>>;
|
|
287
|
+
telegram: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>, z.ZodArray<z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>>]>>;
|
|
288
|
+
cloudwatch: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>, z.ZodArray<z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>>]>>;
|
|
289
|
+
}, z.core.$strip>;
|
|
276
290
|
declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
|
|
277
|
-
declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<
|
|
291
|
+
declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
292
|
+
level: LevelConfig;
|
|
293
|
+
console: ConsoleConfig;
|
|
294
|
+
file?: FileConfig | undefined;
|
|
295
|
+
discord?: DiscordConfig | DiscordConfig[] | undefined;
|
|
296
|
+
telegram?: TelegramConfig | TelegramConfig[] | undefined;
|
|
297
|
+
cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
|
|
298
|
+
}>;
|
|
278
299
|
|
|
279
300
|
export { BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatLogfmt, formatLogfmtValue, generateRequestId, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
declare const LOG_LEVELS: {
|
|
@@ -47,6 +47,7 @@ interface HttpTransportBaseConfig {
|
|
|
47
47
|
}
|
|
48
48
|
interface DiscordConfig extends HttpTransportBaseConfig {
|
|
49
49
|
webhookUrl: string;
|
|
50
|
+
format?: 'embed' | 'markdown';
|
|
50
51
|
username?: string;
|
|
51
52
|
avatarUrl?: string;
|
|
52
53
|
embedColors?: Partial<Record<LogLevel, number>>;
|
|
@@ -104,6 +105,7 @@ declare class LoggerStore<TContext extends LoggerContext = LoggerContext> {
|
|
|
104
105
|
declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
105
106
|
private state;
|
|
106
107
|
private context;
|
|
108
|
+
private profileTimers;
|
|
107
109
|
private constructor();
|
|
108
110
|
static create<TContext extends LoggerContext = LoggerContext>(config: LoggerConfig, store?: LoggerStore<TContext>): Logger<TContext>;
|
|
109
111
|
for(context: string): Logger<TContext>;
|
|
@@ -113,7 +115,7 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
|
113
115
|
clearLevelOverrides(): void;
|
|
114
116
|
getLevelOverrides(): LevelOverride<TContext>[];
|
|
115
117
|
profile(id: string, meta?: object): void;
|
|
116
|
-
error(
|
|
118
|
+
error(errorOrMessage: Error | string, messageOrMeta?: string | Meta, meta?: Meta): void;
|
|
117
119
|
warn(message: string, meta?: Meta): void;
|
|
118
120
|
info(message: string, meta?: Meta): void;
|
|
119
121
|
http(message: string, meta?: Meta): void;
|
|
@@ -121,6 +123,7 @@ declare class Logger<TContext extends LoggerContext = LoggerContext> {
|
|
|
121
123
|
debug(message: string, meta?: Meta): void;
|
|
122
124
|
silly(message: string, meta?: Meta): void;
|
|
123
125
|
private log;
|
|
126
|
+
private getPinoMethod;
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
interface SingletonLogger<TContext extends LoggerContext> {
|
|
@@ -176,7 +179,7 @@ interface BaseHttpTransportOptions {
|
|
|
176
179
|
maxRetries?: number;
|
|
177
180
|
retryDelay?: number;
|
|
178
181
|
}
|
|
179
|
-
declare abstract class BaseHttpTransport extends
|
|
182
|
+
declare abstract class BaseHttpTransport extends EventEmitter {
|
|
180
183
|
protected buffer: MessageBuffer;
|
|
181
184
|
constructor(opts?: BaseHttpTransportOptions);
|
|
182
185
|
log(info: Record<string, unknown>, callback: () => void): void;
|
|
@@ -190,6 +193,10 @@ declare class DiscordTransport extends BaseHttpTransport {
|
|
|
190
193
|
private config;
|
|
191
194
|
constructor(config: DiscordConfig);
|
|
192
195
|
protected sendBatch(messages: BufferedMessage[]): Promise<void>;
|
|
196
|
+
private sendEmbedBatch;
|
|
197
|
+
private sendMarkdownBatch;
|
|
198
|
+
private formatMarkdown;
|
|
199
|
+
private splitContent;
|
|
193
200
|
private createEmbed;
|
|
194
201
|
private metaToFields;
|
|
195
202
|
private sendWebhook;
|
|
@@ -272,8 +279,22 @@ declare const TelegramConfigSchema: z.ZodType<TelegramConfig>;
|
|
|
272
279
|
declare const CloudWatchConfigSchema: z.ZodType<CloudWatchConfig>;
|
|
273
280
|
declare const LevelConfigObjectSchema: z.ZodType<LevelConfigObject>;
|
|
274
281
|
declare const LevelConfigSchema: z.ZodType<LevelConfig>;
|
|
275
|
-
declare const LoggerConfigSchema: z.
|
|
282
|
+
declare const LoggerConfigSchema: z.ZodObject<{
|
|
283
|
+
level: z.ZodType<LevelConfig, unknown, z.core.$ZodTypeInternals<LevelConfig, unknown>>;
|
|
284
|
+
console: z.ZodType<ConsoleConfig, unknown, z.core.$ZodTypeInternals<ConsoleConfig, unknown>>;
|
|
285
|
+
file: z.ZodOptional<z.ZodType<FileConfig, unknown, z.core.$ZodTypeInternals<FileConfig, unknown>>>;
|
|
286
|
+
discord: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>, z.ZodArray<z.ZodType<DiscordConfig, unknown, z.core.$ZodTypeInternals<DiscordConfig, unknown>>>]>>;
|
|
287
|
+
telegram: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>, z.ZodArray<z.ZodType<TelegramConfig, unknown, z.core.$ZodTypeInternals<TelegramConfig, unknown>>>]>>;
|
|
288
|
+
cloudwatch: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>, z.ZodArray<z.ZodType<CloudWatchConfig, unknown, z.core.$ZodTypeInternals<CloudWatchConfig, unknown>>>]>>;
|
|
289
|
+
}, z.core.$strip>;
|
|
276
290
|
declare function validateConfig(config: unknown): z.infer<typeof LoggerConfigSchema>;
|
|
277
|
-
declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<
|
|
291
|
+
declare function safeValidateConfig(config: unknown): z.ZodSafeParseResult<{
|
|
292
|
+
level: LevelConfig;
|
|
293
|
+
console: ConsoleConfig;
|
|
294
|
+
file?: FileConfig | undefined;
|
|
295
|
+
discord?: DiscordConfig | DiscordConfig[] | undefined;
|
|
296
|
+
telegram?: TelegramConfig | TelegramConfig[] | undefined;
|
|
297
|
+
cloudwatch?: CloudWatchConfig | CloudWatchConfig[] | undefined;
|
|
298
|
+
}>;
|
|
278
299
|
|
|
279
300
|
export { BaseHttpTransport, type BaseHttpTransportOptions, type BufferOptions, type BufferedMessage, type CloudWatchConfig, CloudWatchConfigSchema, CloudWatchTransport, type ConsoleConfig, ConsoleConfigSchema, type DiscordConfig, DiscordConfigSchema, DiscordTransport, type FileConfig, FileConfigSchema, type HttpTransportBaseConfig, HttpTransportBaseConfigSchema, LOG_LEVELS, type LevelConfig, type LevelConfigObject, LevelConfigObjectSchema, LevelConfigSchema, type LevelOverride, type LevelOverrideMatch, type LevelRule, LevelRuleSchema, type LogFormat, LogFormatSchema, type LogLevel, LogLevelSchema, Logger, type LoggerConfig, LoggerConfigSchema, type LoggerContext, LoggerStore, type MaskSecretsOptions, MessageBuffer, type Meta, type RequestIdOptions, type SingletonLogger, type TelegramConfig, TelegramConfigSchema, TelegramTransport, type TimingResult, assertLogLevel, createMasker, createSingletonLogger, extractRequestId, flattenObject, formatLogfmt, formatLogfmtValue, generateRequestId, getOrGenerateRequestId, isValidLogLevel, maskSecrets, matchesContext, measureAsync, measureSync, safeValidateConfig, validateConfig };
|