UNPKG

1.61 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.setLogFunction = exports.logger = void 0;
17const util = require("util");
18/*! The external function used to emit logs. */
19let logFunction = null;
20/**
21 * Log function to use for debug output. By default, we don't perform any
22 * logging.
23 *
24 * @private
25 * @internal
26 */
27// eslint-disable-next-line @typescript-eslint/no-explicit-any
28function logger(source, msg, ...otherArgs) {
29 if (logFunction) {
30 const time = new Date().toISOString();
31 const formattedMsg = util.format(`D ${time} | ${source} | ${msg} |`, ...otherArgs);
32 logFunction(formattedMsg);
33 }
34}
35exports.logger = logger;
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}
45exports.setLogFunction = setLogFunction;
46//# sourceMappingURL=logger.js.map
\No newline at end of file