You must put Logback directly in the classpath . See here :
The reservation can be configured either programmatically or with a script configuration expressed in XML or Groovy format. By the way, existing log4j users can convert log4j.properties files to logback.xml using our PropertiesTranslator web application.
We begin by discussing the initialization steps that should be performed to restore:
Logback tries to find a file called logback.groovy in the classpath.
If no such file is found, the log tries to find a file called logback-test.xml in the class path.
If no such file is found, it checks the logback.xml file in the classpath.
If no such file is found, and the executable JVM has a ServiceLoader (JDK 6 and above), ServiceLoader will be used to resolve the implementation of com.qos.logback.classic.spi.Configurator. The first implementation found will be used. See the ServiceLoader documentation for more information.
If none of the above is true, the log is automatically configured automatically using BasicConfigurator, which will cause the log output to be directed to the console.
It seems to me that your configuration file is not in the classpath . Typically, the configuration directory is not in the path to the default classes in most frameworks, in many cases these are /config/<files> , which are in the class path, and you must specify them with /config/name when loading them from using ClassLoader . However, Logback does not do this, so if you want to save the files in the config directory, you need to download them manually.
Essentially, you can tell JoranConfigurator to download the file from a custom location in the classpath, handle errors, etc., to make sure you find your file. See more details .
This is how I load my log configuration, you can probably adapt it to your system. In this case, resource is the path in your class path wherever you decide to place your logback.xml file. In this case, it will probably be /spring-xd/xd/config/logback.xml .
public class LogbackConfigurator { private static final Logger LOG = LoggerFactory.getLogger(LogbackConfigurator.class); public static boolean configure(String resource) throws JoranException { final InputStream configInputStream = LogbackConfigurator.class.getResourceAsStream(resource); final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext);
Typically, this method could be called one of the first lines in main with something like:
LogbackConfigurator.configure(path);
Once this class has been started, your log should be configured as if the system could normally find the configuration file. Note that you can also use -Dproperty=value and System.getProperties().get(keyname) to specify an alternative location for the path to the log file dynamically if you do not want to hardcode the location to your system.
You can also configure the location that should be included in the Spring configuration, but I personally do not recommend it, since you usually need to configure the registration before the injection occurs, so that if any registration events occur during the injection, they will be recorded accordingly.