Click here to Skip to main content
11,928,352 members (50,304 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked

LogXML - A XML Logging Class

, 11 May 2003
Rate this:
Please Sign up or sign in to vote.
A simple XML style logging class for all purposes.


Almost everybody needs sometimes something like a logging class. Me too. That is why I wrote such a class to do my logging although there are already some very convenient logging classes like CProtocol by jazper. But I thought of some general approach: Logging with XML.


The probably most interesting point is the possibility to log into a structure. Now you can log in a fairly natural way: simply go down one level if you call a function and after that go up and you will get a log structure that resembles your program's calling tree. All log entries will automatically get the right place.


Using LogXML is not very difficult. First of all:

  #include "LogXML.h"
Now you can instantiate LogXML by:

LogXML* log = new LogXML("LogFileName.xml", "ApplicationName");
There are several ways to write a Log Entry, some kind of Log Record can be written by:

log->Log("Error: Something is not correct. Please Fix.", // Entry
         __FILE__,               // Filename of Source File<
         "myLoggingFunction()"); // Function Name
Or you can write only one line by:

log->WriteLine("TagName", "This is your Log Entry");

The output (log file) of these examples is:

<?xml-stylesheet href="Log.xsl" type="text/xsl" ?>
        <Entry>Log File opened</Entry>
        <Entry>Error: Something is not correct. Please Fix.</Entry>
    <TagName>This is your Log Entry</TagName>
        <Entry>Log File closed</Entry>


To use such a log file you can use a XML parser like XPath or everything else you want. To convert a file produced by LogXML to something human-readable you can use for example XSL. Since my knowledge of XSL is not the best, I only managed to write a file named Log.XSL that shows Log Records of Level 1, i.e. do not use LogXML::goDown() and use only LogXML::Log() to write entries if you want to use it. And this is our sample Log File shown by Internet Explorer (6.0):


  • May 12, 2003 - First Release 1.0.0


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

SuggestionIs it there ? Pin
@amitgajjar15-Sep-12 1:09
member@amitgajjar15-Sep-12 1:09 
GeneralMy opinion Pin
ComaWhite8615-Nov-08 22:54
memberComaWhite8615-Nov-08 22:54 
GeneralGood idea - wrong tool Pin
Dimka912-May-03 11:15
memberDimka912-May-03 11:15 
GeneralRe: Good idea - wrong tool Pin
sirrube12-May-03 15:04
membersirrube12-May-03 15:04 
GeneralRe: Good idea - wrong tool Pin
whizer13-May-03 7:50
memberwhizer13-May-03 7:50 
GeneralRe: Good idea - wrong tool Pin
whizer13-May-03 7:44
memberwhizer13-May-03 7:44 
GeneralRe: Good idea - wrong tool Pin
Anonymous21-May-03 0:51
sussAnonymous21-May-03 0:51 
GeneralRe: Good idea - wrong tool Pin
whizer21-May-03 4:47
memberwhizer21-May-03 4:47 
GeneralRe: Good idea - wrong tool Pin
Hugo Hallman6-Sep-04 3:05
memberHugo Hallman6-Sep-04 3:05 
GeneralRe: Good idea - wrong tool Pin
tom.schultz5-Oct-04 0:53
membertom.schultz5-Oct-04 0:53 
I've been thinking about using the XML/XSL combo for logging for some time now, the reason for debugging is usually that something's wrong / you expect something to be wrong. In such a case you'd like to have enough information available to come to the correct conclution, and sometimes you want to come to the conclution fast. XML provides a good way to log information and XSL a way to format it so its easy to find. IMHO Smile | :)

Tom Schultz
GeneralRe: Good idea - wrong tool Pin
Andrea8617-Jan-07 1:23
memberAndrea8617-Jan-07 1:23 
GeneralRe: Good idea - wrong tool Pin
S.C.Wong30-Mar-08 1:41
memberS.C.Wong30-Mar-08 1:41 
AnswerRe: Good idea - wrong tool Pin
Dimitris Servis30-Jul-08 2:35
memberDimitris Servis30-Jul-08 2:35 
Questionquestion: the error can be catched? Pin
liuty200612-May-03 10:17
memberliuty200612-May-03 10:17 
AnswerRe: question: the error can be catched? Pin
whizer13-May-03 7:41
memberwhizer13-May-03 7:41 
GeneralPlease comment if you vote Pin
whizer12-May-03 6:43
memberwhizer12-May-03 6:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 12 May 2003
Article Copyright 2003 by whizer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid