[英]Extend Log4JLogger and invoke subclass during runtime
I currently am using the SocketAppender
in Log4J and have run into some issues with passing data over to a remote host, specifically around losing LocationInfo
(class name, line number, etc).我目前在 Log4J 中使用
SocketAppender
,在将数据传递到远程主机时遇到了一些问题,特别是在丢失LocationInfo
(类名、行号等)方面。 What I have done is the following:我所做的如下:
import org.apache.commons.logging.impl.Log4JLogger;
public class MyLogger extends Log4JLogger
{
...
public void debug(Object message)
{
String extra = "Extra!";
super.debug(message + extra);
}
...
}
At runtime how can I change the following code to grab MyLogger
instead of Log4JLogger
?在运行时如何更改以下代码以获取
MyLogger
而不是Log4JLogger
?
private static Log logger = LogFactory.getLog(Test.class);
You don't have to extends Logger but implement your own Appender or extend the base Log4J Appender you need.您不必扩展 Logger,但可以实现自己的 Appender 或扩展您需要的基础 Log4J Appender。 For example you can extend AppenderSkeleton .
例如,您可以扩展AppenderSkeleton 。
I cannot imagine exactly why do you need it.我无法想象你为什么需要它。 Another possibility could be use Log4J Mapped Diagnostic Context .
另一种可能性是使用 Log4J Mapped Diagnostic Context 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.