@yuxilabs/gptp-core
Version:
Core validation, formatting and execution logic for the GPTP file format.
32 lines (31 loc) • 983 B
JavaScript
function isDebugEnabled() {
return process.env.GPTP_DEBUG === "1" || process.env.GPTP_DEBUG === "true";
}
function log(level, tag, ...messages) {
const timestamp = new Date().toISOString();
const prefix = `[GPTP][${level.toUpperCase()}][${tag}]`;
if (level === "debug" && !isDebugEnabled())
return;
const output = `${timestamp} ${prefix}`;
const args = [output, ...messages];
switch (level) {
case "info":
console.log(...args);
break;
case "warn":
console.warn(...args);
break;
case "error":
console.error(...args);
break;
case "debug":
console.debug(...args);
break;
}
}
export const logger = {
info: (tag, ...msg) => log("info", tag, ...msg),
warn: (tag, ...msg) => log("warn", tag, ...msg),
error: (tag, ...msg) => log("error", tag, ...msg),
debug: (tag, ...msg) => log("debug", tag, ...msg),
};