1 | ;
|
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 | */
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.DiagComponentLogger = void 0;
|
19 | const global_utils_1 = require("../internal/global-utils");
|
20 | /**
|
21 | * Component Logger which is meant to be used as part of any component which
|
22 | * will add automatically additional namespace in front of the log message.
|
23 | * It will then forward all message to global diag logger
|
24 | * @example
|
25 | * const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' });
|
26 | * cLogger.debug('test');
|
27 | * // @opentelemetry/instrumentation-http test
|
28 | */
|
29 | class DiagComponentLogger {
|
30 | constructor(props) {
|
31 | this._namespace = props.namespace || 'DiagComponentLogger';
|
32 | }
|
33 | debug(...args) {
|
34 | return logProxy('debug', this._namespace, args);
|
35 | }
|
36 | error(...args) {
|
37 | return logProxy('error', this._namespace, args);
|
38 | }
|
39 | info(...args) {
|
40 | return logProxy('info', this._namespace, args);
|
41 | }
|
42 | warn(...args) {
|
43 | return logProxy('warn', this._namespace, args);
|
44 | }
|
45 | verbose(...args) {
|
46 | return logProxy('verbose', this._namespace, args);
|
47 | }
|
48 | }
|
49 | exports.DiagComponentLogger = DiagComponentLogger;
|
50 | function logProxy(funcName, namespace, args) {
|
51 | const logger = (0, global_utils_1.getGlobal)('diag');
|
52 | // shortcut if logger not set
|
53 | if (!logger) {
|
54 | return;
|
55 | }
|
56 | args.unshift(namespace);
|
57 | return logger[funcName](...args);
|
58 | }
|
59 | //# sourceMappingURL=ComponentLogger.js.map |
\ | No newline at end of file |