Game Development Reference
In-Depth Information
Generating HTML Logs
Generating log files in HTML format after an application has performed its activities is fairly straightforward. You can
easily categorize and store any interesting events in a list. You then iterate through each category and write out that
category's events to an HTML file before the application terminates.
However, most of your logs will need to be written out while your game or tool is running. This is often essential;
you frequently need to gather incremental information on your application, especially when it crashes before
completing its task. Therefore, you must write out your HTML file in such a way that it remains valid after each written
update. This requirement makes it necessary to implement a method of ensuring that the HTML tags you create are
always correctly terminated.
A simple solution is to create a class that keeps a stack of the terminating HTML tags. When you create a new
starting tag, you must push the corresponding terminating tag on to your stack and make a note of its length. Once
you are finished filling in data for the tag, you write out the tag and then remove the corresponding terminating tag
from the stack.
Every time you append HTML data to your currently open tags, you must first seek to the end of the HTML file,
minus the combined text size of your stacked terminating tags. You then write out the new data to the file and then
write out all the terminating tags contained within your stack.
For example, say you are writing out a simple table logging all asserts that fired while running a game. You want
to add a new row to your table every time an assert fires. Therefore, you will write the following to your log file when
you start the game, as shown in Listing 9-1.
Listing 9-1. Creating a Simple HTML Template for Your Log
<HTML>
<HEAD>
Our game's run-time assert log
</HEAD>
<BODY>
<TABLE>
</TABLE>
</BODY>
</HTML>
As you are going to be generating data for the <TABLE> tag, you will still have the preceding HTML , BODY , and
TABLE tags left non-terminated. Therefore, you will have pushed onto your stack the </HTML> , </BODY> , and </TABLE>
terminating tags.
When writing out a new row of data for the table, you must first seek to the start of the </TABLE> tag. You then
write the new table row, and then rewrite the terminating </TABLE> , </BODY> , and </HTML> tags. This approach
ensures that the file always remains valid.
While exploring all the available HTML tags is beyond the scope of this chapter, I will briefly touch on a few tags
I have found to be particularly useful.
TABLE
The TABLE tag provides you with the simplest way to organize the data being logged by your application. You can treat
each table row as an item of generated information, such as the details of a triggered assert, or the name of a tested
checkpoint from an auto-run of the game.
 
Search WWH ::




Custom Search