Skip to content
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
25 changes: 14 additions & 11 deletions client/packages/admin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
type ReadableStreamCtor,
InstantWritableStream,
InstantReadableStream,
type Logger,
} from '@instantdb/core';

import version from './version.ts';
Expand Down Expand Up @@ -135,6 +136,7 @@ type Config = {
useDateObjects?: boolean;
disableValidation?: boolean;
verbose?: boolean;
logger?: Logger;
};

export type InstantConfig<
Expand All @@ -148,6 +150,7 @@ export type InstantConfig<
useDateObjects: UseDates;
disableValidation?: boolean;
verbose?: boolean;
logger?: Logger;
WritableStream?: WritableStreamCtor;
ReadableStream?: ReadableStreamCtor;
};
Expand Down Expand Up @@ -1101,17 +1104,14 @@ type AdminQueryOpts = {
fetchOpts?: RequestInit;
};

interface Logger {
info: (...args: any[]) => void;
debug: (...args: any[]) => void;
error: (...args: any[]) => void;
}

function createLogger(isEnabled: boolean): Logger {
function createLogger(
isEnabled: boolean,
baseLogger: Logger = console,
): Logger {
return {
info: isEnabled ? (...args: any[]) => console.info(...args) : () => {},
debug: isEnabled ? (...args: any[]) => console.debug(...args) : () => {},
error: isEnabled ? (...args: any[]) => console.error(...args) : () => {},
info: isEnabled ? (...args: any[]) => baseLogger.info(...args) : () => {},
debug: isEnabled ? (...args: any[]) => baseLogger.debug(...args) : () => {},
error: isEnabled ? (...args: any[]) => baseLogger.error(...args) : () => {},
};
}

Expand Down Expand Up @@ -1154,7 +1154,7 @@ class InstantAdminDatabase<
this.streams = new Streams(this.#ensureInstantStream.bind(this));
this.rooms = new Rooms<Schema>(this.config);
this.webhooks = new Webhooks<Schema>(this.config, jsonFetch);
this.#log = createLogger(!!this.config.verbose);
this.#log = createLogger(!!this.config.verbose, this.config.logger);
}

/**
Expand Down Expand Up @@ -1719,4 +1719,7 @@ export {

// error types
type InstantIssue,

// logger
type Logger,
};
1 change: 1 addition & 0 deletions client/packages/core/src/Reactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export default class Reactor {
this._log = createLogger(
config.verbose || flags.devBackend || flags.instantLogs,
() => this._reactorStats(),
config.logger,
);

this.versions = { ...(versions || {}), '@instantdb/core': version };
Expand Down
4 changes: 4 additions & 0 deletions client/packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from './utils/PersistedObject.ts';
import { createInstantRouteHandler } from './createRouteHandler.ts';
import { parseSchemaFromJSON } from './parseSchemaFromJSON.ts';
import type { Logger } from './utils/log.ts';

import type {
PresenceOpts,
Expand Down Expand Up @@ -169,6 +170,7 @@ export type Config = {
apiURI?: string;
devtool?: boolean | DevtoolConfig;
verbose?: boolean;
logger?: Logger;
queryCacheLimit?: number;
useDateObjects: boolean;
disableValidation?: boolean;
Expand All @@ -185,6 +187,7 @@ export type InstantConfig<
apiURI?: string;
devtool?: boolean | DevtoolConfig;
verbose?: boolean;
logger?: Logger;
queryCacheLimit?: number;
useDateObjects: UseDates;
disableValidation?: boolean;
Expand Down Expand Up @@ -1225,6 +1228,7 @@ export {
type StoreInterfaceClass,
type StoreInterfaceStoreName,
createInstantRouteHandler,
type Logger,
};

/** @deprecated Use StoreInterface instead */
Expand Down
7 changes: 4 additions & 3 deletions client/packages/core/src/utils/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ export interface Logger {
export default function createLogger(
isEnabled: boolean,
getStats: () => Record<string, any>,
baseLogger: Logger = console,
): Logger {
return {
info: isEnabled
? (...args: any[]) => console.info(...args, getStats())
? (...args: any[]) => baseLogger.info(...args, getStats())
: () => {},
debug: isEnabled
? (...args: any[]) => console.debug(...args, getStats())
? (...args: any[]) => baseLogger.debug(...args, getStats())
: () => {},
error: isEnabled
? (...args: any[]) => console.error(...args, getStats())
? (...args: any[]) => baseLogger.error(...args, getStats())
: () => {},
};
}
4 changes: 4 additions & 0 deletions client/packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import {
CreateWriteStreamOpts,
InstantWritableStream,
InstantReadableStream,
type Logger,
} from '@instantdb/core';

/**
Expand Down Expand Up @@ -283,4 +284,7 @@ export {
type SyncTableSyncTransaction,
type SyncTableLoadFromStorage,
type SyncTableSetupError,

// logger
type Logger,
};
4 changes: 4 additions & 0 deletions client/packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import {
type StoreInterfaceStoreName,
InstantWritableStream,
InstantReadableStream,
type Logger,
} from '@instantdb/core';

import { InstantReactAbstractDatabase } from '@instantdb/react-common';
Expand Down Expand Up @@ -212,4 +213,7 @@ export {

// Server helper
createInstantRouteHandler,

// logger
type Logger,
};
4 changes: 4 additions & 0 deletions client/packages/solidjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
StoreInterface,
createInstantRouteHandler,
type StoreInterfaceStoreName,
type Logger,
} from '@instantdb/core';

import { InstantSolidDatabase } from './InstantSolidDatabase.js';
Expand Down Expand Up @@ -191,4 +192,7 @@ export {

// Server helper
createInstantRouteHandler,

// logger
type Logger,
};
4 changes: 4 additions & 0 deletions client/packages/svelte/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
StoreInterface,
createInstantRouteHandler,
type StoreInterfaceStoreName,
type Logger,
} from '@instantdb/core';

import { InstantSvelteDatabase } from './InstantSvelteDatabase.svelte.js';
Expand Down Expand Up @@ -197,4 +198,7 @@ export {

// Server helper
createInstantRouteHandler,

// logger
type Logger,
};
2 changes: 1 addition & 1 deletion client/packages/version/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// Update the version here and merge your code to main to
// publish a new version of all of the packages to npm.

const version = 'v1.0.44';
const version = 'v1.0.45';

export { version };
4 changes: 4 additions & 0 deletions client/packages/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
StoreInterface,
createInstantRouteHandler,
type StoreInterfaceStoreName,
type Logger,
} from '@instantdb/core';

import { InstantVueDatabase, init } from './InstantVueDatabase.js';
Expand Down Expand Up @@ -196,4 +197,7 @@ export {

// Server helper
createInstantRouteHandler,

// logger
type Logger,
};
Loading