UNPKG

2.22 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright The OpenTelemetry Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.DiagConsoleLogger = void 0;
19const consoleMap = [
20 { n: 'error', c: 'error' },
21 { n: 'warn', c: 'warn' },
22 { n: 'info', c: 'info' },
23 { n: 'debug', c: 'debug' },
24 { n: 'verbose', c: 'trace' },
25];
26/**
27 * A simple Immutable Console based diagnostic logger which will output any messages to the Console.
28 * If you want to limit the amount of logging to a specific level or lower use the
29 * {@link createLogLevelDiagLogger}
30 */
31class DiagConsoleLogger {
32 constructor() {
33 function _consoleFunc(funcName) {
34 return function (...args) {
35 if (console) {
36 // Some environments only expose the console when the F12 developer console is open
37 // eslint-disable-next-line no-console
38 let theFunc = console[funcName];
39 if (typeof theFunc !== 'function') {
40 // Not all environments support all functions
41 // eslint-disable-next-line no-console
42 theFunc = console.log;
43 }
44 // One last final check
45 if (typeof theFunc === 'function') {
46 return theFunc.apply(console, args);
47 }
48 }
49 };
50 }
51 for (let i = 0; i < consoleMap.length; i++) {
52 this[consoleMap[i].n] = _consoleFunc(consoleMap[i].c);
53 }
54 }
55}
56exports.DiagConsoleLogger = DiagConsoleLogger;
57//# sourceMappingURL=consoleLogger.js.map
\No newline at end of file