'use strict';

var _config = require('./../../config.json');

var _config2 = _interopRequireDefault(_config);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var winston = require('winston'); /*
                                   * *******************************************************************************
                                   *  * Copyright (c) 2018 Edgeworx, Inc.
                                   *  *
                                   *  * This program and the accompanying materials are made available under the
                                   *  * terms of the Eclipse Public License v. 2.0 which is available at
                                   *  * http://www.eclipse.org/legal/epl-2.0
                                   *  *
                                   *  * SPDX-License-Identifier: EPL-2.0
                                   *  *******************************************************************************
                                   *
                                   */

var path = require('path');
require('winston-daily-rotate-file');
var fs = require('fs');
var logDir = path.join(__dirname, '../../../../') + '/ioauthoring-logs';

var tsFormat = function tsFormat() {
  return new Date().toLocaleTimeString();
};
winston.emitErrs = true;

if (!fs.existsSync(logDir)) {
  fs.mkdirSync(logDir);
}

var logger = new winston.Logger({
  transports: [new winston.transports.DailyRotateFile({
    name: 'info-file',
    filename: logDir + '/ioauthoring.log',
    level: _config2.default.loggingLevel,
    json: false,
    //maxsize: 20971520, //20 MB
    maxFiles: 90,
    datePattern: 'yyyy-MM-dd_',
    timestamp: tsFormat,
    localTime: true,
    prepend: true
  })],
  exitOnError: false
});

module.exports = logger;