mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 16:02:00 +02:00
Use custom scripts for logging debug messages
Default "GLib.log_structured" method is painfully slow and time provided by it is not very accurate. It also slows down program execution even when G_MESSAGES_DEBUG env is not set. Use custom debug scripts for faster and more accurate messages logging instead.
This commit is contained in:
@@ -1,4 +1,25 @@
|
||||
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,
|
||||
});
|
||||
clapperDebugger.enabled = (
|
||||
clapperDebugger.enabled
|
||||
|| G_DEBUG_ENV != null
|
||||
&& G_DEBUG_ENV.includes('Clapper')
|
||||
);
|
||||
const clapperDebug = clapperDebugger.debug;
|
||||
|
||||
function debug(msg, levelName)
|
||||
{
|
||||
@@ -8,6 +29,10 @@ function debug(msg, levelName)
|
||||
levelName = 'LEVEL_CRITICAL';
|
||||
msg = msg.message;
|
||||
}
|
||||
|
||||
if(levelName !== 'LEVEL_CRITICAL')
|
||||
return clapperDebug(msg);
|
||||
|
||||
GLib.log_structured(
|
||||
'Clapper', GLib.LogLevelFlags[levelName], {
|
||||
MESSAGE: msg,
|
||||
|
Reference in New Issue
Block a user