On Feb 8, 2013, at 7:57 AM, David <d...@dav1d.de> wrote:

> I am currently implementing a logging module, I want to make logging to
> stderr/stdout/"any file" possible, also during runtime-shutdown (logging
> from dtors)
> 
> Atm it lookes like this:
> 
> ----
> void log(LogLevel level, Args...)(Args args) {
>    string message = format(args);
> 
>    ... pass string to writer
> }
> ---
> 
> But format allocates! That makes it throw an InvalidMemoryOperationError
> when calling the logging function from a dtor. So I need a GC-free
> writer for std.format.formattedWrite, similiar to std.stdio's
> LockingTextWriter but with a buffer instead of a file
> (std.array.Appender GC free something like that). I couldn't come up
> with a working solution, I hope you have ideas.

Does your IO layer require one call per log line or can you do multiple writes 
followed by an "end log line" terminator?  Assuming the former, the most 
obvious approach would be for the writer to have a static array equal to the 
max log line size, accumulate until done and then issue one write to the output 
layer.

Reply via email to