Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:09:50+00:00 2026-06-12T20:09:50+00:00

I have a log file that is being written using a defined slf4j XML

  • 0

I have a log file that is being written using a defined slf4j XML format. Is there a way to write a script, feeding in the XML format file, and then parsing the messages contained within?

Example output:

2012-10-11 16:53:25.895 [main] {} INFO  org.mortbay.log - jetty-6.1.11
2012-10-11 16:53:26.097 [main] {} INFO  / - Initializing Spring root WebApplicationContext

I want to create an output file (like a csv) that would separate by the columns based on the definition in the XML:

<encoder>
    <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] {%mdc} %-5level %logger{36} - %msg%n</pattern>
</encoder>

Any help/pointers would be GREATLY appreciated!

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:09:52+00:00Added an answer on June 12, 2026 at 8:09 pm

    Sure, there are plenty of ways of reading an XML file in Perl, including XML::Parser and XML::LibXML.

    I would start with XML::Parser. XML::LibXML seems to be better in the long run, but I feel way more comfortable with XML::Parser.

    EDIT: now that you have edited your question, I see that my response is not adequate. Clearly, getting the pattern (for which you might need the abovementioned XML modules or just a simple regex) will not be a problem. Unfortunately, I don’t know the possible formatting options of the pattern, they seem to be complex.

    You want to create a regex based on the pattern that you could then apply to each line.

    In this specific case, the regex would look like that:

    (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}:\d{2}.\d{3})\s\[(.*?)\]\s\{(.*?)\}\s(.*?*) - (.*)(\d*)
    

    Since I do know Perl, but do not know the message format, I can only make guesses. I assume that a formatting atom in slf4j follows the pattern %-?\w+(\{.*?\}|) — that is, a percent sign, optional minus, alphanumeric characters, and then, optionally, some additional formatting options in curly braces.

    Given that you managed to parse the XML formatting instructions and successfully extract the pattern to the variable $pattern, you now do the following:

    $pattern =~ s/%-?\w+(\{.*?\}|)/(.*?)/g
    

    Applied to your example pattern, this will produce the following regex:

    (.*?) [(.*?)] {(.*?)} (.*?) (.*?) - (.*?)(.*?)
    

    You can match it against every line of your log file:

    @parsed = ( $line =~ /$pattern/ )
    

    This is not perfect yet and will fail; you should recognize the date format, and distinguish between %n and %msg (I assume %n can only contains digits, if not, you have a problem). However, you see where this is going. Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a transaction log file in CSV format that I want use to
I have a script that runs at evening, it writes to a log file
I would like to monitor a log file that is being written to by
I have a program written in Delphi XE that plays a WAV file using
I have a log file that I'm trying to append data to the end
I have a log file that I am reading to a string public static
I have a log file in SqlServer that stores the time an application started,
I have a log method which saves to a file that is named the
I have one requirement that i have to place the log file in the
I have a command (cmd1) that greps through a log file to filter out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.