import path from 'path' ; import bunyan , { Stream } from 'bunyan' ; import { lightFormat } from 'date-fns' ; import getSentryStream from './SentryStream' ; import { errorSerializer } from './serializer' ; type LoggingFunction = { ( error , message ? , ... params ) : void ; ( message , ... params ) : void ; ( data , message , ... params ) : void ; } ; export interface Logger { trace : LoggingFunction ; debug : LoggingFunction ; info : LoggingFunction ; warn : LoggingFunction ; error : LoggingFunction ; fatal : LoggingFunction ; child ( options ) : Logger ; } const logRoot = path . join ( __dirname , '../../../logs' ) ; const logSuffix = lightFormat ( new Date ( ) , 'yyyy-MM-dd.HH-mm-ss' ) ; const streams = process . env . NODE_ENV === 'production' ? [ { path : path . join ( logRoot , `info-${ logSuffix }.log` ) , level : 'info' , } , { path : path . join ( logRoot , `errors-${ logSuffix }.log` ) , level : 'error' , } , { type : 'raw' , level : 'error' , stream : getSentryStream ( { tags : [ 'service' , 'task' ] , extra : [ 'moduleCode' ] , } ) , } , ] : [ { stream : process . stdout , level : 'info' , } , { path : path . join ( logRoot , 'info.log' ) , level : 'debug' , } , { path : path . join ( logRoot , 'errors.log' ) , level : 'error' , } , ] ; const rootLogger = bunyan . createLogger ( { name : 'scraper' , serializers : { err : errorSerializer , } , streams , } ) ; export default rootLogger ;