Home » Community » Forums » » Using XML Technologies For Enhancing Log Files
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic

Page:   1 2 »»

 Last Thread Next Thread 
 Using XML Technologies For Enhancing Log Files
Post Reply 
Beautiful. Just Beautiful. Thanks for the hard work guys! I will have to test this stuff out when I get my dev computer up and running again.

 User Rating: 1933   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Interesting, tho it should be noted that using XML+XSLT+javascript for logging is not new. GLIntercept has been doing it for some time in it's OpenGL logs.
Link: http://glintercept.nutty.org/Demo02/gliInterceptLog.xml


 User Rating: 1015    Report this Post to a Moderator | Link

Wow, this is great. Looks like my logging system needs an update. Is there something simmilar to __NAMESPACE__, __FILE__, __FUNCTION__ or __LINE__ avabile in C# (2.0) or do I have to use System.Diagnostics.Trace?


You should never let your fears become the boundaries of your dreams.

 User Rating: 1336   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Drew_Benton
Beautiful. Just Beautiful. Thanks for the hard work guys!

Cheers

Quote:
Original post by Anonymous Poster
Interesting, tho it should be noted that using XML+XSLT+javascript for logging is not new.

Very true, but it is a mature technology now... as I see it, it's done it's time as the "look at me! I'm a cool new thing you should use" and has refined itself into a solid set of technologies. More importantly, as I mentioned in the article, you have a lot of choices for the tools to create/view the results in...

Quote:
Original post by _DarkWIng_
Is there something simmilar to __NAMESPACE__, __FILE__, __FUNCTION__ or __LINE__ avabile in C# (2.0) or do I have to use System.Diagnostics.Trace?

I don't use C# myself, so I'm not sure... If you didn't have all the information available for free from the runtime/compiler you could, with a bit of effort, probably add this information in by defining some const/static strings?

hth
Jack


Jack Hoxley [ Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]

 User Rating: 1947   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

A very, very good article. Clear, informative, interesting, useful. I could go on. I've messed with using html/javascript for my log files, but I've never taken it to this level. I'm sure that now I will.

 User Rating: 1494   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

I've implemented this into my games since I saw what Jack's implementation of the original idea could do. I must admit that it's helped me out a lot with debugging. There's nothing worse than having to trawl through a log file looking for errors or warnings, it makes it so much easier to be able to colour-code the viewing of the log file and have the ability to see all errors or even ones from just a specific system.

 User Rating: 1902   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

I've been messing around with the code for a few hours, and I've already come up with an improvement I'd like to share.

In the .xsl file, the if statements compare the $eventType (and the $nameSpace, and $specificFile) with a literal string to see if that type of event needs to be filtered out. If the literal comparison is changed to 'contains($eventType,'Warning')' it becomes possible to view any combination of types. The types can then be toggled from the html/javascript to allow an even greater degree of customization. The same obviously goes for the namespace and specific file.

I hope someone finds this useful.

 User Rating: 1494   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

Oh God. I just finished my XML + XSLT like, 5 seconds before I saw the article. Great work, some of your features are very interesting, guess I'll get back and rewrite some parts of it

 User Rating: 1639   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Nice article. There is but one thing I'd like to suggest as an improvement and that's to possibly use an XML library to generate your xml documents with. Perhaps something like TinyXML? Or perhaps add a small interface that will XML encode your values? The reason I say that is because:

outFile " ";

may not result in well formed xml (eg. what if someString contained the text "X <

 User Rating: 1015    Report this Post to a Moderator | Link

Sorry (I didn't have well formed forum code ;)).

Nice article. There is but one thing I'd like to suggest as an improvement and that's to possibly use an XML library to generate your xml documents with. Perhaps something like TinyXML? Or perhaps add a small interface that will XML encode your values? The reason I say that is because:

outFile " ";

may not result in well formed xml.

Other than that, this is spot on :)

 User Rating: 1015    Report this Post to a Moderator | Link

AH! I give up.
Just watch for badly formed XML :D

 User Rating: 1015    Report this Post to a Moderator | Link

Thanks guys, great article.

edit: I could be wrong, but wouldn't the WriteLogEntry function be better off using const char * as the type for the __NAMESPACE__, __FILE__, __FUNCTION__, __LINE__ parameters? Else there is a lot of implicit std::string conversions going on that could impact performance.

[Edited by - DrEvil on June 13, 2005 10:24:32 AM]

 User Rating: 1464   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Anonymous Poster
AH! I give up.
Just watch for badly formed XML :D

you need to use the escape codes: &lt; or &gt; to get what you want:

outFile << " ";

Either way, I get what you're saying... I did cut a corner with that part of the code, but it wasn't really the main focus of the article. I had considered TinyXML, but it was a bit too much for what I personally needed - it's an unsafe assumption I know, but in my logfile output invalid characters aren't a problem

Quote:
Thanks guys, great article.

Glad you liked it

Jack


Jack Hoxley [ Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]

 User Rating: 1947   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Very nice article are there any sourcecode available? I'm curios about how you implemented the __NAMESPACE__, just had a "const char* __NAMESPACE__" or "const std::string __NAMESPACE__" variable in each namespace with the name of the namespace?

 User Rating: 1688   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by CTar
Very nice article are there any sourcecode available? I'm curios about how you implemented the __NAMESPACE__, just had a "const char* __NAMESPACE__" or "const std::string __NAMESPACE__" variable in each namespace with the name of the namespace?

The source code to the C++ part of things isn't included (iirc), but the rest is all included in a zip file here

__NAMESPACE__ is a bit of a hack sadly (), off the top of my head, it's just a #define __NAMESPACE__ "something" at the top of each/every file.

Jack


Jack Hoxley [ Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]

 User Rating: 1947   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by jollyjeffers
Quote:
Original post by CTar
Very nice article are there any sourcecode available? I'm curios about how you implemented the __NAMESPACE__, just had a "const char* __NAMESPACE__" or "const std::string __NAMESPACE__" variable in each namespace with the name of the namespace?

The source code to the C++ part of things isn't included (iirc), but the rest is all included in a zip file here

__NAMESPACE__ is a bit of a hack sadly (), off the top of my head, it's just a #define __NAMESPACE__ "something" at the top of each/every file.

Jack


I haven't read the article, but perhaps you could do something like this?

#define NAMESPACE(n)	namespace n {	const char *scope_ = #n;	}	namespace n

#define __NAMESPACE__	scope_

NAMESPACE(one)
{
	NAMESPACE(two)
	{
		void printnamespace(void)
		{
			std::cout << __NAMESPACE__ << std::endl;
		}
	}
}



Unfortunately, that would only print "two", not "one::two". If any enterprising individuals want to make some modifications to support that, I think it would be pretty cool.

Obviously you'd want to make it a little safer and use less common names than I used in the short example.


 User Rating: 1171   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

If anyone really needs some code for this, I can whizz you an example from my upcoming 4E4 entry. It's a pretty simplified version of what's happening here, but is similar in operation.

 User Rating: 1902   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by mfawcett
If any enterprising individuals want to make some modifications to support that, I think it would be pretty cool.


Well I got this to work for me:

const std::string __NAMESPACE__		= "";

#define NAMESPACE(n)\	
namespace n	\ 
	{\ 
		const std::string _INTERNAL__SCOPE_STR_TEMP = __NAMESPACE__;\ 
		const std::string __NAMESPACE__ = ((_INTERNAL__SCOPE_STR_TEMP+"::")+#n);\ 
	}\ 	
	namespace n\ 







EDIT: Is there a way to make \ in the sourcecode? (FIXED)

 User Rating: 1688   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Good modifications for the __NAMESPACE__ thing! thanks for posting them (++rating)... think I might implement them in my own code. Probably a bit too late to update the article now thought

Cheers,
Jack


Jack Hoxley [ Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]

 User Rating: 1947   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Hi,

I've tried this approach before and found it to be very informing but for one situation: a program crash.

When that happens your log will be incomplete and will contain malformed XML. And since it's a very strict language, many (good) XML viewers will be unable/unwilling to show you the contents. This again means that tracking down the reason your app crashed must begin with fixing your log.

I'm curious, considering the high level of content in your article, if you have found a solution for that.

cu,
CipherCraft


 User Rating: 1041   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

To stop a malformed xml file. Just add the closing tag after each LogEvent.
But remember to get the file position before the closing tag, so when you add the next event go to the remembered file position write the new event, remember the position and add the closing tag.

ofs.seekp(file_position);

// output log event

file_position = ofs.tellp();
ofs << "</RunTimeLog>" << std::endl;
ofs.flush();



Marcus

EDIT: put it in source

 User Rating: 1035   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by CipherCraft
I've tried this approach before and found it to be very informing but for one situation: a program crash.


More than likely, the malformed Xml will be due to an unterminated xml tag and not as a result of a crash during log writing (could happen though it's unlikely). In this scenario, I've found it best to have a log shutdown routine that is called when your application catches a fatal exception - the shutdown routine finalises the log file ready for viewing. It's worth noting that you can open the logfile in a text editor to view the last sequence of entries to allow you to see where the crash happened, even if the logfile isn't termiated properly.

 User Rating: 1902   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Hi,

I think this is a great article, even though I haven't read it completely yet. One thing I noticed though is that your "id" attributes don't conform to the XML standard. In section 3.3.1 of the standard it reads:

Quote:

Validity constraint: ID

Values of type ID MUST match the Name production. A name MUST NOT appear more than once in an XML document as a value of this type; i.e., ID values MUST uniquely identify the elements which bear them.


And this name production is found in section 2.3:

Quote:

[5] Name ::= (Letter | '_' | ':') (NameChar)*


Which means that the ID attribute needs to start with either a letter, an underscore, or a colon.

Not a big deal, but somehow I felt the need to point that out... ;)

Cheers,
Drag0n

 User Rating: 1057   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I too am interested in xml for logging purposes. The only reason I hesitated was this:

Microsoft has been granted United States patent 6,687,897 for "XML script automation."

"While the XML standard itself is royalty free, nothing precludes a company from seeking patent protection for a specific software implementation that incorporates elements of XML. This does not, in any way, change the royalty-free nature of the XML standard itself."

The way the last paragraph reads to me is "Using xml is fine in your app - until Microsoft wants to play ball too. Then they will use the bat on you."

I just program. I'm no lawyer. Can anyone can clear this mess up?

 User Rating: 1015    Report this Post to a Moderator | Link
Page:   1 2 »»
All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: