UNPKG

europa-build

Version:

Tool for generating and maintaining Europa plugins and presets

73 lines 3.14 kB
"use strict"; /* * Copyright (C) 2022 neocotic * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createLogger = void 0; const winston_1 = require("winston"); /** * Creates a logger using the `options` provided. * * It's only expected that a single logger is created using this function and that any other loggers are created as a * child of that. For example; * * ``` * const rootLogger = createLogger(); * const childLogger = rootLogger.child({ name: 'Child' }); * ``` * * @param [options] - The options to be used. * @return A logger. */ function createLogger(options = {}) { var _a, _b; const transportLevel = (_a = options.level) !== null && _a !== void 0 ? _a : 'info'; const transportStream = (_b = options.outputStream) !== null && _b !== void 0 ? _b : process.stdout; return (0, winston_1.createLogger)({ format: winston_1.format.combine(winston_1.format.errors({ stack: true }), winston_1.format.colorize(), winston_1.format.printf((_a) => { var { level, message, timestamp } = _a, meta = __rest(_a, ["level", "message", "timestamp"]); return `${level} [${meta.name || 'ROOT'}] ${getMessage(message, meta.stack)}`; })), transports: [new winston_1.transports.Stream({ level: transportLevel, stream: transportStream })], }); } exports.createLogger = createLogger; function getMessage(message, stack) { if (!message) { return stack || ''; } if (stack) { return stack; } return message; } //# sourceMappingURL=Logger.js.map