/* * Copyright (c) 2017-present Paul Borza * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */ import * as bunyan from 'bunyan'; import * as fs from 'fs'; import * as path from 'path'; export class Bunyan { public static getInstance() { const dirname = path.join(__dirname, '../../../logs/'); // Creates the log directory if it doesn't exist. if (!fs.existsSync(dirname)) { fs.mkdirSync(dirname); } if (!Bunyan.instance) { const streams = [{ count: 7, path: path.join(dirname, 'default.log'), period: '1d', type: 'rotating-file', }] as bunyan.Stream[]; // Writes to stdout in development. if (typeof process.env.NODE_ENV === 'undefined' || process.env.NODE_ENV === 'development') { streams.push({ level: 'info', stream: process.stdout, } as bunyan.Stream); } Bunyan.instance = bunyan.createLogger({ name: 'elf', streams, }); } return Bunyan.instance; } private static instance: bunyan; }