UNPKG

1.79 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.createLogLevelDiagLogger = void 0;
19const types_1 = require("../types");
20function createLogLevelDiagLogger(maxLevel, logger) {
21 if (maxLevel < types_1.DiagLogLevel.NONE) {
22 maxLevel = types_1.DiagLogLevel.NONE;
23 }
24 else if (maxLevel > types_1.DiagLogLevel.ALL) {
25 maxLevel = types_1.DiagLogLevel.ALL;
26 }
27 // In case the logger is null or undefined
28 logger = logger || {};
29 function _filterFunc(funcName, theLevel) {
30 const theFunc = logger[funcName];
31 if (typeof theFunc === 'function' && maxLevel >= theLevel) {
32 return theFunc.bind(logger);
33 }
34 return function () { };
35 }
36 return {
37 error: _filterFunc('error', types_1.DiagLogLevel.ERROR),
38 warn: _filterFunc('warn', types_1.DiagLogLevel.WARN),
39 info: _filterFunc('info', types_1.DiagLogLevel.INFO),
40 debug: _filterFunc('debug', types_1.DiagLogLevel.DEBUG),
41 verbose: _filterFunc('verbose', types_1.DiagLogLevel.VERBOSE),
42 };
43}
44exports.createLogLevelDiagLogger = createLogLevelDiagLogger;
45//# sourceMappingURL=logLevelLogger.js.map
\No newline at end of file