How to configure log4j with a properties file

前端 未结 9 1896
春和景丽
春和景丽 2020-11-29 03:01

How do I get log4j to pick up a properties file.

I\'m writing a Java desktop app which I want to use log4j. In my main method if have this:

   Proper         


        
9条回答
  •  萌比男神i
    2020-11-29 03:42

    Since JVM arguments are eventually passed to your java program as system variables, you can use this code at the beginning of your execution point to edit the property and have log4j read the property you just set in system properties

    try {
            System.setProperty("log4j.configuration", new File(System.getProperty("user.dir")+File.separator+"conf"+File.separator+"log4j.properties").toURI().toURL().toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    

提交回复
热议问题