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 6920647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:10:27+00:00 2026-05-27T10:10:27+00:00

I have the following conversion patter generated by the log file. %d [%t] %-7p

  • 0

I have the following conversion patter generated by the log file.

%d [%t] %-7p %10c{1} – %m%n

what i want is take this pattern in my program and parse the log line according to this,might be using regular expression or anything.

  • 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-05-27T10:10:28+00:00Added an answer on May 27, 2026 at 10:10 am

    Here is a regex parser for that message format:

    public static void main(String[] args) {
    
        // %d [%t] %-7p %10c{1} - %m%n
    
        // ISO8601_date
        // space
        // [
        // thread_id
        // ]
        // space
        // priority
        // space
        // category (basename)
        // space
        // -
        // space
        // message
        // line.separator
    
        String[] samples = {
            "1999-11-27 15:49:37,459 [thread-x] ERROR mypackage - Catastrophic system failure"
        };
    
        String regex = "(\\d{4}-\\d{2}-\\d{2}) (\\d{2}:\\d{2}:\\d{2},\\d{3}) \\[(.*)\\] ([^ ]*) ([^ ]*) - (.*)$";
    
        Pattern p = Pattern.compile(regex);
    
        Matcher m = p.matcher(samples[0]);
    
        if (m.matches() && m.groupCount() == 6) {
            String date = m.group(1);
            String time = m.group(2);
            String threadId = m.group(3);
            String priority = m.group(4);
            String category = m.group(5);
            String message = m.group(6);
    
            System.out.println("date: " + date);
            System.out.println("time: " + time);
            System.out.println("threadId: " + threadId);
            System.out.println("priority: " + priority);
            System.out.println("category: " + category);
            System.out.println("message: " + message);
        }
    }
    

    The output is:

    date: 1999-11-27
    time: 15:49:37,459
    threadId: thread-x
    priority: ERROR
    category: mypackage
    message: Catastrophic system failure
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following information in log4j.properties file.. log4j.appender.file = org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File = C:\\app\\file.log log4j.appender.file.Threshold
I have the following implicit conversion for java.util.Enumerations implicit def enumerationIterator[A](e : Enumeration[A]) :
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
I have following text in a file 23456789 When I tried to replace the
I have the following log4net configuration <log4net debug=true> <appender name=RollingLogFileAppender type=log4net.Appender.RollingFileAppender> <file value=Logs\\CurrentLog.txt/> <appendToFile
I have the following file Log4net.config in my bin directory: <?xml version=1.0 encoding=utf-8 ?>
I have the following in log4j.xml file, when I run my application. Only error
I have the following code: private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); XmlConfigurator.Configure(new FileInfo(log4net.config));
Note, this is some ancient NHibernate installation! I have the following NHibernate class: [Serializable]
I have the following SQL Server error in ASP.net C#: The conversion of a

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.