UNPKG

@globalworldwide/grpc-resolvers

Version:
42 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeLogger = makeLogger; const grpc_js_1 = require("@grpc/grpc-js"); const constants_js_1 = require("@grpc/grpc-js/build/src/constants.js"); const logging_js_1 = require("@grpc/grpc-js/build/src/logging.js"); class Logger { #tracer; #debugTraceFunction; #infoTraceFunction; #errorTraceFunction; #errorErrorFunction; constructor(tracer) { this.#tracer = tracer; this.#debugTraceFunction = this.#trace?.bind(this, constants_js_1.LogVerbosity.DEBUG); this.#infoTraceFunction = this.#trace?.bind(this, constants_js_1.LogVerbosity.INFO); this.#errorTraceFunction = this.#trace?.bind(this, constants_js_1.LogVerbosity.ERROR); this.#errorErrorFunction = this.#error?.bind(this, constants_js_1.LogVerbosity.ERROR); } get debug() { return (0, logging_js_1.isTracerEnabled)(this.#tracer) ? this.#debugTraceFunction : undefined; } get info() { return (0, logging_js_1.isTracerEnabled)(this.#tracer) ? this.#infoTraceFunction : undefined; } get error() { return (0, logging_js_1.isTracerEnabled)(this.#tracer) ? this.#errorTraceFunction : undefined; } get errorError() { return (0, logging_js_1.isTracerEnabled)(this.#tracer) ? this.#errorErrorFunction : undefined; } #trace(severity, text, md) { return grpc_js_1.experimental.trace(severity, this.#tracer, text + (md ? ` ${JSON.stringify(md)}` : '')); } #error(severity, e, text) { return grpc_js_1.experimental.trace(severity, this.#tracer, text + (e ? ` ${JSON.stringify({ code: e.code, name: e.name, message: e.message })}` : '')); } } function makeLogger(tracer) { return new Logger(tracer); } //# sourceMappingURL=logging.js.map