// SPDX-FileCopyrightText: 2021 Johannes Loher // // SPDX-License-Identifier: MIT const loggingContext = "DS4"; const loggingSeparator = "|"; type LogLevel = "debug" | "info" | "warning" | "error"; type LoggingFunction = (...data: unknown[]) => void; class Logger { readonly debug: LoggingFunction; readonly info: LoggingFunction; readonly warn: LoggingFunction; readonly error: LoggingFunction; constructor() { this.debug = this.getLoggingFunction("debug"); this.info = this.getLoggingFunction("info"); this.warn = this.getLoggingFunction("warning"); this.error = this.getLoggingFunction("error"); } getLoggingFunction(type: LogLevel = "info") { const log = { debug: console.debug, info: console.info, warning: console.warn, error: console.error }[type]; return (...data: unknown[]) => log(loggingContext, loggingSeparator, ...data); } } const logger = new Logger(); export default logger;