printf-style logging API

5 views
Skip to first unread message

oystein.rg

unread,
Jul 13, 2009, 6:27:28 AM7/13/09
to firephp-dev
Hi list!

Currently, the FirePHP API is slightly different than Firebug's own
console.log API [1]:

FirePHP:
FirePHP::send($object, $label, $log_level);

console
console.log(format, arg1, ..., argN);

The `format` argument is expanded printf-style, and the `%o` format
conversion specifier results in an inline link to the object in
Firebug's DOM inspector. I personally like flexibility of this API,
and sometimes the ($object, $label) signature can be a bit awkward
when logging more than one variable or when I want the variables to be
included in-line with the label.

I'm not too familiar with the internals the code, but would it be
feasible to add a similar API to FirePHP? I'm thinking:

FirePHP::logf($format, $arg1, ..., $argN), FirePHP::warnf($format,
$arg1, ..., $argN) etc.

The `%d`, `%f` and `%s` specifiers could be expanded server-side, and `
%o` would render the usual FirePHP object inspector in Firebug's
console. Thoughts?

[1] http://getfirebug.com/console.html

(Thanks for creating this tool, by the way -- it has greatly
simplified my web developer life :)

Regards,
--
Øystein Riiser Gundersen
upstruct berlin oslo
http://www.upstruct.com

Christoph Dorn

unread,
Jul 14, 2009, 2:56:38 PM7/14/09
to firep...@googlegroups.com

> I'm not too familiar with the internals the code, but would it be
> feasible to add a similar API to FirePHP? I'm thinking:
>
> FirePHP::logf($format, $arg1, ..., $argN), FirePHP::warnf($format,
> $arg1, ..., $argN) etc.
>
> The `%d`, `%f` and `%s` specifiers could be expanded server-side, and `
> %o` would render the usual FirePHP object inspector in Firebug's
> console. Thoughts?
>
It should not be too difficult to implement. Feel free to create a
ticket for it in the issue tracker [1].

Would you be interested in implementing this feature given some guidance?

Christoph

[1] - http://code.google.com/p/firephp/issues/list

oystein.rg

unread,
Jul 16, 2009, 5:22:34 AM7/16/09
to firephp-dev
On Jul 14, 8:56 pm, Christoph Dorn <christoph...@christophdorn.com>
wrote:
> > FirePHP::logf($format, $arg1, ..., $argN), FirePHP::warnf($format,
> > $arg1, ..., $argN)  etc.
>
> > The `%d`, `%f` and `%s` specifiers could be expanded server-side, and `
> > %o` would render the usual FirePHP object inspector in Firebug's
> > console. Thoughts?
>
> It should not be too difficult to implement. Feel free to create a
> ticket for it in the issue tracker [1].

Done: <http://code.google.com/p/firephp/issues/detail?id=120>

> Would you be interested in implementing this feature given some guidance?

Sure, I could take a stab at it :)

Like I said, I'm not too familiar with the codebase: I can make sense
of the PHP code, but the Firefox extension stuff is a bit harder for
me to follow. Any starting points/tips as to how to go about
implementing this? (From a cursory glance, I think I make out where
the magic happens but it is not immediately clear to me if I need to
make client-side changes at all or if a change to the HTTP header
protocol is needed, etc.)

I'll read up on it and get back to you!

Christoph Dorn

unread,
Jul 16, 2009, 1:11:04 PM7/16/09
to firep...@googlegroups.com

> Like I said, I'm not too familiar with the codebase: I can make sense
> of the PHP code, but the Firefox extension stuff is a bit harder for
> me to follow. Any starting points/tips as to how to go about
> implementing this? (From a cursory glance, I think I make out where
> the magic happens but it is not immediately clear to me if I need to
> make client-side changes at all or if a change to the HTTP header
> protocol is needed, etc.)
>
This is what I propose:

FirePHPCore:

- Add the *f() methods

Protocol:

- Review: http://www.firephp.org/Wiki/Reference/Protocol
- Expansion should happen on client
- Log variables to be substituted into <meta> section of message as:
"PrintFParameters": [ "param value 1", ...]
- Log formatting string into <body> section as usual

Extension:

- Review: http://www.firephp.org/Wiki/Reference/CustomizeDisplay
- Modify request processor to look for "PrintFParameters" in meta and
substitute varibales
- Log resulting message as array ( [ ... , ... , ... , ... ] ) so
firebug will substitute the variables for now
- Add support for this.logfToFirebug(mode, data, false, meta) so
substitution will be done inline without having to re-format into array

The PHP and protocol work should be pretty straight forward. The
extension work will be a bit harder especially because it is difficult
to debug. I can do the extension work pretty quick once you get the PHP
part working if you like.

Thanks for taking the initiative to add support for this!

Christoph


Reply all
Reply to author
Forward
0 new messages