std.logger

Johannes Pfau nospam at example.com
Thu Aug 22 10:48:18 PDT 2013


Am Thu, 22 Aug 2013 19:13:05 +0200
schrieb Robert Schadek <realburner at gmx.de>:

> On 08/22/2013 06:01 PM, develop32 wrote:
> > Why logging functions accept only a string? I would expect it to
> > behave as std.stdio with its variadic parameters.
> >
> > It would be more straightforward to write logging code:
> >
> > log("Moving ", data, " to ", destination);
> >
> > Where 'data' and 'destination' are any variables. I use such setup
> > in my projects and it helps greatly to identify what went wrong
> > when not using a debugger.
> >
> I thought about that. IMO this would create very heavy template bloat,
> because you would also have to pass __LINE__, __FUNCTION__ as template
> arguments.
> Whats so wrong with log("%s %s %s %s".format("Moving", "data", "to",
> destination)); This way you don't have to remember to place the spaces
> left and right.

The problem is that format allocates using the GC. Functions like
writefln can be much more efficient so if the backend is a FileLogger it
could take advantage of that. But IIRC it's not simple to implement
this 'forwarding' with classes / interfaces as you'll need templated
functions...


More information about the Digitalmars-d mailing list