{"id":17573,"library":"dexie-logger","title":"Dexie Logger Middleware","description":"Dexie Logger is a middleware for Dexie.js, a wrapper for IndexedDB, designed to provide enhanced debugging capabilities by logging database operations. Currently at version 1.2.6, it offers detailed insights into database interactions such as `mutate`, `get`, `query`, and `openCursor`. While a specific release cadence isn't published, the project includes future development ideas, indicating an active maintenance state. Its key differentiator lies in its deep integration with Dexie, allowing developers to filter logs based on specific tables and operation types using either a whitelist or a blacklist approach. This makes it a valuable tool for isolating and debugging complex data flow issues within Dexie-backed applications, improving development efficiency and understanding of IndexedDB transactions.","status":"active","version":"1.2.6","language":"javascript","source_language":"en","source_url":"https://github.com/10play/dexie-logger","tags":["javascript","Dexie","Logger","Middleware","typescript"],"install":[{"cmd":"npm install dexie-logger","lang":"bash","label":"npm"},{"cmd":"yarn add dexie-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add dexie-logger","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is a middleware for Dexie.js and requires a Dexie instance to operate.","package":"dexie","optional":false}],"imports":[{"note":"The logger function is exported as the default export. Requires ESM or a transpiler for CommonJS environments.","wrong":"const logger = require('dexie-logger');","symbol":"logger","correct":"import logger from 'dexie-logger';"}],"quickstart":{"code":"import Dexie, { Table } from 'dexie';\nimport logger from 'dexie-logger';\n\n// Define your database schema\ninterface Event {\n  id?: number;\n  name: string;\n  timestamp: Date;\n}\n\ninterface User {\n  id?: number;\n  name: string;\n  email: string;\n}\n\nclass MyDatabase extends Dexie {\n  events!: Table<Event>;\n  users!: Table<User>;\n\n  constructor() {\n    super(\"MyDebuggerDatabase\");\n    this.version(1).stores({\n      events: \"++id, name, timestamp\",\n      users: \"++id, name, email\"\n    });\n  }\n}\n\nconst db = new MyDatabase();\n\n// Apply the logger middleware with specific filters\ndb.use(\n  logger({\n    tableWhiteList: [\"events\"], // Only log operations on the 'events' table\n    operationsWhiteList: [\"mutate\", \"get\"], // Only log 'mutate' (add/update/delete) and 'get' operations\n  })\n);\n\nasync function runExample() {\n  try {\n    console.log(\"Applying Dexie Logger middleware...\");\n\n    // Perform some operations to trigger logs\n    await db.events.add({ name: \"App Started\", timestamp: new Date() });\n    await db.events.add({ name: \"User Session Begin\", timestamp: new Date() });\n    await db.users.add({ name: \"John Doe\", email: \"john@example.com\" }); // This operation on 'users' table will NOT be logged due to tableWhiteList\n\n    const firstEvent = await db.events.get(1); // This 'get' operation will be logged\n    console.log(\"Retrieved event:\", firstEvent);\n\n    await db.events.put({ id: firstEvent?.id, name: \"App Updated\", timestamp: new Date() }); // This 'mutate' operation will be logged\n\n    console.log(\"Check your browser's developer console for Dexie Logger output.\");\n\n  } catch (error) {\n    console.error(\"Database operation failed:\", error);\n  }\n}\n\nrunExample();","lang":"typescript","description":"Initializes a Dexie database, applies the logger middleware with specific table and operation filters, and performs database operations to demonstrate logging output in the console."},"warnings":[{"fix":"Choose `tableWhiteList` or `tablesBlackList` (not both), and `operationsWhiteList` or `operationsBlackList` (not both) to define your logging scope.","message":"When configuring the logger, ensure you use either a whitelist OR a blacklist for tables and operations, but not both simultaneously for the same type. For example, using both `tableWhiteList` and `tablesBlackList` can lead to unexpected logging behavior as the options are mutually exclusive.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For production builds or performance-sensitive environments, consider disabling the logger or only enabling it conditionally during development or specific debugging sessions.","message":"Applying the logger middleware can introduce a slight performance overhead, especially in applications with very high-frequency database operations or large data volumes. While generally negligible for typical debugging, be mindful of its impact in performance-critical sections.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure you have correctly initialized your Dexie database, e.g., `const db = new Dexie(\"MyDatabase\");` and that you are calling `db.use()` on this instance.","cause":"The `db` variable or object you are attempting to apply the middleware to is not a valid Dexie instance.","error":"TypeError: db.use is not a function"},{"fix":"Review the logger configuration passed to `db.use(logger({ ... }))`. Temporarily remove all filters or broaden them to confirm the logger is working, then progressively re-apply filters to identify the specific rule preventing logs.","cause":"The logger's `tableWhiteList`, `tablesBlackList`, `operationsWhiteList`, or `operationsBlackList` configuration is too restrictive or incorrectly set, filtering out the operations you expect to see.","error":"Logs not appearing in console (but operations are succeeding)"},{"fix":"Ensure your project supports ES Modules (ESM) or use a transpiler like Babel or TypeScript to convert ESM imports. If strictly in CommonJS and no transpilation, consider if the library offers a CommonJS export (though `dexie-logger` is primarily ESM-first).","cause":"This typically occurs in CommonJS environments (like older Node.js scripts or build setups without proper ESM transpilation) when trying to use `import logger from 'dexie-logger';`.","error":"ReferenceError: logger is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}