From c0e2ab012982e0c6a5239cbc71bbd5a138d92a57 Mon Sep 17 00:00:00 2001 From: Annika Backstrom Date: Tue, 17 Dec 2019 13:39:18 -0500 Subject: [PATCH] Add more logging to sqlite backend --- jukebox/library/sqlite-backend.js | 9 ++++++--- player.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/jukebox/library/sqlite-backend.js b/jukebox/library/sqlite-backend.js index 47bf340..718ff6e 100644 --- a/jukebox/library/sqlite-backend.js +++ b/jukebox/library/sqlite-backend.js @@ -3,24 +3,27 @@ const Track = require('./track'); class SqliteBackend { - constructor(config, db) { + constructor(config, db, logger) { this.config = config; this.db = db; + this.logger = logger; } find(tag, callback) { this.db.run("INSERT INTO tags (tag) VALUES (?)", tag); this.db.get("SELECT uuid, tag, label FROM library WHERE tag = ? ORDER BY RANDOM() LIMIT 1", tag, (err, row) => { if (typeof row === 'undefined') { + this.logger.debug("no matching tag in sqlite backend", { tag: tag }); return callback(); } + this.logger.debug("found a matching tag", { tag: tag }); callback(new Track(row['tag'], row['uuid'], row['label'])); }); } } -module.exports = function(config, db) { - return new SqliteBackend(config, db); +module.exports = function(config, db, logger) { + return new SqliteBackend(config, db, logger); }; // vim:ts=2 sw=2 et: diff --git a/player.js b/player.js index 1d22bda..af4b71d 100644 --- a/player.js +++ b/player.js @@ -45,7 +45,7 @@ const play_log = require('./jukebox/library/play-log'); const sqlite3 = require('sqlite3'); var db = new sqlite3.Database(config.db); -const MediaLibrarySqliteBackend = require('./jukebox/library/sqlite-backend')(config, db); +const MediaLibrarySqliteBackend = require('./jukebox/library/sqlite-backend')(config, db, logger); const MediaLibrary = new library.Library(config, MediaLibrarySqliteBackend); const PlayLog = new play_log.PlayLog();