java为什么我的日志文件没有在本地资源管理器中创建?
我只想记录我在运行时得到的异常。我有一个应用程序记录器。类,应用程序。属性,log4j2。属性文件。当然还有主课。有人能帮我创建一个日志文件吗
App_记录器。阶级
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() + "] ";
}
}
应用程序。属性文件
log4j2.debug=true
初始化应用程序。阶级
@SpringBootApplication
@CrossOrigin("http://localhost:3000")
public class InitApplication implements CommandLineRunner{
public static void main(String[] args) {
SpringApplication.run(InitApplication.class, args);
}
}
# 1 楼答案
这只是pom中的一个错误。xml文件
早些时候是这样的
然后我添加了这些行,基本上,我排除了Spring boot默认启动记录器,并通过添加其依赖项添加了log4j2记录器。 像这样