UNPKG

2.82 kBJavaScriptView Raw
1/*
2 * Copyright The OpenTelemetry Authors
3 *
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
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { getGlobal } from '../internal/global-utils';
17/**
18 * Component Logger which is meant to be used as part of any component which
19 * will add automatically additional namespace in front of the log message.
20 * It will then forward all message to global diag logger
21 * @example
22 * const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' });
23 * cLogger.debug('test');
24 * // @opentelemetry/instrumentation-http test
25 */
26var DiagComponentLogger = /** @class */ (function () {
27 function DiagComponentLogger(props) {
28 this._namespace = props.namespace || 'DiagComponentLogger';
29 }
30 DiagComponentLogger.prototype.debug = function () {
31 var args = [];
32 for (var _i = 0; _i < arguments.length; _i++) {
33 args[_i] = arguments[_i];
34 }
35 return logProxy('debug', this._namespace, args);
36 };
37 DiagComponentLogger.prototype.error = function () {
38 var args = [];
39 for (var _i = 0; _i < arguments.length; _i++) {
40 args[_i] = arguments[_i];
41 }
42 return logProxy('error', this._namespace, args);
43 };
44 DiagComponentLogger.prototype.info = function () {
45 var args = [];
46 for (var _i = 0; _i < arguments.length; _i++) {
47 args[_i] = arguments[_i];
48 }
49 return logProxy('info', this._namespace, args);
50 };
51 DiagComponentLogger.prototype.warn = function () {
52 var args = [];
53 for (var _i = 0; _i < arguments.length; _i++) {
54 args[_i] = arguments[_i];
55 }
56 return logProxy('warn', this._namespace, args);
57 };
58 DiagComponentLogger.prototype.verbose = function () {
59 var args = [];
60 for (var _i = 0; _i < arguments.length; _i++) {
61 args[_i] = arguments[_i];
62 }
63 return logProxy('verbose', this._namespace, args);
64 };
65 return DiagComponentLogger;
66}());
67export { DiagComponentLogger };
68function logProxy(funcName, namespace, args) {
69 var logger = getGlobal('diag');
70 // shortcut if logger not set
71 if (!logger) {
72 return;
73 }
74 args.unshift(namespace);
75 return logger[funcName].apply(logger, args);
76}
77//# sourceMappingURL=ComponentLogger.js.map
\No newline at end of file