diff --git a/README.md b/README.md index b96f4a4a..97a80f4b 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ See the [Fauna Documentation](https://docs.fauna.com/fauna/current/) for additio - [Iterate on a stream](#iterate-on-a-stream) - [Close a stream](#close-a-stream) - [Stream options](#stream-options) + - [Debug logging](#debug-logging) - [Contributing](#contributing) - [Set up the repo](#set-up-the-repo) - [Run tests](#run-tests) @@ -78,8 +79,7 @@ Stable versions of: ## API reference API reference documentation for the driver is available at -https://fauna.github.io/fauna-js/. The docs are generated using -[TypeDoc](https://typedoc.org/). +https://fauna.github.io/fauna-js/. ## Install @@ -751,6 +751,37 @@ For supported properties, see [StreamClientConfiguration](https://fauna.github.io/fauna-js/latest/types/StreamClientConfiguration.html) in the API reference. +## Debug logging + +To enable or disable debug logging, set the `FAUNA_DEBUG` environment variable +to string-encoded +[`LOG_LEVELS`](https://fauna.github.io/fauna-js/latest/variables/LOG_LEVELS.html) +integer: + +```shell +# Enable logging for warnings (3) and above: +export FAUNA_DEBUG="3" + +# Disable logging: +export FAUNA_DEBUG="6" +``` + +Logs are output to `console` methods. If `FAUNA_DEBUG` is not set or +is invalid, logging is disabled. + +For advanced logging, you can pass a custom log handler using the [client +configuration](#client-configuration)'s `logger` property: + +```js +import { Client, LOG_LEVELS } from "fauna"; +import { CustomLogHandler } from "./your-logging-module"; + +// Create a client with a custom logger. +const client = new Client({ + logger: new CustomLogHandler(LOG_LEVELS.DEBUG), +}); +``` + ## Contributing Any contributions from the community are greatly appreciated! diff --git a/src/index.ts b/src/index.ts index 0d50f17a..b4e8c253 100644 --- a/src/index.ts +++ b/src/index.ts @@ -111,5 +111,6 @@ export { LogLevel, LOG_LEVELS, ConsoleLogHandler, + LogHandler, parseDebugLevel, } from "./util/logging"; diff --git a/src/util/logging.ts b/src/util/logging.ts index d74341be..40c936b8 100644 --- a/src/util/logging.ts +++ b/src/util/logging.ts @@ -14,7 +14,7 @@ export type LogLevel = (typeof LOG_LEVELS)[keyof typeof LOG_LEVELS]; * The intended use is to set FAUNA_DEBUG=0|1|2|3|4. * * This function will convert null, undefined, empty, or or any non matching - * string to a LogLevel of ERROR. + * string to a LogLevel of OFF. * * @param debug_level - The String value of FAUNA_DEBUG. */