Using glog's design for Phobos?

Tomek Sowiński just at ask.me
Thu Aug 26 15:19:24 PDT 2010


Dnia 26-08-2010 o 05:59:19 Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> napisał(a):

> At my workplace we're using Google's logging library glog  
> (http://google-glog.googlecode.com/svn/trunk/doc/glog.html), and the  
> more I use it, the more I like it. It's simple, to the point, and  
> effective.
>
> I was thinking it would be great to adapt a similar design into Phobos.  
> There will be differences such as use of regular argument lists instead  
> of << etc., but the spirit will be similar. What do you think?

Hm.. why not. Some quick thoughts:

* Only a subset of features needs to be ported, e.g.
DLOG(...) == version(debug) LOG(...)
CHECK == enforce()
Also, I don't get the superlativeness of LOG_IF(INFO, pred) << ...   
versus  if (pred) LOG(INFO) << ...

* Instead of LOG(INFO, msg), please go for Log.info(msg).

* LOG_EVERY_N, LOG_FIRST_N, ... generalizes to Log.info!n_pred, where  
n_pred is a function taking an int.
I'm curious about the D implementation, though - how to pull off a  
separate counter for every calling site? I can think only of mixins, I  
mean the ugly ones.

* Consider Log.errorf(msg, args, to, fill, in, holes, in, msg) - I know  
there's Log.error(msg, format(args...)), but formatted logging happens  
often enough to justify *f variants. Besides, it rhymes nicely with  
std.stdio.write(f).

* VLOG seems unnecessary. From my experience it's hard enough to keep the  
meaning of ordinary *named* levels consistent in an application dev'd by >  
1 programmers. Custom levels whose name is a nothing-saying integer?  
Forget it, every one will log under his own lucky number. I'd say adding  
simply a VERBOSE level at the end of the scale would suffice.

* Allow per-module fine grained level settings for ordinary levels  
(info/warn/...)

* Implement logging function body like this:
void info(lazy string msg) { version(no_logs) else {
     ...
}}
So that flagging compilation with -version=no_logs -inline would make the  
logging vanish from binaries. For hardcore people.


Tomek


More information about the Digitalmars-d mailing list