import { log as logStorage } from './storage' ; import { patchConsole } from './functions' ; const levels = { error : 1 , info : 2 , debug : 3 } ; let limitLevel = 3 ; patchConsole ( ) ; const Logger = { setLevel ( level ) { if ( ! levels [ level ] ) { level = 'error' ; } limitLevel = levels [ level ] ; } , write ( type , message , additional ? ) { if ( type === 'error' ) { this . error ( message ) ; } else { this . info ( message ) ; } return logStorage . add ( type , message , additional ) ; } } as ILogger ; Object . keys ( levels ) . forEach ( ( levelName ) => { const levelNumber = levels [ levelName ] ; Logger [ levelName ] = ( ... args ) => { if ( levelNumber <= limitLevel ) { console . groupCollapsed ( levelName ) ; console . info ( '' , ... args ) ; console . trace ( 'trace' ) ; console . groupEnd ( ) ; } } ; } ) ; export function logAndThrowError ( error ) { const logText = new Error ( error ) ; Logger . write ( 'error' , logText , 'logAndThrowError' ) ; throw logText ; } export function logAndRejectError ( error , reject ) { const logText = new Error ( error ) ; Logger . write ( 'error' , logText , 'logAndRejectError' ) ; reject ( logText ) ; } export { Logger } ;