我的logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs.log</file>
<encoder>
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="FILE" />
</root>
</configuration>
我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.intexsoft.training.managers</groupId>
<artifactId>car-park-manager</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>managers</name>
<url>http://localhost:8080/car-park-manager</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>view.Runner</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>hibernate.cfg.xml</directory>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.11.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.11.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
我使用logging
@Controller
@RequestMapping("/")
public class MainController {
private static final Logger logger = LoggerFactory.getLogger(MainController.class);
@Autowired
BusService busService;
@Autowired
DriveService driveService;
@Autowired
RoteService roteService;
@RequestMapping(value = "buses", method = RequestMethod.GET)
public String indexBus(ModelMap model) {
logger.info("Did in MainController method indexBus");
logger.debug("Main controller");
StringBuilder sb = new StringBuilder("<br>");
sb.append("Buses").append("<br>");
busService.getBuses().forEach(it->sb.append(it.toString()).append("<br>"));
model.put("msg", sb.toString());
return "index";
}
...
}
我启动tomcat时的日志
C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24\bin\catalina.bat run
[2017-12-10 09:39:20,931] Artifact car-park-manager:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\user\.IntelliJIdea2017.2\system\tomcat\Unnamed_manager"
Using CATALINA_HOME: "C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24"
Using CATALINA_TMPDIR: "C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_112"
Using CLASSPATH: "C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24\bin\bootstrap.jar;C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24\bin\tomcat-juli.jar"
10-Dec-2017 21:39:21.688 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.24
10-Dec-2017 21:39:21.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 27 2017 13:05:30 UTC
10-Dec-2017 21:39:21.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.24.0
10-Dec-2017 21:39:21.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
10-Dec-2017 21:39:21.692 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_112\jre
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_112-b15
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\user\.IntelliJIdea2017.2\system\tomcat\Unnamed_manager
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\user\.IntelliJIdea2017.2\system\tomcat\Unnamed_manager\conf\logging.properties
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
10-Dec-2017 21:39:21.693 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\user\.IntelliJIdea2017.2\system\tomcat\Unnamed_manager
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Users\user\IdeaProjects\apache-tomcat-8.5.24-windows-x64\apache-tomcat-8.5.24\temp
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
10-Dec-2017 21:39:21.694 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
10-Dec-2017 21:39:21.700 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
10-Dec-2017 21:39:22.540 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2m 2 Nov 2017]
10-Dec-2017 21:39:22.632 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
10-Dec-2017 21:39:22.651 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
10-Dec-2017 21:39:22.656 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
10-Dec-2017 21:39:22.658 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
10-Dec-2017 21:39:22.658 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1223 ms
10-Dec-2017 21:39:22.676 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
10-Dec-2017 21:39:22.676 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.24
10-Dec-2017 21:39:22.676 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
10-Dec-2017 21:39:22.676 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
10-Dec-2017 21:39:22.692 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 36 ms
Connected to server
[2017-12-10 09:39:23,053] Artifact car-park-manager:war exploded: Artifact is being deployed, please wait...
10-Dec-2017 21:39:24.714 INFO [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 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.
Sun Dec 10 21:39:26 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sun Dec 10 21:39:27 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
[2017-12-10 09:39:28,386] Artifact car-park-manager:war exploded: Artifact is deployed successfully
[2017-12-10 09:39:28,386] Artifact car-park-manager:war exploded: Deploy took 5 333 milliseconds
Sun Dec 10 21:39:34 MSK 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
我继续http://localhost:8080/buses,并且logback不会创建文件。并且不写日志(当我创建文件时)。 我需要在文件日志中写日志。记录(我在模块中创建了这个文件) 当我遇到问题?
先谢谢你。