// SPDX-FileCopyrightText: 2021 Johannes Loher // // SPDX-License-Identifier: MIT 'use strict'; const loggingContext = 'DDV'; const loggingSeparator = '|'; /** * Get a logging function for the requested log level. * @typedef {'debug' | 'info' | 'warn' | '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 = console[type]; return (...data) => log(loggingContext, loggingSeparator, ...data); } /** * A singleton logger object. */ const logger = Object.freeze({ debug: getLoggingFunction('debug'), info: getLoggingFunction('info'), warn: getLoggingFunction('warn'), error: getLoggingFunction('error'), getLoggingFunction, }); export default logger;