Jochen Wiedmann | 25 Jun 08:28 2016

Different Processes, same Logfile


is it possible. that multiple proceses share a common log file. (The
processes aree command line executables, ,which will be started at
unpredictable times.




The next time you hear: "Don't reinvent the wheel!"
Maple Wang | 24 Jun 12:25 2016

how to ensure my hook is invoked before shutdown hook of log4j


I registered a shutdownhook in my code and found that there is no any log output from my hook method, the
reason is that since log4j2.1, shutdown hook registry will be enabled by default from log4j, logger is
stopped by log4j's hook before my hook is invoked.

Of course I can disable the hook from log4j by "-Dlog4j.shutdownHookEnabled=false", but I think it might
be better to keep it, so I wonder if there is way to ensure my hook is invoked before log4j's hook.

And if there is no that way, is there any programmatic way to disable the log4j's shutdownhook rather than
JVM parameter.

Thanks in advance.

Best regards.
Matt Sicker | 20 Jun 15:57 2016

How exactly are you supposed to use CloseableThreadContext?

I tried doing it like in the javadocs and get a compilation error:

 <at> Test
public void name() throws Exception {
try (CloseableThreadContext.put("key", "value")) {

List of errors: error: <identifier> expected
                try (CloseableThreadContext.put("key", "value")) {
                                               ^ error: ')' expected
                try (CloseableThreadContext.put("key", "value")) {
                                                ^ error: '{' expected
                try (CloseableThreadContext.put("key", "value")) {
                                                     ^ error: not a statement
                try (CloseableThreadContext.put("key", "value")) {
                                                       ^ error: ';' expected
                try (CloseableThreadContext.put("key", "value")) {
                                                              ^ error: reached end of file while parsing

Am I doing something wrong here?
(Continue reading)

Remko Popma | 20 Jun 06:10 2016

Re: OnStartupTriggeringPolicy/custom header

Yes please create a Jira. We need it for our change log anyway. (And I find that email quickly drops below the horizon...)

Sent from my iPhone

> On 2016/06/20, at 12:30, Leon Finker <leonfin <at>> wrote:
> Yes i can confirm each reconfigure causes the rollover, which is not good
> for us. Should I create jira? Thank you
>> On Jun 15, 2016 12:25 PM, "Ralph Goers" <ralph.goers <at>> wrote:
>> I can add an option to the OnStartupTriggeringPolicy to only roll if the
>> file meets or exceeds a minimum value. The default would be 1 byte.
>> Also, I believe I introduced another bug.  The file is now going to roll
>> every time a reconfiguration takes place, which is obviously incorrect. I
>> need to fix that asap.
>> The PatternLayout does not support interpolation of the header and footer
>> but the Configuration does. All attributes are interpolated as the
>> configuration is read.  You could create your own custom Lookup to get the
>> processId, but that may be something we should add to the standard set of
>> properties.
>> Actually, the triggering policy could write to the file since it has
>> access to the Manager.
>> Ralph
(Continue reading)

流子℡ | 19 Jun 17:09 2016

Question about how to create new log files on an hourly not depend on new byte stream log appended

here is my log config as follows:

name="LingyuLog"			fileName="game"			filePattern="game.%d{yyyy-MM-dd-HH}.log">			<PatternLayout
pattern="%msg%n" />			<Policies>				<TimeBasedTriggeringPolicy interval="1" modulate="true" />			</Policies>		</RollingRandomAccessFile>

As we know,for instance,now is 22:55 pm,the active file  named 'game' is printed continuously,
at 23:00 pm ,the first byte stream out will trigger the file named 'game' rename to
game.2016-06-19-22.log,and print the byte stream to the new file named 'game'. if no other byte stream in 
the next one hour, the behavior will not be triggered.
it will lead to that the log will be batch inserted into mysql db delay if we only pick up the file having suffix '.log'.
because the content still remain in file  named 'game' not be suffix '.log'.

my question is  how to create new log files on an hourly not depend on new byte stream log appended.

Anthony Maire | 17 Jun 15:11 2016

Question about several Async Loggers + RandomAccessFIle appenders with immediateFlush = false


As suggested in AsyncLogger javadoc, I made some performance tests on my
application with (Rolling)RandomAccessFile appenders configured with
immediateFlush = false to take advantage of the potential I/O batching, and
the results are very good :)

However I have a question about the flush on end of batch mechanism when
there are several appenders to flush.

*Case one:*

- AsyncLogger L1 has very few messages to log (let's say its a logger which
logs only when a request fails) and has its dedicated RAF appender A1.
- AsyncLogger L2 is very active (let's say its a logger which logs every
request that enters the system), and has its dedicated RAF appender A2

As far as I understand the code, both loggers use the same disruptor
instance. Let's assume that at some time, an event E1 is submitted to the
disruptor by L1, but the background thread doesn't wake up immediately and
another event E2 is submitted by L2, so both events will be part of the
same batch when the background thread wakes up

I'm afraid that the following will happen :
- A1 encode E1 in its buffer, but does not write to the RAF since
event.isEndOfBatch() == false
- Background thread now process E2, it will be encoded in A2 buffer, and
since E2 is a end of batch event, A2 is flushed
However A1 is not flushed and will never be until another event is logged
to it.
(Continue reading)

Jochen Wiedmann | 17 Jun 10:41 2016

Multiple instances of log4j2.xml


I have an application (more precisely: a war file), which is deployed
identically on the same application server. (Think multi temancy),
Now, in Log4j 1, I handled that situation quite easily, like this:

    final String uri = tenantName + "/log4j.xml";
    final URL url = ClassLoader.getResource(uri);
    if (uri == null) {
        throw new IllegalStateException("Unable to locate logging
configuration: " + uri);

Or, in other words: For every tenant, I have a directory for
configuration files, including log4j.xml.
Simple, quick, and worked absolutely reliable.

But, how do I get this to work with log4j2?




The next time you hear: "Don't reinvent the wheel!"
Rubén Pérez | 15 Jun 20:08 2016

log4j2 archive every week, rotate every startup?


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?

Thanks a lot!
Leon Finker | 15 Jun 17:17 2016

OnStartupTriggeringPolicy/custom header


What would be the best way to implement the following:
1. Always roll log file once on JVM startup (and only on JVM startup).  - This could be done with implementing
another OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files anymore).
2. Log an entry in the new log file (after the roll) with something like:
Constants.LINE_SEPARATOR + "---------- " + + " STARTING " + service_instance_Name + " " +
getProcessId() + " ----------"
- Does PatternLayout's header support system property lookup variables (i.e.: service instance name and
date time now)?
- Not sure how to allow for custom method call to get the getProcessId() into the header
- It could've been easy if I could do it from OnStartupTriggeringPolicy, but there is no way to write to the
new rolled log file from there.

Is there a way?

Thank you
Debraj Manna | 15 Jun 15:04 2016

Override during testing

I want to log only the ERROR during testing in maven. For this purpose I
created a file src/test/resources/, which is going to
override the configuration I already have in
src/main/resources/ But this is not working. My looks like below:-

log4j.rootLogger=ERROR, out, stdout
# CONSOLE appender
| %-5.5p | %-16.16t | %-32.32c{1} | %X{} - %X{} -
%X{bundle.version} | %X |
# File appender
| %-5.5p | %-16.16t | %-32.32c{1} | %X{} - %X{} -
%X{bundle.version} | %X | %m%n

My pom.xml looks like below:-

<project xmlns=""
(Continue reading)

Matt Sicker | 13 Jun 20:24 2016

Question about async logger wait strategies

The code has a case for the busy spin strategy, but it's not listed on this
page: <>. Is this
unsupported or should it be added to the docs?


Matt Sicker <boards <at>>