1 |
|
2 | function Logger(options) {
|
3 |
|
4 | this.level = options.level||Logger.LOG_OFF;
|
5 | this.appendix = options.appendix||"Lighting";
|
6 | }
|
7 |
|
8 | Logger.LEVEL_DEBUG=1;
|
9 | Logger.LEVEL_INFO=2;
|
10 | Logger.LEVEL_WARN=3;
|
11 | Logger.LEVEL_ERROR=4;
|
12 | Logger.LOG_OFF=5;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Logger.prototype.error = function (msg) {
|
19 | if(this.level<=Logger.LEVEL_ERROR){
|
20 | console.error("["+this.appendix+"]"+msg);
|
21 | if(Logger.websocket) Logger.websocket.send(JSON.stringify({
|
22 | type:"log",
|
23 | level:"error",
|
24 | message:msg,
|
25 | userAgent:navigator.userAgent
|
26 | }));
|
27 | }
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | Logger.prototype.warn = function (msg) {
|
35 | if(this.level<=Logger.LEVEL_WARN){
|
36 | console.warn("["+this.appendix+"]"+msg);
|
37 | if(Logger.websocket) Logger.websocket.send(JSON.stringify({
|
38 | type:"log",
|
39 | level:"warn",
|
40 | message:msg,
|
41 | userAgent:navigator.userAgent
|
42 | }));
|
43 | }
|
44 | };
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | Logger.prototype.info = function (msg) {
|
51 | if(this.level<=Logger.LEVEL_INFO){
|
52 | console.info("["+this.appendix+"]"+msg);
|
53 | if(Logger.websocket) Logger.websocket.send(JSON.stringify({
|
54 | type:"log",
|
55 | level:"info",
|
56 | message:msg,
|
57 | userAgent:navigator.userAgent
|
58 | }));
|
59 | }
|
60 | };
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | Logger.prototype.debug = function (msg) {
|
67 | if(this.level<=Logger.LEVEL_DEBUG){
|
68 | console.log("["+this.appendix+"]"+msg);
|
69 | if(Logger.websocket) Logger.websocket.send(JSON.stringify({
|
70 | type:"log",
|
71 | level:"debug",
|
72 | message:msg,
|
73 | userAgent:navigator.userAgent
|
74 | }));
|
75 | }
|
76 | };
|
77 |
|
78 | export default Logger |
\ | No newline at end of file |