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 3 of 3

Thread: SLF4J with java.util.logging - How to set log into files

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default SLF4J with java.util.logging - How to set log into files

    Hi,

    I'm very confused and yours help

    I'm using SLF4J with java.util.logging (I add slf4j-jdk14-1.7.5.jar file into the path).

    when I run this code:

    public class CMain {
    final static Logger logger = LoggerFactory.getLogger(CMain.class);

    public static void main(String[] args) {
    logger.info("Hello World");
    logger.debug("Debug TEST");
    }
    }

    1. I can see "INFO: Hello World 1" only , and cant see the "Debug TEST" line.
    why ?

    2. I want to log into files and not into the console,
    How can I do it ?

    I search in SLF4J site , but didt get any answers.

    Thank's


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: SLF4J with java.util.logging - How to set log into files

    Quote Originally Posted by amit1983 View Post
    I'm using SLF4J with java.util.logging (I add slf4j-jdk14-1.7.5.jar file into the path).
    SLF4J is only a logging "facade", in other words it's an abstraction layer for other real logging frameworks (log4j, java.util.logging, etc...). So SLF4J itself has no configuration. The configuration is for the real logging library/framework.
    Since you have picked the java.util.logging, you should see its reference documentation, that is here:

    http://docs.oracle.com/javase/7/docs...ing/index.html

    Quote Originally Posted by amit1983 View Post
    1. I can see "INFO: Hello World 1" only , and cant see the "Debug TEST" line.
    why ?
    There is a default configuration file in your JRE, it's named logging.properties and you can find it under the "lib" directory of your JRE (for example the private JRE of the JDK, eg. .../jdk1.7.0_xx/jre/lib ).

    You will find the rows:
    .level= INFO
    java.util.logging.ConsoleHandler.level = INFO


    This means that the minimum level logged is INFO (globally but also specifically for ConsoleHandler). Note that java.util.logging does not have the "DEBUG" name, there are other names. SLF4J "maps" debug() to FINE (see javadoc of org.slf4j.impl.JDK14LoggerAdapter). And FINE has less priority than INFO, so with default configuration, debug() is not logged.

    Quote Originally Posted by amit1983 View Post
    2. I want to log into files and not into the console
    Again, the default configuration file of java.util.logging contains:
    handlers= java.util.logging.ConsoleHandler


    Solution: understand how java.util.logging can be configured and write your configuration file.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. The Following User Says Thank You to andbin For This Useful Post:

    ChristopherLowe (December 7th, 2013)

  4. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SLF4J with java.util.logging - How to set log into files

    thanks

Similar Threads

  1. Replies: 4
    Last Post: April 16th, 2013, 06:50 AM
  2. Replies: 1
    Last Post: April 16th, 2013, 04:25 AM
  3. Comparing two log files ignoring the lines
    By Rajitha in forum Java Theory & Questions
    Replies: 1
    Last Post: July 16th, 2012, 11:00 AM
  4. [SLF4J] 'java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory'
    By Jonathansafc in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 18th, 2011, 07:42 AM
  5. [SOLVED] Compile a set of java files for a sudoku program
    By kanishk.dudeja in forum Java Theory & Questions
    Replies: 7
    Last Post: June 16th, 2011, 09:54 AM