On Sat, 28 Aug 2010 05:29:53 +0300, Denis Koroskin <2kor...@gmail.com>
wrote:
On Sat, 28 Aug 2010 05:54:40 +0400, so <s...@so.do> wrote:
On Sat, 28 Aug 2010 04:18:52 +0300, sybrandy <sybra...@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.
Why wouldn't you just keep using writefln for your logging?
I'm afraid you misunderstand why people use logging libraries. I'll try
to explain: once your project grows big, the amount of log it starts to
generate may grow *HUGE*. Once there, you understand the importance of
configuring every bit of the logger. Some logs needs to be disabled,
some logs need to go to console, some logs need to file A, some to file
B etc.
That's why it is a standard practice to have *independent* loggers for
most of your classes. I refuse to use anything that dumps all the logs
into the same bin - it's a joke and not a logging framework.
There is not a thing in my example that says. "you should dump all the
logs into the same bin".
If you have a closer look at it, and try to be objective and don't take
this serious but i can't find a better phrase for it... Stop being OOP
centric.
If you want me to write this retard extra line every time i want to log,
just because in some company a guy needed this, i am not using your so
clever/complex/... library, that is it.
Logger log(new_file, log_level, ....); // wth?
log(....);
....
What is the big deal here? i just want to write a log to somewhere with
the given level.
99% of the time you won't redirect it anyways. Am i wrong?
log("this : ", that);
log(warning, "this : ", that);
Oh you want to redirect it?
string old = log_direct(new, error);
log(error,
log(error,
...
log_direct(old); // or just make a scoped object there and hide this as
well...
Is these so simple for your needs? Roll/write/buy your own, this is not a
standard library issue.
Thanks!
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/