const bunyan = require('bunyan');

module.exports = function (options) {
    options.level = options.level || 'info';
    options.name = options.name || options.level;
    options.enableConsoleLogging = options.enableConsoleLogging || true;

    const logStreams = [
        {
            level: options.level,
            path: options.name + '.log',
            type: 'rotating-file',
            period: '1d',
            count: 14
        },
        {
            level: 'error',
            path: options.name + '.errors.log'
        }
    ];

    if (options.enableConsoleLogging) {
        // noinspection JSCheckFunctionSignatures
        logStreams.push({
            level: options.level,
            stream: process.stdout
        });
    }

    return bunyan.createLogger({
        name: options.name,
        serializers: bunyan.stdSerializers,
        streams: logStreams
    });
};
