darkness-dependent-vision/src/module/logger.js
2021-06-29 05:40:25 +02:00

36 lines
871 B
JavaScript

// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
'use strict';
const loggingContext = 'DDV';
const loggingSeparator = '|';
/**
* @typedef {'debug' | 'info' | 'warning' | 'error'} LogLevel
*/
/**
* @typedef {(...args: unknown[]) => void} LoggingFunction
*/
/**
* @param {LogLevel} [type = 'info'] - The log level of the requested logger
* @returns {LoggingFunction}
*/
function getLoggingFunction(type = 'info') {
const log = { debug: console.debug, info: console.info, warning: console.warn, error: console.error }[type];
return (...data) => log(loggingContext, loggingSeparator, ...data);
}
const logger = Object.freeze({
debug: getLoggingFunction('debug'),
info: getLoggingFunction('info'),
warn: getLoggingFunction('warn'),
error: getLoggingFunction('error'),
getLoggingFunction,
});
export default logger;