import { ApolloPersistOptions , LogLevel , LogLine } from './types' ; export default class Log < T > { debug : boolean ; lines : Array < LogLine > ; static buffer = 30 ; static prefix = '[apollo-cache-persist]' ; constructor ( options ) { const { debug = false } = options ; this . debug = debug ; this . lines = [ ] ; } emit ( level , message ) { if ( level in console ) { const { prefix } = Log ; console [ level ] ( prefix , ... message ) ; } } tailLogs ( ) { this . lines . forEach ( ( [ level , message ] ) => this . emit ( level , message ) ) ; } getLogs ( ) { return this . lines ; } write ( level , message ) { const { buffer } = Log ; this . lines = [ ... this . lines . slice ( 1 - buffer ) , [ level , message ] ] ; if ( this . debug || level !== 'log' ) { this . emit ( level , message ) ; } } info ( ... message ) { this . write ( 'log' , message ) ; } warn ( ... message ) { this . write ( 'warn' , message ) ; } error ( ... message ) { this . write ( 'error' , message ) ; } }