为Vue.js添加友好日志

const isDebugEnabled = process.env.NODE_ENV !== "production";
const isInfoEnabled = true;
const isErrorEnabled = true; let loggerName = "default"; console.log(
"isDebugEnabled,isInfoEnabled,isErrorEnabled=>",
`${isDebugEnabled},${isInfoEnabled},${isErrorEnabled}`
); const debug = log => {
if (isDebugEnabled) {
console.warn("[", loggerName, "]", log);
}
}; const info = log => {
if (isInfoEnabled) {
console.log("[", loggerName, "]", log);
}
}; const error = log => {
if (isErrorEnabled) {
console.error("[", loggerName, "]", log);
}
}; const logger = {
debug,
info,
error
}; export const getLogger = name => {
if (name) {
loggerName = name;
}
return logger;
};

使用

import { getLogger } from "../util/logger";
const logger = getLogger("pages/index"); logger.info("fetch siteConfig and postList finish");
上一篇:android107 指针入门


下一篇:SSDB主从复制