Skip to content

Commit

Permalink
[DOCS-3804] Document logging support (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodewig authored Dec 18, 2024
1 parent fad66a4 commit fa94793
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -751,6 +751,34 @@ For supported properties, see
[StreamClientConfiguration](https://fauna.github.io/fauna-js/latest/types/StreamClientConfiguration.html)
in the API reference.

## Debug logging

To enable debug logging, set the `FAUNA_DEBUG` environment variable to a
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"
```

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!
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ export {
LogLevel,
LOG_LEVELS,
ConsoleLogHandler,
LogHandler,
parseDebugLevel,
} from "./util/logging";
2 changes: 1 addition & 1 deletion src/util/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit fa94793

Please sign in to comment.