debugger blues
cy via Digitalmars-d
digitalmars-d at puremagic.com
Wed Mar 30 19:52:20 PDT 2016
On Tuesday, 29 March 2016 at 23:49:21 UTC, Marco Leise wrote:
> It is straightforward to put spaces between arguments:
> warningf("%s %s %s", "puts", "spaces", "inbetween");
warningf("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s
%s","I","really","don't","know","how","straightforward","that","is","if","you","have","to","manually","count","every","argument","you","pass.");
> If you refer to the common headers that go before each message,
No, I'm referring to concatenating all the arguments before
passing the message to the logger.
> WTF? :p
It's not that crazy an idea. If something takes multiple strings
and doesn't format them the way you like it, then you write a
wrapper around it that takes multiple strings, formats them, then
passes the one string result downward. Just doesn't work so well
with logging, since __file__ and the like need to be passed
along, so they end up adding up a lot of boilerplate.
Anyway, I figured out a way to do it. I thought formattedWrite
was just concatenating the arguments with an Appender!string, but
I was wrong. It actually is taking an output range that calls
logMsgPart for each of the arguments. So... I have nothing to
complain about really. What I thought wasn't there, I actually
just missed seeing.
import std.experimental.logger;
import std.stdio;
class MyLogger: Logger {
bool started;
this() {
super(LogLevel.warning);
started = false;
}
override
void writeLogMsg(ref LogEntry payload) {
writeln("uhhh");
}
override void logMsgPart(const(char)[] msg) {
if(msg.length == 0) return;
if(started)
write(" ");
else
started = true;
write(msg);
}
override void finishLogMsg() {
started = false;
writeln("");
}
}
void main() {
(new MyLogger()).warning("is","this","a","good","idea?");
(new MyLogger()).warning("python","ruined","me");
}
More information about the Digitalmars-d
mailing list