tags:

views:

61

answers:

4

I'm working on a logging system for my 2D engine, and I'm confused on how I should go about creating/editing the file, and how I should output that file.

I've learned that XML is more of a data carrier rather than a data displayer like HTML is. I've read that I can use XML to HTML converters. One method I've thought about is writing characters to a file in HTML.

Clarity on these matters is what I ask of you, stack overflow.

+1  A: 

Just about every log I've ever worked with has been pure text delimited by newlines. If you're going to depart from that, you may want to ask yourself what it is about your logging needs that you want to accomplish with markup.

If you must go the way of markup, I would suggest an XML format that contains a minimal set of markup that would be useful in your situation. You could use XML to capture structure in your log entries (timestamp, severity, and operational code, for example) that would be inconvenient to code for in HTML.

Note that you could also go hybrid and embed some XHTML tags in an XML element whose purpose is to capture displayable text, if you want.

Owen S.
+1  A: 

Creating an XML (or HTML) file doesn't need any special library. Straightforward string concatenation is usually good enough, you may have to encode some special characters (e.g. > into >.

But as Owen says, plain text is a log more common for log files. One reasonable compromise is comma-separated values in a text file, this gives you a little bit of structure without much overhead. For example, the Windows web server (IIS) uses this format by default, and if you have some fields that are output for each line such as timestamp or source filename and line number, this makes it easy to separate those out again.

Ben Voigt
"[...] plain text is a log more common [...]" That's a nice one!
sbi
I guess sometimes typos do work out. It wasn't intentional though.
Ben Voigt
+1  A: 

If you are considering writing logs in XML files, please, stop.

Log files should be simple plain text files, XML-izing it is introducing needless complexity. They are not structured data, they are meant to be read by people, not automated tools.

It all starts with XML logs, and then it goes downhill from there.

Alex B
+1  A: 

The problem with XML or HTML files is that you cannot append at any time. You have to close the final tag (document tag) properly at the end of writing.

Therefore, it's not a popular format for logging.

For logging, I suggest using one of the existing log engines, such as Apache logger, or, John Torjo's boost log candidate. They will support log levels, runtime configuration, etc.

Pavel Radzivilovsky
I have written small throw-away tools that would parse text-only log files and create nice, color-coded HTML (one color for one thread ID) output in order to understand MT issues. But, yes, logs should be written as plain text.
sbi