Philippe Sigaud wrote:
As for you, what are your experiences / projects with opDispatch?
Philippe
I was toying around with the idea of using it for a quick & dirty logger
and came up with this:
**************************
import std.stdio;
import std.string;
struct Log
{
File file;
this(string filename)
{
file.open(filename, "w");
}
void opDispatch(string s, string f = __FILE__, uint line = __LINE__,
S...)(S args)
{
file.writeln("[", f, " @ ", line, "][", toupper(s), "]", args);
}
}
**************************
And then use it like this:
log.error("This is an error.");
log.info("Wouldn't you like to know something?");
debug log.trace("Hey, this is happening now.");
version(AudioStats) log.audio("Some stats: ", foo, bar);
To me, this is much cleaner than the alternative, which would be
something like:
log.write("ERROR", "This is an error");