Files
clapper/src/debug.js
Rafał Dzięgiel 79618edd1e Port to new gtuber lib
Current YouTube code was broken for quite some time. Replace it with
the new Gtuber lib to make this code separate, independent and easier to maintain.
2021-10-18 15:28:34 +02:00

59 lines
1.2 KiB
JavaScript

const { GLib } = imports.gi;
const { Debug } = imports.extras.debug;
const { Ink } = imports.extras.ink;
const G_DEBUG_ENV = GLib.getenv('G_MESSAGES_DEBUG');
const clapperDebugger = new Debug.Debugger('Clapper', {
name_printer: new Ink.Printer({
font: Ink.Font.BOLD,
color: Ink.Color.MAGENTA
}),
time_printer: new Ink.Printer({
color: Ink.Color.ORANGE
}),
high_precision: true,
});
var enabled = (
clapperDebugger.enabled
|| G_DEBUG_ENV != null
&& G_DEBUG_ENV.includes('Clapper')
);
clapperDebugger.enabled = enabled;
function _logStructured(debuggerName, msg, level)
{
GLib.log_structured(
debuggerName, level, {
MESSAGE: msg,
SYSLOG_IDENTIFIER: debuggerName.toLowerCase()
});
}
function _debug(debuggerName, msg)
{
if(msg.message) {
_logStructured(debuggerName, msg.message,
GLib.LogLevelFlags.LEVEL_CRITICAL
);
return;
}
clapperDebugger.debug(msg);
}
function debug(msg)
{
_debug('Clapper', msg);
}
function warn(msg)
{
_logStructured('Clapper', msg, GLib.LogLevelFlags.LEVEL_WARNING);
}
function message(msg)
{
_logStructured('Clapper', msg, GLib.LogLevelFlags.LEVEL_MESSAGE);
}