log4j2

log4j2 archive every week, rotate every startup?

半城伤御伤魂 提交于 2019-12-11 04:27:19
问题 I am trying to figure out how to simply rename the active log file on every startup, and archive all the rotated files once a week. I am forced to specify the "filePattern" at the RollingFile appender declaration, instead of at the policy. Do this make sense? 回答1: I ended up doing my own implementation of a DeleteAction, and attaching it to a DefaultRolloverStrategy, so that it is zipping everything before deleting. You can find the sourcecode at: https://github.com/lqbweb/log4j2-ZipDelete 来源

Setting ThreadContext for all threads in application

时间秒杀一切 提交于 2019-12-11 04:16:49
问题 From this answer https://stackoverflow.com/a/25125159/4367326 I have routingAppender working but I want to set the ThreadContext for every thread in the program. When I set ThreadContext.put("logFileName", "TestLogFile"); it works for the main thread and logs as expected but not for any other threads in my application. How can I achieve this? 回答1: Every child thread will inherit fathers ThreadContext state if you set up system property isThreadContextMapInheritable to true. But this will not

Log4j2 separate log files by module name

我只是一个虾纸丫 提交于 2019-12-11 04:00:19
问题 I want to write log files based on module name. for ex. one log file for user management module and one for products module etc. My project package structure looks like below; com.mycompany.service.user com.mycompany.service.product com.mycompany.controller.user com.mycompany.controller.product ... I want to write log messages from com.mycompany.*.user (com.mycompany.service.user and com.mycompany.controller.user) to com.mycompany.user.log file, and com.mycompany.*.product to com.mycompany

How to configure log4j2 to log for HikariCP

半世苍凉 提交于 2019-12-11 03:33:06
问题 I have written a small Gradle project so that I can learn how to configure HikariCP and JDBC and Log4j2 all together in the same project. I have placed the below log4j2 config in the src/main/resources directory in my project. When I execute the project using gradle run I get a warning about not configuring an appender for the com.zaxxer.hikari.HikariConfig logger. Would some one kindly tell me what i am doing wrong? log4j2.xml <?xml version="1.0" encoding="utf-8"?> <Configuration status=

How to create multiple log file programatically in log4j2?

百般思念 提交于 2019-12-11 02:58:39
问题 I am developing a java application which communicates with lots of devices. For each device I need to create a different log file to log it's communication with device. This is the wrapper class I developed. It creates two log files but the data is written to only the first one. The second file is created but nothing is written to it. The output that should go to second file goes to console. If I uncomment createRootLogger() in constructor nothing is written to both the files, everything goes

log4j migration to log4j2

戏子无情 提交于 2019-12-11 02:45:54
问题 Log4j migration guide https://logging.apache.org/log4j/2.x/manual/migration.html states that Calls to org.apache.log4j.Logger.getLogger that accept a LoggerFactory must remove the org.apache.log4j.spi.LoggerFactory and use one of Log4j 2's other extension mechanisms. What are the extension mechanisms available in log4j2 and how best to migrate a method like below in log4j2 private static TraceLoggerFactory stTraceFactory = new TraceLoggerFactory(); public static Logger getTraceLogger(final

Logging the PID in log4j2 without using thread context

烂漫一生 提交于 2019-12-11 00:59:02
问题 I need to include the PID in my log4js logs. I see many examples which use the thread context. However, these need to be set on each individual thread created. I am constrained against doing this. I need a solution that, either, does not use the thread context, or, can set the PID on all thread contexts, for any thread that may be created, from any arbitrary class. 回答1: Please create a feature request on the Log4j2 issue tracker to make this a built-in feature. For now, you can create a

Understand Ring Buffer in async Logger

為{幸葍}努か 提交于 2019-12-11 00:46:49
问题 In async logger of log4j2 mannual link default value of log4j2.asyncLoggerConfigRingBufferSize is 256 * 1024 What does 256 and 1024 represent here? 回答1: The number of slots in the ringbuffer needs to be a power of 2. This allows you to keep incrementing the counter and use a bitmask instead of modulo to get the array index from the counter. For example, suppose we have a ringbuffer of size 4. Indexes 0 to 3 are valid indexes into the array. We want to avoid checking index++; if (index > 3) {

Log4j2 - Write Logs to Writer

情到浓时终转凉″ 提交于 2019-12-10 23:33:31
问题 In Log4j there was a WriterAppender that made it possible to write the logs to a Writer . I need the same functionality in Log4j2 , but I haven't found an option to do this yet. Does anyone know how to achieve the same with Log4j2 ? 回答1: If there is not an existing appender that serves your needs, create a custom appender plugin. I put together a quick example. package com.logging; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Layout; import org.apache

Logging server classes in Tomcat 6 with log4j2

时光怂恿深爱的人放手 提交于 2019-12-10 22:53:23
问题 I am hoping to use log4j2 to log from both my web applications and the server (tomcat 6) itself, ideally all to the same file. The config I have works fine for the web applications, but not for the server classes. What I want is for lines like the following to be written to a file, (they are currently written to the console only) Aug 15, 2014 1:03:24 PM org.apache.coyote.http11.Http11Protocol start INFO: Starting Coyote HTTP/1.1 on http-80 Aug 15, 2014 1:03:24 PM org.apache.catalina.startup