Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mendess committed Nov 28, 2024
1 parent efa342f commit c314109
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/context/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,19 @@ export class ConsoleLogger implements Logger {
// eslint-disable-next-line no-console
console.error(err.stack);
}
setTag(key: string, value: string): void { }
setSampleRate(sampleRate: number): void { }
addBreadcrumb(breadcrumb: Breadcrumb): void { }
setTag(key: string, value: string): void {}
setSampleRate(sampleRate: number): void {}
addBreadcrumb(breadcrumb: Breadcrumb): void {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
info(category: string, message: string, data?: { [key: string]: any }): void { }
info(category: string, message: string, data?: { [key: string]: any }): void {}
}

export class VoidLogger implements Logger {
setTag(key: string, value: string): void { }
setSampleRate(sampleRate: number): void { }
addBreadcrumb(breadcrumb: Breadcrumb): void { }
captureException(e: Error): void { }
info(category: string, message: string, data?: { [key: string]: any }): void { }
setTag(key: string, value: string): void {}
setSampleRate(sampleRate: number): void {}
addBreadcrumb(breadcrumb: Breadcrumb): void {}
captureException(e: Error): void {}
info(category: string, message: string, data?: { [key: string]: any }): void {}
}
/* eslint-enable */

Expand All @@ -179,7 +179,6 @@ export class WshimLogger {
private loggingEndpoint: string;

constructor(env: Bindings, sampleRate: number = 1) {

if (!env.WSHIM_TOKEN) {
throw new Error('Service token is required for WshimLogger');
}
Expand All @@ -189,21 +188,19 @@ export class WshimLogger {

this.serviceToken = env.WSHIM_TOKEN;
this.sampleRate = sampleRate;
this.fetcher = env.WSHIM_SOCKET
this.fetcher = env.WSHIM_SOCKET;
this.loggingEndpoint = `${env.WSHIM_ENDPOINT}/log`;
}

private shouldLog(): boolean {
return Math.random() < this.sampleRate;
}

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-explicit-any */
log(...msg: any[]): void {
if (!this.shouldLog()) return;

const message = msg
.map(o => (typeof o === 'object' ? JSON.stringify(o) : String(o)))
.join(' ');
const message = msg.map(o => (typeof o === 'object' ? JSON.stringify(o) : String(o))).join(' ');
const logEntry: LogEntry = { message, level: 'info' };

this.logs.push(logEntry);
Expand All @@ -230,7 +227,7 @@ export class WshimLogger {

this.logs.push(logEntry);
}
/* eslint-enable @typescript-eslint/no-explicit-any */
/* eslint-enable @typescript-eslint/no-explicit-any */

public async flushLogs(): Promise<void> {
if (this.logs.length === 0) return;
Expand Down

0 comments on commit c314109

Please sign in to comment.