1
- const LEVEL = {
2
- ASSERT : 1 ,
3
- ERROR : 2 ,
4
- WARN : 3 ,
5
- INFO : 4 ,
6
- DEBUG : 5 ,
7
- TRACE : 6
8
- } as const ;
9
-
10
1
export class Log {
11
- static readonly ASSERT = LEVEL . ASSERT ;
12
- static readonly ERROR = LEVEL . ERROR ;
13
- static readonly WARN = LEVEL . WARN ;
14
- static readonly INFO = LEVEL . INFO ;
15
- static readonly DEBUG = LEVEL . DEBUG ;
16
- static readonly TRACE = LEVEL . TRACE ;
2
+ static readonly ASSERT = 1 ;
3
+ static readonly ERROR = 2 ;
4
+ static readonly WARN = 3 ;
5
+ static readonly INFO = 4 ;
6
+ static readonly DEBUG = 5 ;
7
+ static readonly TRACE = 6 ;
17
8
18
9
assert = console . assert . bind ( console ) ;
19
10
error = console . error . bind ( console ) ;
@@ -22,7 +13,7 @@ export class Log {
22
13
debug = console . debug . bind ( console ) ;
23
14
trace = console . log . bind ( console ) ;
24
15
25
- level : number = Log . INFO ;
16
+ level = Log . INFO ;
26
17
27
18
constructor ( level ?: number ) {
28
19
if ( level !== undefined ) {
@@ -32,22 +23,18 @@ export class Log {
32
23
}
33
24
34
25
setLevel ( level : number ) {
35
- console . log ( 'Current log level:' , this . level ) ;
36
- console . log ( 'New log level:' , level ) ;
37
- console . log ( 'Log.INFO:' , Log . INFO ) ;
38
- console . log ( 'Log.DEBUG:' , Log . DEBUG ) ;
39
26
this . level = level ;
40
27
if ( level >= Log . ASSERT ) this . assert = console . assert . bind ( console ) ;
41
- else this . assert = ( ) => { } ;
28
+ else this . assert = function ( ) { } ;
42
29
if ( level >= Log . ERROR ) this . error = console . error . bind ( console ) ;
43
- else this . error = ( ) => { } ;
30
+ else this . error = function ( ) { } ;
44
31
if ( level >= Log . WARN ) this . warn = console . warn . bind ( console ) ;
45
- else this . warn = ( ) => { } ;
32
+ else this . warn = function ( ) { } ;
46
33
if ( level >= Log . INFO ) this . info = console . info . bind ( console ) ;
47
- else this . info = ( ) => { } ;
34
+ else this . info = function ( ) { } ;
48
35
if ( level >= Log . DEBUG ) this . debug = console . debug . bind ( console ) ;
49
- else this . debug = ( ) => { } ;
36
+ else this . debug = function ( ) { } ;
50
37
if ( level >= Log . TRACE ) this . trace = console . log . bind ( console ) ;
51
- else this . trace = ( ) => { } ;
38
+ else this . trace = function ( ) { } ;
52
39
}
53
40
}
0 commit comments