-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathlogger.ts
41 lines (36 loc) · 1.12 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
// For backwards compatibility
if (process.env.GRAPHILE_WORKER_DEBUG) {
process.env.GRAPHILE_LOGGER_DEBUG = process.env.GRAPHILE_WORKER_DEBUG;
}
import {
LogFunctionFactory as GraphileLogFunctionFactory,
Logger as GraphileLogger,
LogLevel,
makeConsoleLogFactory,
} from "@graphile/logger";
export interface LogScope {
label?: string;
workerId?: string;
taskIdentifier?: string;
jobId?: string;
}
export { LogLevel };
// For backwards compatibility
export class Logger extends GraphileLogger<LogScope> {}
export type LogFunctionFactory = GraphileLogFunctionFactory<LogScope>;
export const consoleLogFactory = makeConsoleLogFactory<LogScope>();
export const defaultLogger = new Logger(
makeConsoleLogFactory({
format: `[%s%s] %s: %s`,
formatParameters(level, message, scope) {
const taskText = scope.taskIdentifier ? `: ${scope.taskIdentifier}` : "";
const jobIdText = scope.jobId ? `{${scope.jobId}}` : "";
return [
scope.label || "core",
scope.workerId ? `(${scope.workerId}${taskText}${jobIdText})` : "",
level.toUpperCase(),
message,
];
},
}),
);