std.log version 2
Jose Armando Garcia
jsancio at gmail.com
Sat Jun 4 10:04:01 PDT 2011
Hi everyone,
I went back and incorporated a lot of the community requested changes.
The module has changed quite a bit. Some notable changes are:
* Got rid of all the *Config struct. You can now configure some parts
of std.log even after logging as started. See Configuration
* Got rid of the initLogging methods/templates they are not need
anymore. The module should work without initialization.
* Added the log severity critical which throws when logged.
* Gave in and made LogFilter a final class
* Fixed compile time disabling by using a template to get the
LogFilter. The new syntax is log!info.
* Added rich boolean support! More on that below.
code: https://github.com/jsancio/phobos/blob/master/std/log.d
doc: http://jsancio.github.com/phobos/phobos/std_log.html
Note: I had to make changes to std.datetime (was getting a segfault;
changes are in my repo) and druntime (patch attached).
Now on to rich boolean. I wanted to be able to print in the log
message why the when() expression is true. To achieve this I added a
struct Rich(Type)
which encapsulate the value and the reason for that value. Right now
the implementation is not every smart and just stores the reason as a
string.
For example if you write:
log!info.format("You passed %s argument(s)", args.length - 1);
log!info.when(richGreater(args.length, 1))("Arguments: ", args[1 .. $]);
log!info.when(richOr(richIsNull(obj), richEqual(10, 20)))("Something strange");
you get the following log lines:
20110604T152711.0138317Z:93d780 src/justo/main.d:11 INFO You passed 4
argument(s)
20110604T152711.0142393Z:93d780 src/justo/main.d:12 INFO when(true =
(a > b) <a = '5', b = '1'>) Arguments: [--minloglevel=info,
--logtostderr, --stderrThreshold=info, --v=0]
20110604T152711.0150535Z:93d780 src/justo/main.d:14 INFO when(true =
(a || b) <a = 'true = (a is null) <a = 'null'>', b = 'false = (a == b)
<a = '10', b = '20'>'>) Something strange!
I am interested to hear people's option of this. How can it be improved?
Many thanks,
-Jose
-------------- next part --------------
A non-text attachment was scrubbed...
Name: druntime.patch
Type: application/octet-stream
Size: 871 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110604/cdea53ba/attachment.obj>
More information about the Digitalmars-d
mailing list