Logger for D (was: Using glog's design for Phobos?)

so so at so.do
Fri Aug 27 18:54:40 PDT 2010


On Sat, 28 Aug 2010 04:18:52 +0300, sybrandy <sybrandy at gmail.com> wrote:

> Here's my current version of the logger.  All of the documentation
> should be in the logger.d file.  I also provided a sample config file
> (logger.conf) and a sample test file that I was using for benchmarking
> (main.d).  Let me know if you have any questions.  Feedback on improving
> this is also welcome.
>
> The one thing I forgot to note in here is that the function that writes
> to the log is passed into the second version of the constructor, which
> needs to be used only once in the code.  A simple log writer is included
> at the bottom of logger.d that does work.  The reason I did this was
> when I initially asked for feedback, I got several ideas on how the
> logger can be improved.  Also, I discussed this with a friend of mine
> who stated that people may want to log to something other than a file,
> such as syslog.  So, instead of trying to make the one "end all be all"
> logger, I felt that by allowing it to accept a function as a parameter
> to the constructor, the person can write to any type of log file,
> database, whatever they want and the logger interface works the same no
> matter what.
>
> There currently is a bug somewhere that I don't understand.  Even though
> I have "OwnerTerminated" as part of my receive statement, I still see
> exceptions when the program closes.  However, it doesn't seem to affect
> the execution of the logger.
>
> Enjoy.
>
> Casey

Hello?
Couldn't it be just like this?

enum log_level {
   note, // or info whatever
   warning,
   error,
   fatal,
}

string log_direct(string filename); // returns last log file directed.
void log(A...)(A a)
{
   if(typof(a[0]) == log_level)
     do_level_thingy();

   ... // rest.
}

version(debug)  void debug_log(A...)(A a) { log(a); }
else            void debug_log(A...)(A a) {}

void main()
{
   std::string old_file = log_direct(new_file); // if you like to change it  
that is
   log("log me pretty", arg1, ....);
   log(error, "log me pretty error", arg1, ...);
   log(warning, "log me pretty warning", arg1, ...);
}

Isn't that good/beautiful/flexible enough?
Please don't start with instantiated loggers, they are ugly so ugly and  
unnecessary!

Thanks.

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list