@graphql-hive/logger 0.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/Logger-BMj0djMW.d.ts +116 -0
- package/dist/index.cjs +761 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +754 -0
- package/dist/request.cjs +20 -0
- package/dist/request.d.cts +26 -0
- package/dist/request.d.ts +26 -0
- package/dist/request.js +17 -0
- package/package.json +58 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
type MaybeLazy<T> = T | (() => T);
|
|
2
|
+
type AttributeValue = any;
|
|
3
|
+
type Attributes = AttributeValue[] | {
|
|
4
|
+
[key: string | number]: AttributeValue;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
declare function jsonStringify(val: unknown, pretty?: boolean): string;
|
|
8
|
+
interface LogWriter {
|
|
9
|
+
write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void | Promise<void>;
|
|
10
|
+
flush(): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
declare class MemoryLogWriter implements LogWriter {
|
|
13
|
+
logs: {
|
|
14
|
+
level: LogLevel;
|
|
15
|
+
msg?: string;
|
|
16
|
+
attrs?: unknown;
|
|
17
|
+
}[];
|
|
18
|
+
write(level: LogLevel, attrs: Record<string, any>, msg: string | null | undefined): void;
|
|
19
|
+
flush(): void;
|
|
20
|
+
}
|
|
21
|
+
declare const asciMap: {
|
|
22
|
+
timestamp: string;
|
|
23
|
+
trace: string;
|
|
24
|
+
debug: string;
|
|
25
|
+
info: string;
|
|
26
|
+
warn: string;
|
|
27
|
+
error: string;
|
|
28
|
+
message: string;
|
|
29
|
+
reset: string;
|
|
30
|
+
};
|
|
31
|
+
declare class ConsoleLogWriter implements LogWriter {
|
|
32
|
+
#private;
|
|
33
|
+
color(style: keyof typeof asciMap, text: string | null | undefined): string | null | undefined;
|
|
34
|
+
write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void;
|
|
35
|
+
flush(): void;
|
|
36
|
+
}
|
|
37
|
+
declare class JSONLogWriter implements LogWriter {
|
|
38
|
+
write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void;
|
|
39
|
+
flush(): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
|
|
43
|
+
interface LoggerOptions {
|
|
44
|
+
/**
|
|
45
|
+
* The minimum log level to log.
|
|
46
|
+
*
|
|
47
|
+
* Providing `false` will disable all logging.
|
|
48
|
+
*
|
|
49
|
+
* Provided function will always be invoked to get the current log level.
|
|
50
|
+
*
|
|
51
|
+
* @default env.LOG_LEVEL || env.DEBUG ? 'debug' : 'info'
|
|
52
|
+
*/
|
|
53
|
+
level?: MaybeLazy<LogLevel | false>;
|
|
54
|
+
/** A prefix to include in every log's message. */
|
|
55
|
+
prefix?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The attributes to include in all logs. Is mainly used to pass the parent
|
|
58
|
+
* attributes when creating {@link Logger.child child loggers}.
|
|
59
|
+
*/
|
|
60
|
+
attrs?: Attributes;
|
|
61
|
+
/**
|
|
62
|
+
* The log writers to use when writing logs.
|
|
63
|
+
*
|
|
64
|
+
* @default [new ConsoleLogWriter()]
|
|
65
|
+
*/
|
|
66
|
+
writers?: [LogWriter, ...LogWriter[]];
|
|
67
|
+
}
|
|
68
|
+
declare class Logger implements LogWriter {
|
|
69
|
+
#private;
|
|
70
|
+
constructor(opts?: LoggerOptions);
|
|
71
|
+
/** The prefix that's prepended to each log message. */
|
|
72
|
+
get prefix(): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The attributes that are added to each log. If the log itself contains
|
|
75
|
+
* attributes with keys existing in {@link attrs}, the log's attributes will
|
|
76
|
+
* override.
|
|
77
|
+
*/
|
|
78
|
+
get attrs(): Attributes | undefined;
|
|
79
|
+
/** The current {@link LogLevel} of the logger. You can change the level using the {@link setLevel} method. */
|
|
80
|
+
get level(): false | LogLevel;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the new {@link LogLevel} of the logger. All subsequent logs, and {@link child child loggers} whose
|
|
83
|
+
* level did not change, will respect the new level.
|
|
84
|
+
*/
|
|
85
|
+
setLevel(level: MaybeLazy<LogLevel | false>): void;
|
|
86
|
+
write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void;
|
|
87
|
+
flush(): Promise<void> | undefined;
|
|
88
|
+
child(prefix: string): Logger;
|
|
89
|
+
child(attrs: Attributes, prefix?: string): Logger;
|
|
90
|
+
log(level: LogLevel): void;
|
|
91
|
+
log(level: LogLevel, attrs: MaybeLazy<Attributes>): void;
|
|
92
|
+
log(level: LogLevel, msg: string, ...interpol: unknown[]): void;
|
|
93
|
+
log(level: LogLevel, attrs: MaybeLazy<Attributes>, msg: string, ...interpol: unknown[]): void;
|
|
94
|
+
trace(): void;
|
|
95
|
+
trace(attrs: MaybeLazy<Attributes>): void;
|
|
96
|
+
trace(msg: string, ...interpol: unknown[]): void;
|
|
97
|
+
trace(attrs: MaybeLazy<Attributes>, msg: string, ...interpol: unknown[]): void;
|
|
98
|
+
debug(): void;
|
|
99
|
+
debug(attrs: MaybeLazy<Attributes>): void;
|
|
100
|
+
debug(msg: string, ...interpol: unknown[]): void;
|
|
101
|
+
debug(attrs: MaybeLazy<Attributes>, msg: string, ...interpol: unknown[]): void;
|
|
102
|
+
info(): void;
|
|
103
|
+
info(attrs: MaybeLazy<Attributes>): void;
|
|
104
|
+
info(msg: string, ...interpol: unknown[]): void;
|
|
105
|
+
info(attrs: MaybeLazy<Attributes>, msg: string, ...interpol: unknown[]): void;
|
|
106
|
+
warn(): void;
|
|
107
|
+
warn(attrs: MaybeLazy<Attributes>): void;
|
|
108
|
+
warn(msg: string, ...interpol: unknown[]): void;
|
|
109
|
+
warn(attrs: MaybeLazy<Attributes>, msg: string, ...interpol: unknown[]): void;
|
|
110
|
+
error(): void;
|
|
111
|
+
error(attrs: MaybeLazy<Attributes>): void;
|
|
112
|
+
error(msg: string, ...interpol: unknown[]): void;
|
|
113
|
+
error(attrs: MaybeLazy<Attributes>, msg: string, ...interpol: unknown[]): void;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { ConsoleLogWriter as C, JSONLogWriter as J, Logger as L, MemoryLogWriter as M, type LogLevel as a, type LoggerOptions as b, type LogWriter as c, jsonStringify as j };
|