[MUD-Dev] Technical programming question (circular buffers & logging)

Chris Gray cg at ami-cg.GraySage.Edmonton.AB.CA
Wed Jul 14 22:35:53 New Zealand Standard Time 1999

[Ben Greear:]

> So, what I want to do is modify my logging class (basically just
> an ofstream with some flags tacked on it).  I was thinking about
> making it a sort of ring-buffer where it just kept the last 50k
> or some other nice round number.

I've used that technique both in my MUD and at work. It works pretty well.
Rather than getting complex and logging full text messages, however, we've
tended to just log simpler things. My MUD just logs a pointer to a text
message, and a single 32 bit value. If the system itself aborts, it
dumps the contents of the ring out - it deferences the string pointers
to get the actual text. I think there was an occasion at work where I
needed to look at the buffer in a core dump, and it was a bit clumsy,
but certainly doable.

> Oh, one final thing:  If I keep it all in memory, I will want to
> (at least) catch the SIGSEGV can flush it to disk at that time.
> Does anyone forsee any problems with this??

Should work, as long as you rely on as little as possible in the dumping
code. E.g. open the logging file with a low level 'open' call, write
it out with no use of stdio, iostream, etc., then close it. That should
minimize the amount of code/data you depend on, and reduce the likelihood
of a nested SEGV.

Don't design inefficiency in - it'll happen in the implementation.

Chris Gray     cg at ami-cg.GraySage.Edmonton.AB.CA

MUD-Dev maillist  -  MUD-Dev at kanga.nu

More information about the MUD-Dev mailing list