log4j

log4j:WARN Unrecognized element rollingPolicy

本小妞迷上赌 提交于 2019-12-07 11:13:00
问题 I had this warning in log when my application was starting log4j:WARN Unrecognized element rollingPolicy tried to Google for answers, but adding apache-log4j-extras-1.1.jar didn't helped me. I'm using slf4j-log4j12 1.7.2 with log4j 1.2.17 . 回答1: Instead of rollingPolicy I used DailyRollingFileAppender and no extras jar is needed. <appender name="rollingLog" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="${catalina.home}/logs/rolling.log" /> <param name="append"

Which log4j facade to choose?

China☆狼群 提交于 2019-12-07 11:09:14
问题 Essentially I'm looking for something with the same behavior, configuration, logging levels as log4j, but with some of the missing functionality (e.g. formatted logging — see here and here for related SO threads.) Current nominees are slf4j and log5j. 回答1: I'm inclined toward SLF4J. allows parameterized logging (formatting) allows consolidation of other frameworks (great for apps using many libraries, each logging to a different framework) log5j is good, but does not have near as much market

Is SLF4J good to be used in a multithreaded application for logging to a database?

强颜欢笑 提交于 2019-12-07 10:29:23
问题 I am working on a multithreaded application. I am already using Log4j to log statements to files. I have been recently looking into the possibility of logging to a Mysql database. The logging component has to be reliable under a heavy load and has to be thread safe. I heard of SFL4J. My understanding of SLF4J is that is just a facade or abstraction layer. I was wondering if SLF4J was a good database logging solution to use in a multithreaded application? And in the case of a heavy load, would

Under Spring Framework: WARN: WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader)

邮差的信 提交于 2019-12-07 10:25:05
问题 I have spent all day trying to solve the logging problem I'm having with log4j in a webapp. No matter what I do, I cannot get rid of the following: log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Just to be clear, I have read all of the articles here on Stack Overflow addressing this issue. I've read the

Is there an easy way to create a logger instance for every class?

瘦欲@ 提交于 2019-12-07 09:51:24
问题 I am now using static method to log (because I find it very easy to log in Android), but now I need to configure different appenders for different classes, so I have a problem with static logging method. And I read Log4J: Strategies for creating Logger instances, I notice it is time for me to change the logging strategy, so I will need the following code to my class which needs a special logger. private static final Logger logger = Logger.getLogger(XXXX.class); I feel since this is repeated

Appending current time to a new log file each time log4j is initialized

自闭症网瘾萝莉.ら 提交于 2019-12-07 08:44:43
问题 Every single time I run my app, I want a new log file to be generated with the time stamp. Something like MyFile-4Nov2010-132122.log . I've seen the use of the DailyRollingFileAppender however I want it to roll each and every time as opposed to just daily. 回答1: Subclass FileAppender or DailyRollingFileAppender to create a new file when the appender is instantiated. 回答2: You can also configure the XML config file as below: <appender name="file" class="org.apache.log4j.DailyRollingFileAppender"

Hiding or Encrypting Password in log4j.properties file SMTP Appender

青春壹個敷衍的年華 提交于 2019-12-07 08:32:26
问题 I am using custom gmail smtp appendar for sending error logs from my gmail account. Following the instructions: http://www.tgerm.com/2010/05/log4j-smtpappender-gmail-custom.html - Everything works great. Except one thing: In my log4j.properties: I don't want to type my password "log4j.appender.EMAIL.SMTPPassword=somepass" so that I can share this project with my team mates. Does anyone have a suggestion ? Below is log4j.properties part: log4j.appender.EMAIL=com.tgerm.log4j.appender

How to include multiple log4j2.xml files in a project?

一笑奈何 提交于 2019-12-07 08:25:32
问题 My Project is composed of multiple modules. Each module can run on its own and have a separate log4j2.xml Say Project X is composed of three modules: Module A has log4j2.xml (contains Loggers and Appenders) Module B has log4j2.xml Module C has log4j2.xml While integrating the modules, I have to manually copy-paste the Loggers and Appenders from each module's log4j2.xml into the project specific log4j2.xml file. To avoid copy-paste, I've looked for XInclude to include multiple files but it

ThreadLocal与InheritableThreadLocal区别

廉价感情. 提交于 2019-12-07 08:17:58
最近项目中为了让打印的日志可以追踪,看到了Logback和log4j2支持的MDC功能,其内部利用了子线程从父线程继承InheritableThreadLocal类型变量的特性。以前只使用到了ThreadLocal,在这里做一下对比,并简单的做了一些分析 ThreadLocal与InheritableThreadLocal区别 ThreadLocal声明的变量是线程私有的成员变量,每个线程都有该变量的副本,线程对变量的修改对其他线程不可见 InheritableThreadLocal声明的变量同样是线程私有的,但是子线程可以使用同样的InheritableThreadLocal类型变量从父线程继承InheritableThreadLocal声明的变量,父线程无法拿到其子线程的。即使可以继承,但是子线程对变量的修改对父线程也是不可见的。 原理 ThreadLocal原理: Thread有一个类型为ThreadLocal.ThreadLocalMap变量:threadLocals,ThreadLocalMap底层是一个Entry数组,用于保存ThreadLocal引用和真正变量(程序中销售人的主管姓名)的值 看下面的代码和注释了解如何将值放入threadLocals的 调用ThreadLocal对象的set()方法 public void set(T value) { /

switch from log4j to logback

拟墨画扇 提交于 2019-12-07 06:43:00
问题 I have this code with log4j, I don't use any kind of configuration files static Logger logger = Logger.getLogger(Application.class); ... Appender ap = new NTEventLogAppender(); SimpleLayout layout = new SimpleLayout(); Appender fp = null; try { fp = new FileAppender(layout, "output.txt"); } catch (IOException e) { e.printStackTrace(); } logger.addAppender(ap); logger.addAppender(fp); logger.info("info"); can anybody show me how can I do the same thing with logback 回答1: Why is it that you don