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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:59:03+00:00 2026-06-12T10:59:03+00:00

I am adding a logger to my program, surfing the net I add to

  • 0

I am adding a logger to my program, surfing the net I add to my code a very simple logger with the basic 2-line definition:

private static final Logger LOG = Logger.getLogger(GUI.class.getName());

public MyClass(){

    //other stuff...
    LOG.info("text to log");
    //other stuff...
}

After few hours of developing I was wondering how to format the style of the logged text and I came to this class:

java.util.logging.SimpleFormatter

Reading the Javadoc I can find:

The formatting can be customized by specifying the format string in the java.util.logging.SimpleFormatter.format property.

There are also few examples:

Some example formats:
java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"
This prints 1 line with the log level (4$), the log message (5$) and the timestamp (1$) in a square bracket.

WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011]

I tried each one of them, but the “format” field is “not visible” (private I suppose) so I can’t edit it directly. There isn’t any method similar to
setStringVar(String regex);
to set the var from the outside.

I tried to extends the class
public class MyClass extends SimpleFormatter{

but “format” var is not editable. I also tried extending Formatter (the super-class of SimpleFormatter) without success.

The only thing I could do is to extend SimpleFormatter and manually override its:
public String format(LogRecord rec);
with boring and complicated code.

I was just wondering if is there any way to simply use the inside regex reader of the SimpleFormatter Class

EDIT:errors

  • 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-12T10:59:04+00:00Added an answer on June 12, 2026 at 10:59 am

    Have you looked at the JavaDoc. It gives a overview of the SimpleFormatter.

    Also, format is a public method within SimpleFormatter.

    Further the line

    java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"
    

    should be defined in a properties file and not the Java class.

    To be honest, I don’t use java.util.logging I use log4j as Fildor mentioned. I find it much simpler. First you need a config file, like log4j.xml below:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
    <log4j:configuration>
        <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d %5p %c{1}:%L - %m%n"/>
            </layout>
        </appender>
        <root>
            <priority value="debug"></priority>
            <appender-ref ref="stdout"/>
        </root>
    </log4j:configuration>
    

    You are free to tweak the conversion pattern, see PatternLayout for details. Then in your class define the following private static member

    static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(Testing.class);
    

    The simply when you want to output logging do:

    LOG.error("Test Error");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Adding strings localization files in iPhone bundle is very simple and perfectly fine but
A simple XY line graph: The X axis will represent the complete range of
I'm adding logging to some python code that deals with exceptions, in the example
Simple synopsis: I have a program which needs authentication from user to get access
I work in C#, .Net 2.0. When I debug my code everything works fine.
I am adding loggers at runtime in log4j.xml <logger name=com.bas> <priority value=DEBUG/> <appender-ref ref=B2BAPP/>
I have created my own simple logger class which uses COM interop to redirect
Adding more and more configurations to my servlet container ( Embedded Jetty in my
Adding more than one child to a WPF StatusBar results in poor layout with
Adding Exceptional Handling is a good practise, but I have a doubt, In our

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.