Skip to content

Commit

Permalink
Update logger.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellrgn authored Feb 1, 2025
1 parent 4c4b2a2 commit 57e1d8b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,7 @@ export class Logger {
return {...defaults, ...logMessage};
}

public log(content: LogMessageSimple, dest?: string): void {
let logURL = dest ?? this.dest;
if (!logURL) {
console.log(JSON.stringify(content));
return;
}
if (!URL.canParse(logURL)) {
console.warn('Invalid log destination: ' + logURL);
console.log(JSON.stringify(content));
return;
}

public log(content: LogMessageSimple, dest?: string): void {
let defaults: Partial<LogMessage> = {
version: "2",
severity: "info",
Expand All @@ -101,8 +90,18 @@ export class Logger {
},
outcome: "", // failure or warning details
}

let logMessage: LogMessageSimple = this.applyLogFallbacks(content, defaults);

let logURL = dest ?? this.dest;
if (!logURL) {
console.log(JSON.stringify(content));
return;
}
if (!URL.canParse(logURL)) {
console.warn('Invalid log destination: ' + logURL);
console.log(JSON.stringify(content));
return;
}

fetch(logURL, {
method: "POST",
Expand All @@ -112,4 +111,4 @@ export class Logger {
body: JSON.stringify(logMessage),
});
}
}
}

0 comments on commit 57e1d8b

Please sign in to comment.