Skip to content

Commit

Permalink
Update logging options
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Nov 13, 2024
1 parent 509c793 commit 2b8923e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions sdks/node-sdk/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import {
generateInboxId,
getInboxIdForAddress,
GroupMessageKind,
Level,
type Consent,
type ConsentEntityType,
type LogOptions,
type Message,
type Client as NodeClient,
type SignatureRequestType,
Expand Down Expand Up @@ -69,9 +71,13 @@ export type OtherOptions = {
*/
requestHistorySync?: string;
/**
* Optionally set the logging level (default: 'off')
* Enable structured JSON logging
*/
logging?: "debug" | "info" | "warn" | "error" | "off";
structuredLogging?: boolean;
/**
* Logging level
*/
loggingLevel?: Level;
};

export type ClientOptions = NetworkOptions &
Expand Down Expand Up @@ -106,6 +112,11 @@ export class Client {
(await getInboxIdForAddress(host, isSecure, accountAddress)) ||
generateInboxId(accountAddress);

const logOptions: LogOptions = {
structured: options?.structuredLogging ?? false,
level: options?.loggingLevel ?? Level.off,
};

return new Client(
await createClient(
host,
Expand All @@ -115,7 +126,7 @@ export class Client {
accountAddress,
encryptionKey,
options?.requestHistorySync,
options?.logging ?? "off",
logOptions,
),
[new GroupUpdatedCodec(), new TextCodec(), ...(options?.codecs ?? [])],
);
Expand Down
2 changes: 2 additions & 0 deletions sdks/node-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type {
Installation,
ListConversationsOptions,
ListMessagesOptions,
LogOptions,
Message,
PermissionPolicySet,
} from "@xmtp/node-bindings";
Expand All @@ -33,6 +34,7 @@ export {
GroupMetadata,
GroupPermissions,
GroupPermissionsOptions,
Level,
PermissionLevel,
PermissionPolicy,
PermissionUpdateType,
Expand Down

0 comments on commit 2b8923e

Please sign in to comment.