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 {
26 // ///////////////////////////////////////////////////////////////////////////////////////////////
29 * No-op call so that we can leave imports in place,
30 * even when there's no debugging.
36 // ///////////////////////////////////////////////////////////////////////////////////////////////
40 * @param level threshold.
42 static setLevel(level) {
43 this.level = Logger.OFF;
44 if (Common.getType(level) === 'Number') {
47 this.level = Logger[level];
51 // ///////////////////////////////////////////////////////////////////////////////////////////////
61 // ///////////////////////////////////////////////////////////////////////////////////////////////
64 * Write DEBUG-level log.
65 * @param msg message or tokens.
67 static debug(...msg) {
68 if (this.level >= Logger.DEBUG) {
69 const out = this.serialize(msg);
70 console.info(`ASDCS [DEBUG] ${out}`);
74 // ///////////////////////////////////////////////////////////////////////////////////////////////
77 * Write INFO-level log.
78 * @param msg message or tokens.
81 if (this.level >= Logger.INFO) {
82 const out = this.serialize(msg);
83 console.info(`ASDCS [INFO] ${out}`);
87 // ///////////////////////////////////////////////////////////////////////////////////////////////
91 * @param msg message or tokens.
94 if (this.level >= Logger.WARN) {
95 const out = this.serialize(msg);
96 console.warn(`ASDCS [WARN] ${out}`);
100 // ///////////////////////////////////////////////////////////////////////////////////////////////
104 * @param msg message or tokens.
106 static error(...msg) {
107 if (this.level >= Logger.ERROR) {
108 const out = this.serialize(msg);
109 console.error(`ASDCS [ERROR] ${out}`);
113 // ///////////////////////////////////////////////////////////////////////////////////////////////
117 * @param msg message or tokens.
120 static serialize(...msg) {
122 msg.forEach(token => {
123 out = `${out}${token}`;
129 // /////////////////////////////////////////////////////////////////////////////////////////////////
136 Logger.level = Logger.OFF;