[logback-user] Simplest Java sample; Simplest logback.xml; what no logfile

Kundan Bapat kundan.bapat at gmail.com
Wed Jun 26 08:02:58 CEST 2013


Single barebones Java file using slf4j package - 2 imports; Default package.
barebones logbackxml - directly under classpath - which is 'current
directory'.

The log statements in file seen on console, but no FileAppender (file)
created.
Messing with logback.xml syntax makes no difference - means it is simply not
read by the program.

I can use help.  This is my first trial with logback; only used log4j a
while back.  no groovy or maven nothing.  plain command line javac and java.

Java:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NMSLogger {
    private final Logger nmsLogger =
LoggerFactory.getLogger(NMSLogger.class);

    public void sayHello(String name) {

        nmsLogger.info("INFO: Hi, {}", name);
        nmsLogger.info("INFO:Welcome to the NBN NMS LogBack World.  Hello
World!\n");
        nmsLogger.error("EROR:Welcome to the NBN NMS LogBack World.  Hello
World!\n");
    }
    public static void main(String[] args) {
        NMSLogger theLogger = new NMSLogger();
        theLogger.sayHello("srccodes.com");
    }
}
------------- logback.xml:
<configuration>
  <appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>logFile.log</File>
    <rollingPolicy
      class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <FileNamePattern>
             logFile.%d{yyyy-MM-dd}.log.zip
      </FileNamePatter>
    </rollingPolicy>

    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>
        %d{HH:mm:ss,SSS} [%thread] %-5level %logger{22} - %msg%n
      </Pattern>
    </layout>
    <root level="${root-level:-debug}">
      <appender-ref ref="FILE"/>
    </root>
  </appender>
</configuration>
----------- dir:
logback.xml  NMSLogger.class  NMSLogger.java  slf4j-api-1.7.5.jar* 
slf4j-jdk14-1.7.5.jar
==========

Any help, pointers please?



--
View this message in context: http://logback.10977.n7.nabble.com/Simplest-Java-sample-Simplest-logback-xml-what-no-logfile-tp12583.html
Sent from the Users mailing list archive at Nabble.com.


More information about the Logback-user mailing list