{"size": 2206, "ext": "js", "max_stars_repo_path": "provider/Logger.js", "max_stars_repo_name": "nbaudis/trigger-cloudant", "max_stars_repo_stars_event_min_datetime": "2019-05-17T02:09:55.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-17T02:09:55.000Z", "max_issues_repo_path": "provider/Logger.js", "max_issues_repo_name": "nbaudis/trigger-cloudant", "max_issues_repo_issues_event_min_datetime": "2019-10-28T23:42:16.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-05T10:10:32.000Z", "max_forks_repo_path": "provider/Logger.js", "max_forks_repo_name": "nbaudis/trigger-cloudant", "max_forks_repo_forks_event_min_datetime": "2018-09-13T17:58:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-05-03T09:45:16.000Z"}
{"max_stars_count": 1, "max_issues_count": 4, "max_forks_count": 5, "avg_line_length": 35.0158730159, "max_line_length": 135, "alphanum_fraction": 0.6210335449}
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var _ = require('lodash');
var moment = require('moment');
var winston = require('winston');
var safeStringify = require('json-stringify-safe');

var logger = new winston.Logger({
    transports: [
        new winston.transports.Console({
            timestamp: function () {
                return moment.utc().format("YYYY-MM-DDTHH:mm:ss.SSS") + 'Z';
            },
            formatter: function (options) {
                // Return string will be passed to logger.
                return '[' + options.timestamp() + '] [' + options.level.toUpperCase() + '] [??] [cloudantTrigger] ' + options.message;
            }
        })
    ]
});

function getMessage(argsObject) {
    var args = Array.prototype.slice.call(argsObject);
    args.shift();
    args.forEach(function (arg, i) {
        if (_.isObject(args[i])) {
            args[i] = safeStringify(args[i]);
        }
    });
    return args.join(' ');
}

// FORMAT: s"[$time] [$category] [$id] [$componentName] [$name] $message"
module.exports = {
    info: function (name) {
        logger.info('[' + name + ']', getMessage(arguments));
    },
    warn: function (name) {
        logger.warn('[' + name + ']', getMessage(arguments));
    },
    error: function (name) {
        logger.error('[' + name + ']', getMessage(arguments));
    },
    debug: function (name) {
        logger.debug('[' + name + ']', getMessage(arguments));
    }
};
