UNPKG

@syntest/core

Version:

The common core of the SynTest Framework

118 lines 4.74 kB
"use strict"; /* * Copyright 2020-2021 Delft University of Technology and SynTest contributors * * This file is part of SynTest Framework - SynTest Core. * * Licensed 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.setupLogger = exports.getLogger = void 0; const winston_1 = require("winston"); const Configuration_1 = require("../Configuration"); // define the custom settings for each transport (file, console) function getLoggerSettings(logDirectory) { return { error: { level: "error", filename: `${logDirectory}/error.log`, handleExceptions: true, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.simple()), }, warn: { level: "warn", filename: `${logDirectory}/warn.log`, handleExceptions: true, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.simple()), }, info: { level: "info", filename: `${logDirectory}/info.log`, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.simple()), }, http: { level: "http", filename: `${logDirectory}/http.log`, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.simple()), }, verbose: { level: "verbose", filename: `${logDirectory}/verbose.log`, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.simple()), }, debug: { level: "debug", filename: `${logDirectory}/debug.log`, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.timestamp(), winston_1.format.simple()), }, silly: { level: "silly", filename: `${logDirectory}/silly.log`, json: false, maxsize: 5242880, maxFiles: 1, colorize: false, format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.errors({ stack: true }), winston_1.format.simple(), winston_1.format.timestamp()), }, }; } // eslint-disable-next-line @typescript-eslint/no-explicit-any let logger = null; // instantiate a new Winston Logger with the settings defined above function getLogger() { if (!logger) { throw new Error("You have to call setupLogger before the program can start"); } return logger; } exports.getLogger = getLogger; function setupLogger() { if (logger) { // close existing one before creating a new one. logger.close(); } const settings = getLoggerSettings(Configuration_1.CONFIG.logDirectory); const options = { transports: [ ...Configuration_1.CONFIG.logToFile.map((logLevel) => new winston_1.transports.File(settings[logLevel])), ], exitOnError: false, // do not exit on handled exceptions }; logger = (0, winston_1.createLogger)(options); } exports.setupLogger = setupLogger; //# sourceMappingURL=logger.js.map