forked from versatica/mediasoup
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLogger.ts
47 lines (40 loc) · 945 Bytes
/
Logger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import debug from 'debug';
const APP_NAME = 'mediasoup';
export class Logger
{
private readonly _debug: debug.Debugger;
private readonly _warn: debug.Debugger;
private readonly _error: debug.Debugger;
constructor(prefix?: string)
{
if (prefix)
{
this._debug = debug(`${APP_NAME}:${prefix}`);
this._warn = debug(`${APP_NAME}:WARN:${prefix}`);
this._error = debug(`${APP_NAME}:ERROR:${prefix}`);
}
else
{
this._debug = debug(APP_NAME);
this._warn = debug(`${APP_NAME}:WARN`);
this._error = debug(`${APP_NAME}:ERROR`);
}
/* eslint-disable no-console */
this._debug.log = console.info.bind(console);
this._warn.log = console.warn.bind(console);
this._error.log = console.error.bind(console);
/* eslint-enable no-console */
}
get debug(): debug.Debugger
{
return this._debug;
}
get warn(): debug.Debugger
{
return this._warn;
}
get error(): debug.Debugger
{
return this._error;
}
}