/**
 * Simple logger that just writes to the console.
 */ import { ILogger } from 'polar-shared/src/logger/ILogger' ; /**
 * A logger that calls a delegate with try/catch and then does a console.error
 * if the underlying logger fails.
 *
 */ export class SafeLogger implements ILogger { public readonly name : string ; private readonly delegate : ILogger ; constructor ( delegate ) { this . delegate = delegate ; this . name = 'safe-logger+' + delegate . name ; } public notice ( msg , ... args ) { this . withTryCatch ( ( ) => this . delegate . notice ( msg , ... args ) ) ; } public warn ( msg , ... args ) { this . withTryCatch ( ( ) => this . delegate . warn ( msg , ... args ) ) ; } public error ( msg , ... args ) { this . withTryCatch ( ( ) => this . delegate . error ( msg , ... args ) ) ; } public info ( msg , ... args ) { this . withTryCatch ( ( ) => this . delegate . info ( msg , ... args ) ) ; } public verbose ( msg , ... args ) { this . withTryCatch ( ( ) => this . delegate . verbose ( msg , ... args ) ) ; } public debug ( msg , ... args ) { this . withTryCatch ( ( ) => this . delegate . debug ( msg , ... args ) ) ; } public async sync ( ) { await this . delegate . sync ( ) ; } private withTryCatch ( logFunction ) { try { logFunction ( ) ; } catch ( e ) { console . error ( "Unable to log: " , e ) ; } } }