log-mate
Version:
log-mate makes logging effortless & powerful—log to console, files, databases, or cloud with structured logs, encryption, real-time streaming, and auto-rotation. It’s plug & play, supports multi-transport logging, and boosts performance with async, lazy l
24 lines (18 loc) • 717 B
JavaScript
let format = "text";
function setFormat(type) {
if (["json", "yaml", "text"].includes(type)) {
format = type;
}
}
function formatLog(level, message, ...args) {
const logObject = { level, message, args, timestamp: new Date().toISOString() };
if (format === "json") {
return JSON.stringify(logObject);
} else if (format === "yaml") {
return `level: ${level}\nmessage: ${message}\nargs: ${JSON.stringify(args)}\ntimestamp: ${logObject.timestamp}`;
}
return `[${level}] ${logObject.timestamp} - ${message} ${args.join(" ")}`;
}
// module.exports = setFormat;
// module.exports = formatLog;
module.exports = { setFormat, formatLog };