You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/public/react/src/common/LogUtil.js

62 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import moment from 'moment'
const log = require('loglevel');
log.enableAll();
// 获取后可以改变日志级别
window.getLog = () => {
return log;
}
window._logWithTimeStamp = true;
const timeStamp = () => {
if (window._logWithTimeStamp) {
return `[${moment().format('hh:mm:ss')}] `
}
return ''
}
/*
带trace的、默认折叠起来的控制台输出
第一个参数最好传入string类型的标识接着可以跟任意类型任意个数的参数各个参数都会打印到控制台
*/
export function trace_collapse(content) {
if (console.groupCollapsed) {
console.groupCollapsed(typeof content == 'string' ? content : 'trace_collapse');
log.trace(arguments);
console.groupEnd();
} else {
trace(content)
}
}
export function trace(content) {
log.trace(content);
}
export function debug(content) {
log.debug(content);
}
export function info(content) {
log.info(content);
}
export function warn(content) {
log.warn(content);
}
export function error(content) {
log.error(content);
}
export function trace_c(content) {
log.trace(`${timeStamp()}%c${content}`, 'color:magenta;');
}
export function debug_c(content) {
log.debug(`${timeStamp()}%c${content}`, 'color:cyan;');
}
export function info_c(content) {
log.info(`${timeStamp()}%c${content}`, 'color:blue;');
}
export function warn_c(content) {
log.warn(`${timeStamp()}%c${content}`, 'color:crimson;');
}
export function error_c(content) {
log.error(`${timeStamp()}%c${content}`, 'color:red;');
}