Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS-3804] Document logging support #312

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading