"Off the shelf" way to use log4j's XMLLayout?

Notes, tips, and other usefull things on how to use LogMX

Moderator: admin

Post Reply
dovinci
Posts: 1
Joined: Wed Dec 26, 2007 6:26 am
Location: Vancouver, WA USA

"Off the shelf" way to use log4j's XMLLayout?

Post by dovinci » Wed Dec 26, 2007 6:30 am

I'm working with logs created with log4j's rolling file appender, using a layout that uses org.apache.log4j.xml.XMLLayout.

I'm wondering what the easiest / quickest way is to use LogMX with these log files. I'm trying to configure parsers several ways, but don't really know what I'm doing... and I'm not successfully defining a parser for these XML log4j log files yet.

I have specified a pattern string for some secondary log files that my system can generates, and that works fine.

But the primary log files are generated using the XMLLayout layout. Any hints how to parse those files with LogMX?

admin
Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Post by admin » Wed Dec 26, 2007 11:09 am

Hello,

To read such XML files, you can use one of these two ways:
  • Create a LogMX Java Parser that will use an XML parser (SAX may be better here than DOM). This solution will be useful if you want to use, for example, XSD/DTD (XML validation) or XML entities in your files (e.g. to translate ">" in ">")
  • Create a LogMX Java Parser that will parse the XML stream itself. This solution will be useful if your format is not very complex. It will also be easier to implement.

To create a LogMX Java Parser, you only have to write a single Java class, here are a few links for documentation:
  • http://www.logmx.com/p_parser_dev.php
  • Directory "help/parsers_api/" (or "help/api/" since v1.2.2) of your LogMX directory (API javadoc)
  • Directory "parsers/src/sample/" of your LogMX directory (Java Parser sample)

Feel free to post any question you may have on parser development (our forum has a section called "Writing a Parser")

lost_traveller
Posts: 6
Joined: Mon Mar 31, 2008 12:41 pm

Post by lost_traveller » Mon Mar 31, 2008 12:42 pm

Did you manage to implement this as I need this too? could you post the source code please?

I've very surprised this isn't supported by default.

admin
Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Post by admin » Mon Mar 31, 2008 11:47 pm

Hello,

You're right, it's a common log4j layout. It will be included in the next release (v1.2.3) that should be available in one or two weeks. In the meantime, here is the Java Class Parser that will be used in this next release:
http://www.logmx.com/dev/parsers/Log4jXMLLogFileParser.java.html
  • copy/paste this code in a file "Log4jXMLLogFileParser.java"
  • modify 1st line of file to use your own package
  • move this .java file in the sub-folder matching your package name, in "parsers/src/" LogMX directory (e.g. "parsers/src/my/parser" for "my.parser")
  • type "ant" in a shell in "parsers/" LogMX directory (if you don't have Ant, you can use the Eclipse project in "parsers/" directory)
  • [Re]start LogMX and go to "Tools" > "Options" > "Parsers" > green "+" button > tab "Java parser class" > select your class "Log4jXMLLogFileParser" and click OK


Feel free to post any other question/problem on this forum.

lost_traveller
Posts: 6
Joined: Mon Mar 31, 2008 12:41 pm

Post by lost_traveller » Wed Apr 02, 2008 7:54 am

Thats great! many thanks! i'm sure this will be very useful to many others too!

I know this probably isnt a place for it but there is a bug that "Integrate with windows explorer" does not work if you install to a directory which contains a space, eg "C:\program files\"

Also could you add a tick box and "always use this option" to the dialog which says "open file in new tab or merge with current file" please?

Also the integrate with explorer associates all files with LogMX, it should only associate a subset, e.g. .log files, and use shellex i.e.:

[HKEY_CLASSES_ROOT\.log\shellex...

admin
Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Post by admin » Thu Apr 03, 2008 9:05 pm

Hello,

We are currently working on a new full-win32 based solution to re-implement the "Open with LogMX" context menu item.
Indeed, the current implementation doesn't work for install directories containing a space, and, you're right, information should be written in registry in "shellex" and use a DLL. It should be available within a few weeks. Yet, this version will still add this context menu item for all files, because log files can use .txt, .html, .xml, .trace,...extensions. Next releases may let the user choose extension(s) to use, or all of them.

For the dialog "open file in new tab or merge with current file", we will add such a check box in this dialog, and a new Combo box in global Options dialog: "When dropping a file onto another file: [Ask me what to do(default)/Open file in new tab/Merge file with current file]". Thanks for this idea!

admin
Site Admin
Posts: 418
Joined: Sun Dec 17, 2006 10:30 pm

Post by admin » Wed Apr 16, 2008 8:55 pm

Hello,

The new version v1.2.3 released today includes the new Log4j XML Parser, a new version of "Open with LogMX" context menu item, and it now allows the user to always open or merge a file dropped on the main window.

lost_traveller
Posts: 6
Joined: Mon Mar 31, 2008 12:41 pm

Post by lost_traveller » Fri Apr 18, 2008 7:31 am

Thanks for that, we have been discussing some other features which we would like to see, someone suggested it remembering the shown/hidden classes as well as the columns?

Post Reply