All logs are now structured logs
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
All logs are now structured logs
|
||||
@@ -74,12 +74,11 @@ export class IndexEndpointService {
|
||||
|
||||
indexStats.jobs++;
|
||||
} catch (error) {
|
||||
logger.debug("Failed to register job", {
|
||||
logger.error("Failed to register job", {
|
||||
endpointId: endpoint.id,
|
||||
job,
|
||||
error,
|
||||
});
|
||||
|
||||
logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,12 +88,11 @@ export class IndexEndpointService {
|
||||
|
||||
indexStats.sources++;
|
||||
} catch (error) {
|
||||
logger.debug("Failed to register source", {
|
||||
logger.error("Failed to register source", {
|
||||
endpointId: endpoint.id,
|
||||
source,
|
||||
error,
|
||||
});
|
||||
|
||||
logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,12 +105,11 @@ export class IndexEndpointService {
|
||||
|
||||
indexStats.dynamicTriggers++;
|
||||
} catch (error) {
|
||||
logger.debug("Failed to register dynamic trigger", {
|
||||
logger.error("Failed to register dynamic trigger", {
|
||||
endpointId: endpoint.id,
|
||||
dynamicTrigger,
|
||||
error,
|
||||
});
|
||||
|
||||
logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,12 +122,11 @@ export class IndexEndpointService {
|
||||
|
||||
indexStats.dynamicSchedules++;
|
||||
} catch (error) {
|
||||
logger.debug("Failed to register dynamic schedule", {
|
||||
logger.error("Failed to register dynamic schedule", {
|
||||
endpointId: endpoint.id,
|
||||
dynamicSchedule,
|
||||
error,
|
||||
});
|
||||
|
||||
logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,44 +47,52 @@ export class Logger {
|
||||
return logLevels.indexOf(logLevel) <= logLevels.indexOf(setLevel);
|
||||
}
|
||||
|
||||
log(...args: any[]) {
|
||||
log(message: string, ...args: Array<Record<string, unknown> | undefined>) {
|
||||
if (this.#level < 0) return;
|
||||
|
||||
console.log(`[${formattedDateTime()}] [${this.#name}] `, ...args);
|
||||
this.#structuredLog(console.log, message, ...args);
|
||||
}
|
||||
|
||||
error(...args: any[]) {
|
||||
error(message: string, ...args: Array<Record<string, unknown> | undefined>) {
|
||||
if (this.#level < 1) return;
|
||||
|
||||
console.error(`[${formattedDateTime()}] [${this.#name}] `, ...args);
|
||||
this.#structuredLog(console.error, message, ...args);
|
||||
}
|
||||
|
||||
warn(...args: any[]) {
|
||||
warn(message: string, ...args: Array<Record<string, unknown> | undefined>) {
|
||||
if (this.#level < 2) return;
|
||||
|
||||
console.warn(`[${formattedDateTime()}] [${this.#name}] `, ...args);
|
||||
this.#structuredLog(console.warn, message, ...args);
|
||||
}
|
||||
|
||||
info(...args: any[]) {
|
||||
info(message: string, ...args: Array<Record<string, unknown> | undefined>) {
|
||||
if (this.#level < 3) return;
|
||||
|
||||
console.info(`[${formattedDateTime()}] [${this.#name}] `, ...args);
|
||||
this.#structuredLog(console.info, message, ...args);
|
||||
}
|
||||
|
||||
debug(message: string, ...args: Array<Record<string, unknown> | undefined>) {
|
||||
if (this.#level < 4) return;
|
||||
|
||||
this.#structuredLog(console.debug, message, ...args);
|
||||
}
|
||||
|
||||
#structuredLog(
|
||||
loggerFunction: (message: string, ...args: any[]) => void,
|
||||
message: string,
|
||||
...args: Array<Record<string, unknown> | undefined>
|
||||
) {
|
||||
const structuredLog = {
|
||||
timestamp: new Date(),
|
||||
name: this.#name,
|
||||
message,
|
||||
args: structureArgs(
|
||||
...structureArgs(
|
||||
safeJsonClone(args) as Record<string, unknown>[],
|
||||
this.#filteredKeys
|
||||
),
|
||||
timestamp: new Date(),
|
||||
name: this.#name,
|
||||
message,
|
||||
};
|
||||
|
||||
console.debug(
|
||||
loggerFunction(
|
||||
JSON.stringify(structuredLog, createReplacer(this.#jsonReplacer))
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user