From 36d75f6b75d7ede4656636f1d8bf770eb1cb3a80 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 14 Jan 2020 10:25:49 -0800 Subject: [PATCH] feat: allow logging to be disabled (#880) --- dev/src/logger.ts | 11 +++++++---- types/firestore.d.ts | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dev/src/logger.ts b/dev/src/logger.ts index 28296f3f1..c0b3cb07f 100644 --- a/dev/src/logger.ts +++ b/dev/src/logger.ts @@ -22,7 +22,7 @@ import {validateFunction} from './validate'; let libVersion: string; /*! The external function used to emit logs. */ -let logFunction: ((msg: string) => void) | undefined = undefined; +let logFunction: ((msg: string) => void) | null = null; /** * Log function to use for debug output. By default, we don't perform any @@ -49,15 +49,18 @@ export function logger( } /** - * Sets the log function for all active Firestore instances. + * Sets or disables the log function for all active Firestore instances. + * + * @param logger A log function that takes a message (such as `console.log`) or + * `null` to turn off logging. */ -export function setLogFunction(logger: (msg: string) => void): void { +export function setLogFunction(logger: ((msg: string) => void) | null): void { validateFunction('logger', logger); logFunction = logger; } /** - * Sets the log function for all active Firestore instances. + * Sets the library version to be used in log messages. * * @private */ diff --git a/types/firestore.d.ts b/types/firestore.d.ts index c6f5f1533..038c90018 100644 --- a/types/firestore.d.ts +++ b/types/firestore.d.ts @@ -35,9 +35,12 @@ declare namespace FirebaseFirestore { export type UpdateData = {[fieldPath: string]: any}; /** - * Sets the log function for all active Firestore instances. + * Sets or disables the log function for all active Firestore instances. + * + * @param logger A log function that takes a message (such as `console.log`) or + * `null` to turn off logging. */ - function setLogFunction(logger: (msg:string) => void): void; + function setLogFunction(logger: ((msg:string) => void) | null) : void; /** * Settings used to directly configure a `Firestore` instance.