Re: GJS: Logging for extensions?



On Sun, Jul 3, 2011 at 4:07 AM, Tim Cuthbertson <tim gfxmonk net> wrote:
> On Sun, Jul 3, 2011 at 5:17 PM, Jasper St. Pierre <jstpierre mecheye net> wrote:
>> On Sun, Jul 3, 2011 at 2:25 AM, Tim Cuthbertson <tim gfxmonk net> wrote:
>>> Hi all,
>>>
>>> Since I'm working on a reasonably complex shell extension
>>> (http://gfxmonk.net/shellshape/), I am wondering if there's a decent
>>> logging system for gjs or gnome-shell. Right now I'm using
>>> global.log(), but this is a bit rubbish since it's really verbose, and
>>> I end up leaving my log comments commented out and traipsing round the
>>> codebase enabling them when I'm trying to debug something.
>>>
>>> So, is there anything for this already? Or should I try porting a
>>> browser-based logger to gjs and/or roll my own?
>>
>> What would you like? Something like "console.log", "console.warn" and
>> "console.error"? Where would you like it to go?
>>
>> I've been trying to get it out of the LookingGlass for a bit now, but
>> I don't have any good ideas for replacements besides stderr or a new a
>> panel. What would you like?
>>
>>> Cheers,
>>>  - Tim.
>
> I'm thinking something like log4j, python's logging module, etc.
> Basically, I'd like:
>  - namespaced loggers via getLogger("namespace") with individual log levels
>  - a way to configure log levels per-logger, either programatically or
> with environment variables (or better: both)
>  - logger heirarchicy (e.g logger "shellshape.layout" inherits its log
> level from the "shellshape" logger unless its level is specifically
> changed)

I don't really want to re-invent this. I'd be willing to add better
wrappers for GLib's existing logging support[0].

> That all relates to the programming interface, not where logs go.
> Right now all I need is to log to the console, I just want a better
> way to manage *what* goes to the console.
>
> But it would be good to have gnome-shell / gjs specific appenders. E.g
> the default appender would pump messages out to the console, but you
> could add/configure additional appenders, like:
>  - file output (I'd love to be able to ask my users to send me
> /var/log/shellshape for bug reports)
>  - syslog
>  - an actual notification popup (only for really critical ones, presumably)
>
> These could have different formatters, so that the console is short
> and easily readable but the full information (logger name, timestamp)
> could be written to the log file or syslog.
>
> I've had a look at log4javascript: http://log4javascript.org/
> It looks pretty decent, I think I'll see if I can get it outputting to
> the gjs console. Do you know if/how I could:
>  - get access to system environment variables, and
>  - open / append to a file on disk

GLib.getenv for the first, Gio/GFile.

Look at the lookingGlass before I wrote the new history manager for an
example of writing to files.[1]

> I don't know much about gjs system integration, and docs seem
> exceedingly scarce...
>
> Cheers,
>  - Tim.
>

[0] http://developer.gnome.org/glib/unstable/glib-Message-Logging.html
[1] http://git.gnome.org/browse/gnome-shell/commit/?id=4bedbca66fa485056b7f63e3ce94b326a610805e

-- 
 Jasper


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]