DWT2 Phobos-compatible logging suggestion

Jacob Carlborg doob at me.com
Wed Jul 14 03:03:05 PDT 2010


On 2010-07-13 23.46, Jeremy Powers wrote:
> Looks reasonable to me.  Some comments:
>
> I see a danger w/ having the whole class version()'ed around - the
> methods are defined twice, and need to be kept in sync.  Would it be
> better to just do the version around the implementations?  I.E.
> something like:
>
>    class DWTLogger {
>      version(Tango) {
>        tango.util.log.Log.Logger logger;
>      }
>      ...
>      void info(T...)(String file, ulong line, String fmt, T args){
>        version(Tango) {
>          ...
>        } else {
>          ...
>        }
>      }

I agree, if the method signatures are the same on both phobos and tango 
then the version condition should be located inside the method.

> Also, should the tags for the different levels match log4j style?
> That is, use 'INFO', 'DEBUG', etc....
>
> Aside:  I was hoping there would be a D-standard logging solution
> similar to log4j, but haven't found one outside of Tango yet - not
> sure how important logging is to DWT itself, but this is definitely
> something needed for many projects.  If such a thing did exist, we
> could just delegate to it (or use directly).
>
> One more:
>
>> 4) ExceptionPrintStackTrace has become less flexible, but this shouldn't
>> matter and can easily be fixed if needed.
>
> I've been mucking around with the way exceptions are defined, to allow
> Java-translated code to work with less changes, so assuming I actually
> get that done and it works the ExceptionPrintStackTrace method should
> be unneeded - in favor of just doing e.printStackTrace().  Anyway,
> when I get that part finished I'll send something to the list.
>
>
> I'm actually a big fan of code reviews as a form of collaboration - do
> you want to use the list as a place for this kind of thing, or does it
> make sense to do something more formal w/ issue tracking etc?

Hm, I think using the issue tracking system might be better, it easier 
to keep track of and it doesn't get lost so easy. We can use the issue 
tracking system for the DWT project, the DWT2 project doesn't have a 
trac environment.

> Jeremy
>
> On Tue, Jul 13, 2010 at 2:00 PM, torhu<no at spam.invalid>  wrote:
>> Ok, this is sort my way to get some cooperation going on the DWT project.
>>   Check it out and make suggestions for improvements, or just say "ok" if you
>> approve :)
>>
>> I've been trying for a couple of hours to find a way to do logging that's
>> compatible with both Phobos and Tango.
>>
>> Here's what I came up with, this is tested and working:
>> http://pastebin.ca/1900029
>>
>> This is what I had to take into consideration:
>>
>> 1) Phobos formatting uses functions like format(...), while tango uses
>> format(char[] fmt, ...).  Using the signature func(T...)(String fmt, T args)
>> was the simplest way I found to be able to just forward arguments to both
>> kinds of formatters.
>>
>> 2) Format specifiers are different.  I just did fmt = replace(fmt, "{}",
>> "%s") in the Phobos version, which takes care of most cases.  We can revisit
>> this later if there's an actual need for more flexible formatting.
>>
>> 3) The IDwtLogger interface had to go, as template member functions cannot
>> be virtual. Cfr. item 1.  The interface was not put to use anywhere, so this
>> should be of no concern.
>>
>> 4) ExceptionPrintStackTrace has become less flexible, but this shouldn't
>> matter and can easily be fixed if needed.
>>


-- 
Jacob Carlborg


More information about the Digitalmars-d-dwt mailing list