mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-15 00:44:22 +09:00
[WIP] Add debug logging, fixes #103
To enable more debug logging without custom builds while still maintaining a minimal syslog impact by default - Add a settings variable 'debug', hidden from the user - Use dconf to write/read it (suggest adding to the README and/or wiki). Only for debugging purposes really - When 'debug' is set it will enable the possibility of extra logging - The new 'debug' function also adds in some meta data such as unique syslog id instead of gnome-shell, file/func/line id to easier locate in code - Changed the Render all MenuItems and a couple of outcommented updated logs to use the new debug function instead Todo's before no longer WIP: - Place it somewhere else than in this, cause I presume it wont be reachable everywhere then - Consider replacing regular log with something like this as well (to gain the neat meta data (extension prefix, file, func, line)) - Think some more on the usage of log domains and if possible to turn of more logging that way instead of dconf variable
This commit is contained in:
@@ -7,6 +7,7 @@ const Util = imports.misc.util;
|
||||
const Mainloop = imports.mainloop;
|
||||
const Clutter = imports.gi.Clutter;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
|
||||
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
||||
const Convenience = Me.imports.convenience;
|
||||
@@ -21,6 +22,30 @@ const FreonItem = Me.imports.freonItem;
|
||||
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
|
||||
const _ = Gettext.gettext;
|
||||
|
||||
function _makeLogFunction(prefix) {
|
||||
return msg => {
|
||||
// Grab the second line of a stack trace, i.e. caller of debug()
|
||||
let regex = /(?:(?:[^<.]+<\.)?([^@]+))?@(.+):(\d+):\d+/g;
|
||||
let trace = ((msg.stack) ? msg : new Error()).stack.split('\n')[1];
|
||||
let [m, func, file, line] = regex.exec(trace);
|
||||
file = GLib.path_get_basename(file);
|
||||
|
||||
let hdr = [file, func, line].filter(k => (k)).join(':');
|
||||
|
||||
GLib.log_structured(
|
||||
'freon',
|
||||
GLib.LogLevelFlags.LEVEL_MESSAGE,
|
||||
{
|
||||
MESSAGE: `[${prefix}] [${hdr}]: ${msg}`,
|
||||
SYSLOG_IDENTIFIER: 'org.gnome.shell.extensions.freon',
|
||||
CODE_FILE: file,
|
||||
CODE_FUNC: `${func}`,
|
||||
CODE_LINE: `${line}`
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var FreonMenuButton = new Lang.Class({
|
||||
Name: 'FreonMenuButton',
|
||||
Extends: PanelMenu.Button,
|
||||
@@ -30,6 +55,13 @@ var FreonMenuButton = new Lang.Class({
|
||||
|
||||
this._settings = Convenience.getSettings();
|
||||
|
||||
var _debugFunc = _makeLogFunction('DEBUG');
|
||||
this.debug = this._settings.get_boolean('debug') ? _debugFunc : () => {};
|
||||
|
||||
this._settings.connect('changed::debug', () => {
|
||||
this.debug = this._settings.get_boolean('debug') ? _debugFunc : () => {};
|
||||
});
|
||||
|
||||
this._sensorMenuItems = {};
|
||||
|
||||
this._utils = {
|
||||
@@ -244,14 +276,14 @@ var FreonMenuButton = new Lang.Class({
|
||||
let needUpdate = false;
|
||||
for (let sensor of Object.values(this._utils)) {
|
||||
if (sensor.available && sensor.updated) {
|
||||
// global.log(sensor + ' updated');
|
||||
this.debug(sensor + ' updated');
|
||||
sensor.updated = false;
|
||||
needUpdate = true;
|
||||
}
|
||||
}
|
||||
if(needUpdate) {
|
||||
this._updateDisplay(); // #74
|
||||
// global.log('update display');
|
||||
this.debug('update display');
|
||||
}
|
||||
},
|
||||
|
||||
@@ -410,7 +442,7 @@ var FreonMenuButton = new Lang.Class({
|
||||
|
||||
if(this._needRerender){
|
||||
this._needRerender = false;
|
||||
global.log('[FREON] Render all MenuItems');
|
||||
this.debug('Render all MenuItems');
|
||||
this.menu.removeAll();
|
||||
this._appendMenuItems(sensors);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -75,5 +75,11 @@
|
||||
<description>Group more than three voltage menu items</description>
|
||||
</key>
|
||||
|
||||
<key type="b" name="debug">
|
||||
<default>false</default>
|
||||
<summary>Enable debug logging</summary>
|
||||
<description>Enable debug logging from the extension</description>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
</schemalist>
|
||||
|
||||
Reference in New Issue
Block a user