import { Connector } from './connector' ; import { config , logPath , disableWatchdog , logLevel } from './config' ; import * as Winston from 'winston' ; export interface LoggerInstance extends Winston . LoggerInstance { warning : never ; } console . log ( 'process started' ) ; const logger = new Winston . Logger ( { } ) as LoggerInstance ; if ( logPath ) { logger . add ( Winston . transports . Console , { level : logLevel || 'verbose' , handleExceptions : true , json : false } ) ; logger . add ( Winston . transports . File , { level : logLevel || 'debug' , handleExceptions : true , json : true , filename : logPath } ) ; logger . info ( 'Logging to' , logPath ) ; const orgConsoleLog = console . log ; console . log = function ( ... args ) { if ( args . length >= 1 ) { logger . debug ( ... args ) ; orgConsoleLog ( ... args ) ; } } ; } else { logger . add ( Winston . transports . Console , { handleExceptions : true , json : true , level : logLevel , stringify : ( obj ) => { obj . localTimestamp = getCurrentTime ( ) ; obj . randomId = Math . round ( Math . random ( ) * 10000 ) ; return JSON . stringify ( obj ) ; } } ) ; logger . info ( 'Logging to Console' ) ; console . log = function ( ... args ) { if ( args . length >= 1 ) { logger . debug ( ... args ) ; } } ; } function getCurrentTime ( ) { const v = Date . now ( ) ; return new Date ( v ) . toISOString ( ) ; } process . on ( 'unhandledRejection' , ( reason , p ) => { logger . error ( 'Unhandled Promise rejection, see below' ) ; logger . error ( 'reason:' , reason ) ; logger . error ( 'promise:' , p ) ; } ) ; process . on ( 'warning' , ( e ) => { logger . warn ( 'Unhandled warning, see below' ) ; logger . error ( 'error' , e ) ; logger . error ( 'error.reason' , e . reason || e . message ) ; logger . error ( 'error.stack' , e . stack ) ; } ) ; logger . info ( '------------------------------------------------------------------' ) ; logger . info ( 'Starting Playout Gateway' ) ; if ( disableWatchdog ) logger . info ( 'Watchdog is disabled!' ) ; const connector = new Connector ( logger ) ; logger . info ( 'Core:          ' + config . core . host + ':' + config . core . port ) ; logger . info ( '------------------------------------------------------------------' ) ; connector . init ( config ) . catch ( ( e ) => { logger . error ( e ) ; } ) ;