Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: logging.properties file ignored

  1. #1
    Junior Member
    Join Date
    Sep 2024
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default logging.properties file ignored

    Hi!
    I'm trying to learn about java.util.logging with a really basic Maven project.
    I have a single class "HelloWorld" wich contains:

    package fr.ill.ics.log;

    import java.util.logging.Level;
    import java.util.logging.Logger;

    public class HelloWorld {

    private static Logger logger = Logger.getLogger(HelloWorld.class.getName());

    public static void main(String[] args) {

    logger.info("INFO log");

    logger.log(Level.WARNING, "WARNING log");

    logger.log(Level.SEVERE, "SEVERE log");
    }
    }


    and a logging.properties file in my directory "src/main/resources":


    handlers=java.util.logging.FileHandler,java.util.l ogging.ConsoleHandler
    .level=SEVERE
    java.util.logging.FileHandler.pattern=%h/java%u.log
    java.util.logging.FileHandler.limit=50000
    java.util.logging.FileHandler.count=1
    java.util.logging.FileHandler.formatter=java.util. logging.XMLFormatter
    java.util.logging.ConsoleHandler.formatter=java.ut il.logging.SimpleFormatter
    java.util.logging.SimpleFormatter.format=[%1$tc] %4$s: %5$s %n


    The problem is that my main class totally ignores the configuration file, I can see that when I change the log level inside logging.properties.
    What am I doing wrong ?
    Thanks!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,106
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: logging.properties file ignored

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2024
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: logging.properties file ignored

    Quote Originally Posted by Norm View Post
    yes, my example comes from there

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,106
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: logging.properties file ignored

    Another link found on above site: https://docs.oracle.com/en/java/java...0-0C0DDA271DBC

    Here is the commandline used to execute the program:
    java -Djava.util.logging.config.file=logging.properties HelloWorld
    Log file is written here: C:\Users\Norm\java0.log
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Sep 2024
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: logging.properties file ignored

    Thanks a lot it works well !

Similar Threads

  1. Logging excel file using log4j.properties
    By sneha343 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 6th, 2011, 10:03 AM
  2. How to get File Properties like Subject , commnet
    By MVK in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 26th, 2011, 12:59 PM
  3. Paramaters to update properties file
    By d0nal in forum Java Theory & Questions
    Replies: 1
    Last Post: September 14th, 2011, 11:17 AM
  4. Structured Properties File?
    By moka in forum Java Theory & Questions
    Replies: 7
    Last Post: October 19th, 2010, 11:14 AM
  5. Accessing Properties File
    By java_mein in forum Java Servlet
    Replies: 5
    Last Post: May 14th, 2010, 02:44 AM