UNPKG

1.56 kBJavaScriptView Raw
1"use strict";
2// Copyright 2024 Google LLC
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.
15Object.defineProperty(exports, "__esModule", { value: true });
16exports.logger = logger;
17exports.setLogFunction = setLogFunction;
18const util = require("util");
19/*! The external function used to emit logs. */
20let logFunction = null;
21/**
22 * Log function to use for debug output. By default, we don't perform any
23 * logging.
24 *
25 * @private
26 * @internal
27 */
28// eslint-disable-next-line @typescript-eslint/no-explicit-any
29function logger(source, msg, ...otherArgs) {
30 if (logFunction) {
31 const time = new Date().toISOString();
32 const formattedMsg = util.format(`D ${time} | ${source} | ${msg} |`, ...otherArgs);
33 logFunction(formattedMsg);
34 }
35}
36/**
37 * Sets or disables the log function for all active BigQuery instances.
38 *
39 * @param logger A log function that takes a message (such as `console.log`) or
40 * `null` to turn off logging.
41 */
42function setLogFunction(logger) {
43 logFunction = logger;
44}
45//# sourceMappingURL=logger.js.map
\No newline at end of file