appy-one / acebase

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
MIT License
491 stars 27 forks source link

Adding logging when using sqlite as storage backend? #87

Closed Darkle closed 2 years ago

Darkle commented 2 years ago

Hi, when in development there are often times when I would like to log all db queries to the console. This is of course doable with the native acebase storage using the log option, but that feature isnt available when using sqlite as a storage backend.

I was wondering if it would be possible to add logging when using sqlite as a storage backend with acebase. It seems that the sqlite3 library that acebase is using supports logging the db queries via the Database#on('trace', [callback]) api mentioned here: https://github.com/mapbox/node-sqlite3/wiki/Debugging#databaseontrace-callback

I also found this thread for mysql, perhaps a logging option could be enabled for both?

Cheers.

appy-one commented 2 years ago

I think it would be a nice feature to implement, but there currently is no query logging implemented. The logLevel setting works for all storage engines, but that's for console logging of internal operations. The sqlite storage engine will log other messages than default storage because it operates differently. If you are referring to transaction logging, which is only available for binary storage: that's something else. Transaction logging writes all data mutations to a separate log file to provide enhanced data synchronization and recovery options.

Long story short: there is no query logging.

What you can do though, is manually logging query stats and hints by adding a .on('stats', stats => console.log(stats)) and .on('hints', hints => console.log(hints)) to your queries.