Files
Superalgos/api/src/logger/index.js
T
2018-10-30 15:19:16 -07:00

34 lines
1004 B
JavaScript

import { createLogger, format, transports } from 'winston'
import { inspect } from 'util'
import { AuthentificationError, DatabaseError, WrongArgumentsError, ServiceUnavailableError } from './errors'
class LoggerService {
constructor() {
const winstonTransports = [
new transports.Console({
format: format.combine(
format.colorize(),
format.timestamp({ format: 'YY/MM/DD HH:mm' }),
format.printf(
info => `${info.timestamp} - ${info.level}: ${JSON.parse(JSON.stringify(inspect(info.message)))}`
)
),
}),
]
const logger = createLogger({
level: 'info',
transports: winstonTransports,
exceptionHandlers: winstonTransports,
})
return new Proxy(this, {
get: (target, propKey) => logger[propKey],
})
}
}
export const logger = new LoggerService() // Default logger
export { LoggerService, AuthentificationError, DatabaseError, WrongArgumentsError, ServiceUnavailableError }