Created
September 4, 2022 18:38
-
-
Save GautamPanickar/71fb4962fa59aeb532f4bb691b79927b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Winston from 'winston'; | |
import Secret from './secret'; | |
class Logger { | |
private logger: Winston.Logger; | |
public constructor() { | |
this.initializeLogger(); | |
} | |
/** | |
* Initializes the winston logger | |
*/ | |
private initializeLogger(): void { | |
this.logger = Winston.createLogger({ | |
transports: [ | |
new (Winston.transports.Console)({ | |
level: Secret.ENVIRONMENT === 'prod' ? 'error' : 'debug' | |
}), | |
new (Winston.transports.File)({ | |
filename: 'debug.log', | |
level: 'debug' | |
}) | |
] | |
}); | |
if (Secret.ENVIRONMENT !== 'prod') { | |
this.logger.debug('Logging initialized at debug level'); | |
} | |
} | |
/** | |
* Logs the message | |
* @param message | |
*/ | |
public info(message: string): void { | |
console.log(message); | |
this.logger.info(message); | |
} | |
/** | |
* Logs the error | |
* @param message | |
*/ | |
public logError(message: string): void { | |
console.log(message); | |
this.logger.error(message); | |
} | |
/** | |
* Logs the debug info | |
* @param message | |
*/ | |
public debug(message: string): void { | |
console.log(message); | |
this.logger.debug(message); | |
} | |
} | |
export default new Logger(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment