简体   繁体   English

扩展 Log4JLogger 并在运行时调用子类

[英]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.

相关问题 在Websphere 8.5.01上部署时,Log4JLogger不实现日志 - Log4JLogger does not implement Log when deploying on websphere 8.5.01 是什么原因导致Log4JLogger无法找到或无法使用? - Whats the root cause of Log4JLogger' cannot be found or is not useable? PDFBox 合并命令工具与 Log4JLogger 的问题 - PDFBox merge command tool problem with Log4JLogger 在WildFly中重新部署ESAPI应用程序时,ClassCastException Log4JLogger无法转换为Logger - ClassCastException Log4JLogger cannot be cast to Logger when redeploying ESAPI application in WildFly 选择在运行时从java扩展的子类 - Choose which subclass to extend from at runtime in java Java调用子类和超类 - Java invoke subclass and superclass Sbt test: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger - Sbt test: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger log4j2.xml 在运行时没有选择系统属性的变化? - log4j2.xml is not picking the changes in system properties during the runtime? 使用logback获取运行时最新日志的文件名 - Get file name of the newest log during runtime using logback log4j2:在运行时重新配置记录器的问题 - log4j2 : Problem with reconfiguration of the loggers during runtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM