typescript-api-starter icon indicating copy to clipboard operation
typescript-api-starter copied to clipboard

Adapt logging to Heroku's logging technique

Open omept opened this issue 3 years ago • 1 comments

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.

omept avatar Aug 22 '22 12:08 omept

ong-gtp Sounds good. It would be helpful if you send a PR and then we can close the issue.

cham11ng avatar Aug 24 '22 23:08 cham11ng

Resolved by https://github.com/cham11ng/typescript-api-starter/pull/61

cham11ng avatar Sep 08 '22 18:09 cham11ng