feat:提交
This commit is contained in:
33
tests/dev1/dataHandle/common/log.ts
Normal file
33
tests/dev1/dataHandle/common/log.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
export class Logger
|
||||
{
|
||||
name: string
|
||||
static interceptors: LogInterceptor[] = []
|
||||
constructor(name: string)
|
||||
{
|
||||
this.name = name
|
||||
}
|
||||
|
||||
static AddInterceptor(interceptor: LogInterceptor)
|
||||
{
|
||||
Logger.interceptors.push(interceptor)
|
||||
}
|
||||
|
||||
error(error: Error, payload: any = null)
|
||||
{
|
||||
console.error(error, payload)
|
||||
Logger.interceptors.forEach((i) =>
|
||||
{
|
||||
i.call(this, error, payload)
|
||||
})
|
||||
}
|
||||
|
||||
info(message: string, payload: any = null)
|
||||
{
|
||||
console.info(message, payload)
|
||||
Logger.interceptors.forEach((i) =>
|
||||
{
|
||||
i.call(this, message, payload)
|
||||
})
|
||||
}
|
||||
}
|
||||
export type LogInterceptor = (this: Logger, info: string | Error, payload: any) => void
|
Reference in New Issue
Block a user