update
This commit is contained in:
@@ -9,130 +9,78 @@ class LOG_LEVEL_TYPES {
|
||||
const Log_Level_Names: Array<string> = ['debug', 'log', 'info', 'warn', 'error']
|
||||
|
||||
export class Logger {
|
||||
public static tag: string = '[HaoJslog]' //可以设置当前游戏的前缀
|
||||
public static LEVEL: number = LOG_LEVEL_TYPES.WARN //当前Logger等级
|
||||
public static tag: string = '[HaoJslog]' // 可以设置当前游戏的前缀
|
||||
public static LEVEL: number = LOG_LEVEL_TYPES.WARN // 当前Logger等级
|
||||
public static Log_Color_Config: Array<string> = [
|
||||
'color:#890;font-size:10px;',
|
||||
'color:#000;font-size:11px;',
|
||||
'color:#09f;font-size:12px;',
|
||||
'color:#f90;font-size:13px;',
|
||||
'color:#f00;font-size:15px;'
|
||||
'color:#f00;font-size:15px;',
|
||||
]
|
||||
|
||||
private static Terminal_Log: boolean = false
|
||||
|
||||
public static formatNow() {
|
||||
let date: Date = new Date() //后端返回的时间戳是秒
|
||||
return (
|
||||
date.getFullYear() +
|
||||
'-' +
|
||||
(date.getMonth() + 1) +
|
||||
'-' +
|
||||
date.getDate() +
|
||||
' ' +
|
||||
date.getHours() +
|
||||
':' +
|
||||
date.getMinutes() +
|
||||
':' +
|
||||
date.getSeconds() +
|
||||
':' +
|
||||
date.getMilliseconds()
|
||||
)
|
||||
const date: Date = new Date() // 后端返回的时间戳是秒
|
||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}:${date.getMilliseconds()}`
|
||||
}
|
||||
|
||||
private static getLogPreKey(nowLevel: number): string {
|
||||
return '[' +
|
||||
Logger.formatNow() +
|
||||
'] ' +
|
||||
Logger.tag +
|
||||
' [' +
|
||||
Log_Level_Names[nowLevel] +
|
||||
'] '
|
||||
return `[${Logger.formatNow()}] ${Logger.tag} [${Log_Level_Names[nowLevel]}] `
|
||||
}
|
||||
|
||||
public static debug(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.DEBUG) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.DEBUG)
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.DEBUG)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.DEBUG)
|
||||
const fileStr: string = str + params.join(' ')
|
||||
// LogErrorFileUtil.debug(fileStr);
|
||||
if (this.Terminal_Log) {
|
||||
console.log(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr)
|
||||
}
|
||||
if (this.Terminal_Log)
|
||||
console.log(`%c${str}`, this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG], ...params)
|
||||
else console.info(fileStr)
|
||||
}
|
||||
|
||||
public static log(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.LOG) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.LOG)
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.LOG)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.LOG)
|
||||
const fileStr: string = str + params.join(' ')
|
||||
// LogErrorFileUtil.log(fileStr);
|
||||
if (this.Terminal_Log) {
|
||||
console.log(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr) //console.log(str, ...params)
|
||||
}
|
||||
if (this.Terminal_Log)
|
||||
console.log(`%c${str}`, this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG], ...params)
|
||||
else console.info(fileStr) // console.log(str, ...params)
|
||||
}
|
||||
|
||||
public static info(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.INFO) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.INFO)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.info(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.info(fileStr)
|
||||
}
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.INFO) return
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.INFO)
|
||||
const fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log)
|
||||
console.info(`%c${str}`, this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG], ...params)
|
||||
else console.info(fileStr)
|
||||
}
|
||||
|
||||
public static warn(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.WARN) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.WARN)
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.WARN)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.warn(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.warn(fileStr)
|
||||
}
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.WARN)
|
||||
const fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log)
|
||||
console.warn(`%c${str}`, this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG], ...params)
|
||||
else console.warn(fileStr)
|
||||
}
|
||||
|
||||
public static error(...params: any) {
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.ERROR) {
|
||||
return
|
||||
}
|
||||
let str: string = this.getLogPreKey(LOG_LEVEL_TYPES.ERROR)
|
||||
let fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log) {
|
||||
console.error(
|
||||
'%c' + str,
|
||||
this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG],
|
||||
...params
|
||||
)
|
||||
} else {
|
||||
console.error(fileStr)
|
||||
}
|
||||
if (Logger.LEVEL > LOG_LEVEL_TYPES.ERROR) return
|
||||
|
||||
const str: string = this.getLogPreKey(LOG_LEVEL_TYPES.ERROR)
|
||||
const fileStr: string = str + params.join(' ')
|
||||
if (this.Terminal_Log)
|
||||
console.error(`%c${str}`, this.Log_Color_Config[LOG_LEVEL_TYPES.DEBUG], ...params)
|
||||
else console.error(fileStr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user