/**
 * Simple logger that just writes to the console.
 */ import { ILogger } from 'polar-shared/src/logger/ILogger' ; import { SafeLogger } from './SafeLogger' ; /**
 * Allows us to log to multiple delegates at once.
 */ export class MultiLogger implements ILogger { public readonly name : string ; private readonly delegates : ILogger [ ] ; constructor ( ... delegates ) { delegates = MultiLogger . toSafeLoggers ( delegates ) ; this . delegates = delegates ; this . name = 'multi-logger|' + this . delegates . map ( delegate => delegate . name ) . join ( "+" ) ; } public notice ( msg , ... args ) { this . delegates . forEach ( delegate => delegate . notice ( msg , ... args ) ) ; } public warn ( msg , ... args ) { this . delegates . forEach ( delegate => delegate . warn ( msg , ... args ) ) ; } public error ( msg , ... args ) { this . delegates . forEach ( delegate => delegate . error ( msg , ... args ) ) ; } public info ( msg , ... args ) { this . delegates . forEach ( delegate => delegate . info ( msg , ... args ) ) ; } public verbose ( msg , ... args ) { this . delegates . forEach ( delegate => delegate . verbose ( msg , ... args ) ) ; } public debug ( msg , ... args ) { this . delegates . forEach ( delegate => delegate . debug ( msg , ... args ) ) ; } public async sync ( ) { for ( const delegate of this . delegates ) { await delegate . sync ( ) ; } } private static toSafeLoggers ( delegates ) { return delegates . map ( current => { if ( current instanceof SafeLogger ) { return current ; } else { return new SafeLogger ( current ) ; } } ) ; } }