UNPKG

@villedemontreal/logger

Version:
167 lines 4.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggerConfigs = void 0; const general_utils_1 = require("@villedemontreal/general-utils"); const logger_1 = require("../logger"); /** * Logger Config */ class LoggerConfigs { /** * The Correlation Id provider is required. */ constructor(correlationIdProvider) { /** * The correlation id provider. * To set this is required. */ this.correlationIdProvider = null; /** * Enable logging to a file. * Default to false. */ this.logToFile = false; /** * The directory where the potential * log file will be written. * Default to "./log". */ this.logDir = './log'; /** * Log rotation file nb */ this.logRotateFilesNbr = 30; /** * Log rotation threshhold in MB */ this.logRotateThresholdMB = 100; /** * Log maximum total size in MB */ this.logRotateMaxTotalSizeMB = 1000; /** * Logging level (info, debug, warning, error) * * Default value : DEBUG in DEV or WARNING otherwise. */ this.logLevel = process.env.NODE_ENV === general_utils_1.globalConstants.Environments.DEV ? logger_1.LogLevel.DEBUG : logger_1.LogLevel.WARNING; /** * Log in human readable form in the console. */ this.logHumanReadableinConsole = false; /** * Add the stack trace to the error log in development */ this.addStackTraceToErrorMessagesInDev = process.env.NODE_ENV === general_utils_1.globalConstants.Environments.DEV ? true : false; /** * Log the source of the error in the log message */ this.logSource = true; if (!correlationIdProvider) { throw new Error(`The Correlation Id provider is required.`); } this.correlationIdProvider = correlationIdProvider; } /** * The current Correlation Id. */ get correlationId() { return this.correlationIdProvider(); } /** * Logging to a file? */ isLogToFile() { return this.logToFile; } /** * Get the directory where the log files should be written */ getLogDirectory() { return this.logDir; } /** * Get the current logging level */ getLogLevel() { return this.logLevel; } isLogHumanReadableinConsole() { return this.logHumanReadableinConsole; } isAddStackTraceToErrorMessagesInDev() { return this.addStackTraceToErrorMessagesInDev; } isLogSource() { return this.logSource; } getLogRotateFilesNbr() { return this.logRotateFilesNbr; } getLogRotateThresholdMB() { return this.logRotateThresholdMB; } getLogRotateMaxTotalSizeMB() { return this.logRotateMaxTotalSizeMB; } /** * Enable logging to a file in addition to * logging to the standard output. * This should probably be let to FALSE in our * current network where Graylog is used : no * log files are indeed required! */ setSlowerLogToFileToo(logToFile) { this.logToFile = logToFile; } /** * Set the directory where the log files should be written */ setLogDirectory(logDir) { this.logDir = logDir; } /** * Set the logging level */ setLogLevel(loglevel) { this.logLevel = loglevel; } /** * Set the logs in the console to be human readable */ setLogHumanReadableinConsole(logHumanReadableinConsole) { this.logHumanReadableinConsole = logHumanReadableinConsole; } /** * Set the stack trace to be logged in development environment */ setAddStackTraceToErrorMessagesInDev(addStackTraceToErrorMessagesInDev) { this.addStackTraceToErrorMessagesInDev = addStackTraceToErrorMessagesInDev; } /** * Set if the source of the error should be logged */ setLogSource(logSource) { this.logSource = logSource; } /** * Set the number of log files to rotate */ setLogRotateFilesNbr(logRotateFilesNb) { this.logRotateFilesNbr = logRotateFilesNb; } /** * Set the log rotation threshhold. */ setLogRotateThresholdMB(logRotateThresholdMB) { this.logRotateThresholdMB = logRotateThresholdMB; } /** * Set the maximum total size of the logfile */ setLogRotateMaxTotalSizeMB(logRotateMaxTotalSizeMB) { this.logRotateMaxTotalSizeMB = logRotateMaxTotalSizeMB; } } exports.LoggerConfigs = LoggerConfigs; //# sourceMappingURL=configs.js.map