-
Notifications
You must be signed in to change notification settings - Fork 67
/
structured-logger.ts
56 lines (51 loc) · 1.55 KB
/
structured-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
import { Logger } from "./logger";
import * as uuid from "uuid";
import pino from "pino";
import { JobDTO } from "../../client/job";
import { QueuesUpdateCronBody } from "../scheduler/types/queues/update-cron";
export class StructuredLogger implements Logger {
constructor(
public readonly log = pino({
level: process.env.LOG_LEVEL || "trace",
})
) {}
started(address: string, telemetryEnabled: boolean) {
this.log.info(`Listening on ${address}`);
if (telemetryEnabled) {
this.log.info(`
Quirrel collects completely anonymous telemetry data about general usage,
opt-out by setting the DISABLE_TELEMETRY environment variable.`);
}
}
executionErrored(
job: { tokenId: string; id: string; endpoint: string; body: string },
error: string
): void {
this.log.error({ error, job }, "Caught error during execution");
}
jobCreated(
job: JobDTO & {
tokenId: string;
}
): void {
this.log.info({ job }, "Created job.");
}
jobDeleted(job: { endpoint: string; id: string; tokenId: string }): void {
this.log.info({ job }, "Deleted job.");
}
cronUpdated(crons: QueuesUpdateCronBody, deleted: string[]): void {
this.log.info({ crons, deleted }, "updated crons");
}
startingExecution(job: {
id: string;
tokenId: string;
endpoint: string;
body: string;
}): () => void {
const child = this.log.child({ correlationId: uuid.v4() });
child.info({ job }, "Started execution of job.");
return () => {
child.info({ job }, "Ended execution of job");
};
}
}