UNPKG

2.44 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;
19var 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 */
31var DiagConsoleLogger = /** @class */ (function () {
32 function DiagConsoleLogger() {
33 function _consoleFunc(funcName) {
34 return function () {
35 var args = [];
36 for (var _i = 0; _i < arguments.length; _i++) {
37 args[_i] = arguments[_i];
38 }
39 if (console) {
40 // Some environments only expose the console when the F12 developer console is open
41 // eslint-disable-next-line no-console
42 var theFunc = console[funcName];
43 if (typeof theFunc !== 'function') {
44 // Not all environments support all functions
45 // eslint-disable-next-line no-console
46 theFunc = console.log;
47 }
48 // One last final check
49 if (typeof theFunc === 'function') {
50 return theFunc.apply(console, args);
51 }
52 }
53 };
54 }
55 for (var i = 0; i < consoleMap.length; i++) {
56 this[consoleMap[i].n] = _consoleFunc(consoleMap[i].c);
57 }
58 }
59 return DiagConsoleLogger;
60}());
61exports.DiagConsoleLogger = DiagConsoleLogger;
62//# sourceMappingURL=consoleLogger.js.map
\No newline at end of file