Adapt logging to Heroku's logging technique
Firstly, this is an awesome project setup and it was very useful for an app I built recently. Thank you for making it.
The only way to read the logs from heroku is via an addon service or heroku's cli. I deployed the application on Heroku and I had to add logFileGenarationSupport config variable in src\config\config.ts that tells me if my deployment destination supports log file generation.
logFileGenarationSupport: process.env.LOG_FILE_GENERATION_SUPPORT || 'false',
I also modified the src\utils\logger.ts file to look like this:
let trans: any = [];
let logger: Logger;
if (logFileGenarationSupport == 'false') {
logger = createLogger({
level: logging.level,
format: combine(splat(), colorize(), timestamp(), formatter),
transports: [new transports.Console()]
});
} else {
if (!fs.existsSync('logs')) {
fs.mkdirSync('logs');
}
if (environment === 'development') {
trans = [new transports.Console()];
}
logger = createLogger({
level: logging.level,
format: combine(splat(), colorize(), timestamp(), formatter),
transports: [
...trans,
new DailyRotateFile({
maxSize: logging.maxSize,
maxFiles: logging.maxFiles,
datePattern: logging.datePattern,
zippedArchive: true,
filename: `logs/${logging.level}-%DATE%.log`
})
]
});
}
I think it would be nice to have this option added.
ong-gtp Sounds good. It would be helpful if you send a PR and then we can close the issue.
Resolved by https://github.com/cham11ng/typescript-api-starter/pull/61