/**
* ログユーティリティ
*/
const LOG_LEVELS = {
debug: 0,
info: 1,
warn: 2,
error: 3,
};
let currentLogLevel =
LOG_LEVELS[process.env.LOG_LEVEL?.toLowerCase() || "info"] || 1;
/**
* ログ出力
* @param {string} level - ログレベル (debug, info, warn, error)
* @param {string} message - ログメッセージ
* @param {*} data - 追加データ
*/
function log(level, message, data = null) {
const levelValue = LOG_LEVELS[level] || LOG_LEVELS.info;
if (levelValue < currentLogLevel) return;
const timestamp = new Date().toISOString();
const prefix = `[${timestamp}] [${level.toUpperCase()}]`;
if (data) {
console.log(`${prefix} ${message}`, data);
} else {
console.log(`${prefix} ${message}`);
}
}
export const Logger = {
debug: (msg, data) => log("debug", msg, data),
info: (msg, data) => log("info", msg, data),
warn: (msg, data) => log("warn", msg, data),
error: (msg, data) => log("error", msg, data),
};