Adding Prettier and fixing up eslint version
[sdc.git] / dox-sequence-diagram-ui / src / main / webapp / lib / ecomp / asdc / sequencer / common / Logger.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16
17 /* eslint-disable no-console */
18
19 import Common from './Common';
20
21 /**
22  * Logger, to allow calls to console.log during development, but
23  * disable them for production.
24  */
25 export default class Logger {
26     // ///////////////////////////////////////////////////////////////////////////////////////////////
27
28     /**
29      * No-op call so that we can leave imports in place,
30      * even when there's no debugging.
31      */
32     static noop() {
33         // Nothing.
34     }
35
36     // ///////////////////////////////////////////////////////////////////////////////////////////////
37
38     /**
39      * Set debug level.
40      * @param level threshold.
41      */
42     static setLevel(level) {
43         this.level = Logger.OFF;
44         if (Common.getType(level) === 'Number') {
45             this.level = level;
46         } else {
47             this.level = Logger[level];
48         }
49     }
50
51     // ///////////////////////////////////////////////////////////////////////////////////////////////
52
53     /**
54      * Get debug level.
55      * @returns {number|*}
56      */
57     static getLevel() {
58         return this.level;
59     }
60
61     // ///////////////////////////////////////////////////////////////////////////////////////////////
62
63     /**
64      * Write DEBUG-level log.
65      * @param msg message or tokens.
66      */
67     static debug(...msg) {
68         if (this.level >= Logger.DEBUG) {
69             const out = this.serialize(msg);
70             console.info(`ASDCS [DEBUG] ${out}`);
71         }
72     }
73
74     // ///////////////////////////////////////////////////////////////////////////////////////////////
75
76     /**
77      * Write INFO-level log.
78      * @param msg message or tokens.
79      */
80     static info(...msg) {
81         if (this.level >= Logger.INFO) {
82             const out = this.serialize(msg);
83             console.info(`ASDCS [INFO] ${out}`);
84         }
85     }
86
87     // ///////////////////////////////////////////////////////////////////////////////////////////////
88
89     /**
90      * Write debug.
91      * @param msg message or tokens.
92      */
93     static warn(msg) {
94         if (this.level >= Logger.WARN) {
95             const out = this.serialize(msg);
96             console.warn(`ASDCS [WARN] ${out}`);
97         }
98     }
99
100     // ///////////////////////////////////////////////////////////////////////////////////////////////
101
102     /**
103      * Write error.
104      * @param msg message or tokens.
105      */
106     static error(...msg) {
107         if (this.level >= Logger.ERROR) {
108             const out = this.serialize(msg);
109             console.error(`ASDCS [ERROR] ${out}`);
110         }
111     }
112
113     // ///////////////////////////////////////////////////////////////////////////////////////////////
114
115     /**
116      * Serialize msg.
117      * @param msg message or tokens.
118      * @returns {string}
119      */
120     static serialize(...msg) {
121         let out = '';
122         msg.forEach(token => {
123             out = `${out}${token}`;
124         });
125         return out;
126     }
127 }
128
129 // /////////////////////////////////////////////////////////////////////////////////////////////////
130
131 Logger.OFF = 0;
132 Logger.ERROR = 1;
133 Logger.WARN = 2;
134 Logger.INFO = 3;
135 Logger.DEBUG = 4;
136 Logger.level = Logger.OFF;