Не показываются логи
В своем приложении я использую slf4j, cargo и logback. С помощью Cargo я запускаю контейнер с веб-приложением, поскольку с конфигурациями возникают проблемы. Я хочу выводить в консоль логи, однако, ничего не вижу.
pom 4.0.0
<groupId>ru.javawebinar</groupId>
<artifactId>topjava</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Calories Management</name>
<url>http://javaops-demo.ru/topjava</url>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<finalName>topjava</finalName>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.8.3</version>
<configuration>
<container>
<containerId>tomcat9x</containerId>
<type>embedded</type>
</container>
<deployables>
<deployable>
<type>war</type>
<location>${project.build.directory}/${project.build.finalName}.war</location>
<properties>
<context>/</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--Web-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- Logging with SLF4J and LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.7</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.7</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<profiles>
</profiles>
<dependencyManagement>
</dependencyManagement>
</project>
logback:
<!-- To enable JMX Management -->
<jmxConfigurator/>
<appender name="file" class="ch.qos.logback.core.FileAppender">
<file>${TOPJAVA_ROOT}/log/topjava.log</file>
<encoder>
<charset>UTF-8</charset>
<pattern>%date %-5level %logger{0} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>%-5level %logger{0} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<logger name="ru.javawebinar.topjava" level="debug"/>
<root level="info">
<appender-ref ref="file"/>
<appender-ref ref="console"/>
</root>
</configuration>
UserServlet:
package ru.javawebinar.topjava.web;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class UserServlet extends HttpServlet {
private static final Logger LOG = LoggerFactory.getLogger(UserServlet.class);
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/users.jsp").forward(request, response);
response.sendRedirect("users.jsp");
LOG.debug("redirect to users");
}
}
Вывод в консоли:
"C:\Program Files\Java\jdk-20\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\GitHubProjs\topjavaweb -Djansi.passthrough=true "-Dmaven.home=F:\IntelliJ IDEA 2023.1.3\plugins\maven\lib\maven3" "-Dclassworlds.conf=F:\IntelliJ IDEA 2023.1.3\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=F:\IntelliJ IDEA 2023.1.3\plugins\maven\lib\maven-event-listener.jar" "-javaagent:F:\IntelliJ IDEA 2023.1.3\lib\idea_rt.jar=58012:F:\IntelliJ IDEA 2023.1.3\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "F:\IntelliJ IDEA 2023.1.3\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar;F:\IntelliJ IDEA 2023.1.3\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2023.1.3 org.codehaus.cargo:cargo-maven2-plugin:1.8.3:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< ru.javawebinar:topjava >-----------------------
[INFO] Building Calories Management 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- cargo-maven2-plugin:1.8.3:run (default-cli) @ topjava ---
[INFO] [en2.ContainerRunMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-tomcat:jar:1.8.3 for container tomcat9x
[INFO] [beddedLocalContainer] Tomcat 9.x Embedded starting...
Nov 04, 2023 8:37:52 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Nov 04, 2023 8:37:52 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Nov 04, 2023 8:37:52 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.41]
Nov 04, 2023 8:37:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Nov 04, 2023 8:37:52 PM org.apache.catalina.core.StandardContext setPath
WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
Nov 04, 2023 8:37:52 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Nov 04, 2023 8:37:53 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Nov 04, 2023 8:37:53 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [162] milliseconds.
[INFO] [beddedLocalContainer] Tomcat 9.x Embedded started on port [8080]
[INFO] Press Ctrl-C to stop the container...