2021-06-26 22:02:00 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-06-26 14:32:40 +02:00
|
|
|
const loggingContext = "DS4";
|
|
|
|
const loggingSeparator = "|";
|
|
|
|
|
|
|
|
type LogLevel = "debug" | "info" | "warning" | "error";
|
|
|
|
type LoggingFunction = (...data: unknown[]) => void;
|
|
|
|
|
2021-07-01 02:56:09 +02:00
|
|
|
const getLoggingFunction = (type: LogLevel = "info"): LoggingFunction => {
|
|
|
|
const log = { debug: console.debug, info: console.info, warning: console.warn, error: console.error }[type];
|
|
|
|
return (...data: unknown[]) => log(loggingContext, loggingSeparator, ...data);
|
|
|
|
};
|
2021-06-26 14:32:40 +02:00
|
|
|
|
2021-07-01 02:56:09 +02:00
|
|
|
const logger = Object.freeze({
|
|
|
|
debug: getLoggingFunction("debug"),
|
|
|
|
info: getLoggingFunction("info"),
|
|
|
|
warn: getLoggingFunction("warning"),
|
|
|
|
error: getLoggingFunction("error"),
|
|
|
|
getLoggingFunction,
|
|
|
|
});
|
2021-06-26 14:32:40 +02:00
|
|
|
|
|
|
|
export default logger;
|