为什么我的日志文件没有在本地资源管理器中创建



我只想记录我在运行时得到的异常。我有一个Application_Logger.class,Application.properties,log4j2。属性文件。当然还有主课。有人能帮我创建一个日志文件吗?

应用程序记录器类

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ApplicationLogger {
transient static Logger cat = (Logger) LogManager.getLogger(ApplicationLogger.class);
public static final boolean TRACE_EMPTY_EXCEPTION_CALL = true;
/**
*  Logs the message
*/
public static void log(String message){
cat.debug(message);
}
public static void log(String message, UserDTO loginUser) {
cat.debug(getLoginUserDetails(loginUser) + message);
}
/**
* Logs the message and the exception
*/
public static void log(String message, Exception e){
log(message, e, null);
}
public static void log(String message, Exception e, UserDTO loginUser) {
if(e != null)
cat.error(getLoginUserDetails(loginUser) + message, e);
else {
if(TRACE_EMPTY_EXCEPTION_CALL) {
try {
throw new Exception("Empty exception encountered");
}catch(Exception ex) {
log(message, ex, loginUser);
}
}
else
cat.debug(getLoginUserDetails(loginUser) + message);
}
}
/** logs the message as an error
* 
* @param message
*/
public static void logError(String message){
logError(message, null);
}
public static void logError(String message, UserDTO loginUser){
cat.error(getLoginUserDetails(loginUser) + message);
}
public static void log(String empNo, String operation, String operand){
cat.debug(empNo + ":" + operation + ":" + operand);
}
public static String getLoginUserDetails(UserDTO loginUser) {
if(loginUser == null)
return "";
return "[" + loginUser.getEmpId() + ", " + loginUser.getTenantId() + "] ";
}
}

Application.properties文件

log4j2.debug=true

InitApplication.class

@SpringBootApplication
@CrossOrigin("http://localhost:3000")
public class InitApplication implements CommandLineRunner{
public static void main(String[] args) {        
SpringApplication.run(InitApplication.class, args);
}
}

这只是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 
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>ABC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ABC</name>
<description>LOG4j2</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>



<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>


<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>   

</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

然后我添加了这些行,基本上,我排除了Spring引导默认启动记录器,并通过添加其依赖项添加了log4j2记录器。像这样。

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>  

相关内容

  • 没有找到相关文章