Hi Everyone,
I am trying to get my new Vaadin Project running with Logback and it does not work.
What i did:
Read the Vaadin Book: https://vaadin.com/book/-/page/advanced.logging.html
My code looks like:
import javax.servlet.annotation.WebServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
@Theme("myvaadin")
public class MyvaadinUI extends UI {
static {
// SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}
private static final Logger logger = LoggerFactory.getLogger(MyvaadinUI.class);
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyvaadinUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
setSizeFull();
VerticalLayout root = new VerticalLayout();
setContent(root);
root.addComponent(new Label("success"));
logger.info("success");
}
}
To the Ivy.xml, I added:
<dependency org="org.slf4j" name="jul-to-slf4j" rev="1.7.12"/>
<dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.4"/>
<dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.4"/>
<dependency org="ch.qos.logback" name="logback-classic" rev="1.1.3"/>
The Logback.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread]
%-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.example.myvaadin" level="ERROR" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<!-- Strictly speaking, the level attribute is not necessary since -->
<!-- the level of the root level is set to DEBUG by default. -->
<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
What I now expected, is NO Output, because I set the logging level to ERROR and all I added was … info(“…”), and there are no errors.
Interessting is that I also get an error that no logging ConsoleHandler was found.
Here is my Console Output:
[code]
01:24:37,510 WARNING [com.vaadin.server.DefaultDeploymentConfiguration]
(default task-27)
Vaadin is running in DEBUG MODE.
Add productionMode=true to web.xml to disable debug features.
To show debug window, add ?debug to your application URL.
01:24:37,602 ERROR [stderr]
(default task-30) Handler java.util.logging.ConsoleHandler is not defined
01:24:37,619 INFO [com.example.myvaadin.MyvaadinUI]
(default task-32) success
[/code]Do you have any Ideas what I did wrong? Or any suggestions what i could improve.
Thanks