UNPKG

2.7 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2019 gRPC 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 * http://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 */
18var _a, _b, _c, _d;
19Object.defineProperty(exports, "__esModule", { value: true });
20exports.trace = exports.log = exports.setLoggerVerbosity = exports.setLogger = exports.getLogger = void 0;
21const constants_1 = require("./constants");
22let _logger = console;
23let _logVerbosity = constants_1.LogVerbosity.ERROR;
24const verbosityString = (_b = (_a = process.env.GRPC_NODE_VERBOSITY) !== null && _a !== void 0 ? _a : process.env.GRPC_VERBOSITY) !== null && _b !== void 0 ? _b : '';
25switch (verbosityString.toUpperCase()) {
26 case 'DEBUG':
27 _logVerbosity = constants_1.LogVerbosity.DEBUG;
28 break;
29 case 'INFO':
30 _logVerbosity = constants_1.LogVerbosity.INFO;
31 break;
32 case 'ERROR':
33 _logVerbosity = constants_1.LogVerbosity.ERROR;
34 break;
35 case 'NONE':
36 _logVerbosity = constants_1.LogVerbosity.NONE;
37 break;
38 default:
39 // Ignore any other values
40}
41exports.getLogger = () => {
42 return _logger;
43};
44exports.setLogger = (logger) => {
45 _logger = logger;
46};
47exports.setLoggerVerbosity = (verbosity) => {
48 _logVerbosity = verbosity;
49};
50// eslint-disable-next-line @typescript-eslint/no-explicit-any
51exports.log = (severity, ...args) => {
52 if (severity >= _logVerbosity && typeof _logger.error === 'function') {
53 _logger.error(...args);
54 }
55};
56const tracersString = (_d = (_c = process.env.GRPC_NODE_TRACE) !== null && _c !== void 0 ? _c : process.env.GRPC_TRACE) !== null && _d !== void 0 ? _d : '';
57const enabledTracers = new Set();
58const disabledTracers = new Set();
59for (const tracerName of tracersString.split(',')) {
60 if (tracerName.startsWith('-')) {
61 disabledTracers.add(tracerName.substring(1));
62 }
63 else {
64 enabledTracers.add(tracerName);
65 }
66}
67const allEnabled = enabledTracers.has('all');
68function trace(severity, tracer, text) {
69 if (!disabledTracers.has(tracer) && (allEnabled || enabledTracers.has(tracer))) {
70 exports.log(severity, new Date().toISOString() + ' | ' + tracer + ' | ' + text);
71 }
72}
73exports.trace = trace;
74//# sourceMappingURL=logging.js.map
\No newline at end of file