java Jaxrs web app无法使用Apache commons+UTIL登录到外部文件。登录中
我有一个简单的Jaxrs服务,我想在其中将日志写入外部文件。虽然日志是在服务器控制台中打印的,但它们不会打印到我指定的外部日志文件中。以下是我遵循的配置
在src/main/resources中,我有两个名为commons logging的文件。属性和日志配置。我在pom中配置的属性。xml将它们复制到目标/类
公共日志记录。配置之后的属性
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger
和日志配置。属性包含以下内容
# The following creates two handlers
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Set the default logging level for the root logger
.level=SEVERE
# log level for the "com.example" package
sample.logging.level=FINE
# Set the default logging level
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.FileHandler.level=FINE
# Set the default formatter
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
# Specify the location and name of the log file
java.util.logging.FileHandler.pattern={path to my log file}
Jaxrs服务类具有以下特性
package org.test.testproject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.ws.rs.*;
import java.util.logging.Logger;
@Path("/")
public class TestService {
//private static final Logger customLog = Logger.getLogger(TestService.class.getName());
private static final Log wso2Log = LogFactory.getLog(TestService.class);
private static Logger customLog = Logger.getLogger(TestService.class.getName());
@GET
@Path("/customers/{id}/")
public void getCustomer(@PathParam("id") String id) {
customLog.info("get customer information Custom logging for " + id);
wso2Log.info("----invoking getCustomer, Customer id is: " + id);
}
}
它正在编译,我可以检索。战争档案。部署后,它只显示服务器控制台中的日志。我有什么遗漏吗。任何帮助都将不胜感激
共 (0) 个答案