Skip to content

Remove js-logger dependency#966

Draft
simolus3 wants to merge 15 commits into
v2from
remove-js-logger
Draft

Remove js-logger dependency#966
simolus3 wants to merge 15 commits into
v2from
remove-js-logger

Conversation

@simolus3
Copy link
Copy Markdown
Contributor

As proposed in #948, this removes the js-logger dependency in favor of a custom logging interface. The idea is that:

  1. The interface should be as simple as possible, and be easy to implement for users with custom logging needs.
  2. This is only used for logs from the SDK, not a general-purpose logging library. We can afford making logging inside the SDK a bit less ergonomic (passing level as a named parameter instead of one method per level) to keep the interface smaller.
  3. Outside of the message, which is always a string, we have additional fields which are well-typed and named (credits to Luc for the idea).
  4. There is no global hierarchy of loggers, and no global createBaseLogger. If you want a PowerSync database to log, you pass a logger in. By default, we use an implementation forwarding logs to console.log.

For the most part, users can keep using the default option and continue to get a default out-of-the-box experience where messages with level info and higher are logged to the console with a [PowerSync] prefix. To customize this:

  1. Implement the PowerSyncLogger interface, and pass an instance of that to PowerSyncDatabase. Or, if you want the default logger but with another minimum severity, use createPowerSyncLogger.
  2. When instantiating a WASQLiteOpenFactory directly, one also needs to pass a logger. The web SDK would forward the one from the database by default.
  3. For log messages forwarded from workers, the way to configure the minimum severity has changed. Before, we'd use the log level of the database logger. Because the logger interface is essentially a sink now and doesn't expose that, we can't do that anymore. Instead,
    • For database workers, a logLevel can be passed to WASQLiteOpenFactory, and messages with that level or higher are forwarded to the main tab.
    • For sync workers, the minimum log level can be configured as an option when constructing the database.

This is a breaking change, which is why this PR has the v2 branch as a target. The idea is to bundle up changes which we can then release at once.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 15, 2026

🦋 Changeset detected

Latest commit: 2b898c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@powersync/common Major
@powersync/adapter-sql-js Patch
@powersync/attachments-storage-react-native Major
@powersync/attachments Major
@powersync/drizzle-driver Major
@powersync/kysely-driver Major
@powersync/node Major
@powersync/nuxt Major
@powersync/op-sqlite Major
@powersync/react-native Major
@powersync/react Major
@powersync/tanstack-react-query Major
@powersync/vue Major
@powersync/web Major
@powersync/diagnostics-app Patch
@powersync/capacitor Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

if (options.logLevel) {
logger.setLevel(options.logLevel);
}
export function createPowerSyncLogger(options?: Partial<CreateLoggerOptions>): PowerSyncLogger & CreateLoggerOptions {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would createConsoleLogger perhaps be a better description here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants