2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /* eslint-disable no-console */
19 import Common from './Common';
22 * Logger, to allow calls to console.log during development, but
23 * disable them for production.
25 export default class Logger {
27 // ///////////////////////////////////////////////////////////////////////////////////////////////
30 * No-op call so that we can leave imports in place,
31 * even when there's no debugging.
37 // ///////////////////////////////////////////////////////////////////////////////////////////////
41 * @param level threshold.
43 static setLevel(level) {
44 this.level = Logger.OFF;
45 if (Common.getType(level) === 'Number') {
48 this.level = Logger[level];
52 // ///////////////////////////////////////////////////////////////////////////////////////////////
62 // ///////////////////////////////////////////////////////////////////////////////////////////////
65 * Write DEBUG-level log.
66 * @param msg message or tokens.
68 static debug(...msg) {
69 if (this.level >= Logger.DEBUG) {
70 const out = this.serialize(msg);
71 console.info(`ASDCS [DEBUG] ${out}`);
75 // ///////////////////////////////////////////////////////////////////////////////////////////////
78 * Write INFO-level log.
79 * @param msg message or tokens.
82 if (this.level >= Logger.INFO) {
83 const out = this.serialize(msg);
84 console.info(`ASDCS [INFO] ${out}`);
88 // ///////////////////////////////////////////////////////////////////////////////////////////////
92 * @param msg message or tokens.
95 if (this.level >= Logger.WARN) {
96 const out = this.serialize(msg);
97 console.warn(`ASDCS [WARN] ${out}`);
101 // ///////////////////////////////////////////////////////////////////////////////////////////////
105 * @param msg message or tokens.
107 static error(...msg) {
108 if (this.level >= Logger.ERROR) {
109 const out = this.serialize(msg);
110 console.error(`ASDCS [ERROR] ${out}`);
114 // ///////////////////////////////////////////////////////////////////////////////////////////////
118 * @param msg message or tokens.
121 static serialize(...msg) {
123 msg.forEach((token) => {
124 out = `${out}${token}`;
130 // /////////////////////////////////////////////////////////////////////////////////////////////////
137 Logger.level = Logger.OFF;