From c767b3e4b2750d4dd094cec2cdd427cdc75050eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 8 Apr 2021 12:09:42 +0200 Subject: [PATCH] Separate debug messages for YouTube --- src/debug.js | 42 ++++++++++++++++++++++++++++++++++++------ src/youtube.js | 2 +- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/debug.js b/src/debug.js index 33489a56..2f7d2e14 100644 --- a/src/debug.js +++ b/src/debug.js @@ -19,9 +19,19 @@ clapperDebugger.enabled = ( || G_DEBUG_ENV != null && G_DEBUG_ENV.includes('Clapper') ); -const clapperDebug = clapperDebugger.debug; -function debug(msg, levelName) +const ytDebugger = new Debug.Debugger('YouTube', { + name_printer: new Ink.Printer({ + font: Ink.Font.BOLD, + color: Ink.Color.RED + }), + time_printer: new Ink.Printer({ + color: Ink.Color.LIGHT_BLUE + }), + high_precision: true, +}); + +function _debug(msg, levelName, debuggerName) { levelName = levelName || 'LEVEL_DEBUG'; @@ -30,12 +40,32 @@ function debug(msg, levelName) msg = msg.message; } - if(levelName !== 'LEVEL_CRITICAL') - return clapperDebug(msg); + if(levelName !== 'LEVEL_CRITICAL') { + switch(debuggerName) { + case 'Clapper': + clapperDebugger.debug(msg); + break; + case 'YouTube': + ytDebugger.debug(msg); + break; + } + + return; + } GLib.log_structured( - 'Clapper', GLib.LogLevelFlags[levelName], { + debuggerName, GLib.LogLevelFlags[levelName], { MESSAGE: msg, - SYSLOG_IDENTIFIER: 'clapper' + SYSLOG_IDENTIFIER: debuggerName.toLowerCase() }); } + +function debug(msg, levelName) +{ + _debug(msg, levelName, 'Clapper'); +} + +function ytDebug(msg, levelName) +{ + _debug(msg, levelName, 'YouTube'); +} diff --git a/src/youtube.js b/src/youtube.js index 25275cec..8cb5650c 100644 --- a/src/youtube.js +++ b/src/youtube.js @@ -4,7 +4,7 @@ const FileOps = imports.src.fileOps; const Misc = imports.src.misc; const YTDL = imports.src.assets['node-ytdl-core']; -const { debug } = Debug; +const debug = Debug.ytDebug; const InitAsyncState = { NONE: 0,