/
Logger.ts
67 lines (55 loc) · 1.91 KB
/
Logger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { Dictionary, Highlighter } from '../typings';
export interface Logger {
/**
* Logs a message inside given namespace.
*/
log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
/**
* Logs error message inside given namespace.
*/
error(namespace: LoggerNamespace, message: string, context?: LogContext): void;
/**
* Logs warning message inside given namespace.
*/
warn(namespace: LoggerNamespace, message: string, context?: LogContext): void;
/**
* Logs a message inside given namespace.
*/
logQuery(context: LogContext): void;
/**
* Sets active namespaces. Pass `true` to enable all logging.
*/
setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
}
export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info';
export interface LogContext extends Dictionary {
query?: string;
label?: string;
params?: unknown[];
took?: number;
results?: number;
level?: 'info' | 'warning' | 'error';
enabled?: boolean;
debugMode?: LoggerNamespace[];
connection?: {
type?: string;
name?: string;
};
}
export interface LoggerOptions {
writer: (message: string) => void;
debugMode?: boolean | LoggerNamespace[];
highlighter?: Highlighter;
usesReplicas?: boolean;
}
/**
* Logger options to modify format output and overrides, including a label and additional properties that can be accessed by custom loggers
*
* Differs from {@link LoggerOptions} in terms of how they are used; this type is primarily a public type meant to be used within methods like `EntityManager.Find`
*
* @example
* await em.findOne(User, 1, { loggerContext: { label: 'user middleware' } };
* // [query] (user middleware) select * from user where id = 1;
*/
export type LoggingOptions = Pick<LogContext, 'label' | 'enabled' | 'debugMode'> & Dictionary;