-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ceki Gulcu <[email protected]>
- Loading branch information
Showing
10 changed files
with
490 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.apache.log4j.varia; | ||
|
||
import org.apache.log4j.helpers.LogLog; | ||
|
||
public class InterruptUtil { | ||
final boolean previouslyInterrupted; | ||
|
||
public InterruptUtil() { | ||
super(); | ||
previouslyInterrupted = Thread.currentThread().isInterrupted(); | ||
} | ||
|
||
public void maskInterruptFlag() { | ||
if (previouslyInterrupted) { | ||
Thread.interrupted(); | ||
} | ||
} | ||
|
||
public void unmaskInterruptFlag() { | ||
if (previouslyInterrupted) { | ||
try { | ||
Thread.currentThread().interrupt(); | ||
} catch (SecurityException se) { | ||
LogLog.error("Failed to interrupt current thread", se); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<log4j:configuration debug="true" | ||
xmlns:log4j='http://jakarta.apache.org/log4j/'> | ||
|
||
|
||
<appender name="V1" class="org.apache.log4j.VectorAppender"/> | ||
|
||
<appender name="ASYNC" class="org.apache.log4j.NewAsyncAppender"> | ||
<param name="QueueSize" value="500"/> <!-- Buffer size for events --> | ||
<appender-ref ref="V1"/> | ||
</appender> | ||
|
||
<root> | ||
<level value="trace" /> | ||
<appender-ref ref="ASYNC" /> | ||
</root> | ||
|
||
</log4j:configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/org/apache/log4j/BlockableVectorAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.apache.log4j; | ||
|
||
import org.apache.log4j.spi.LoggingEvent; | ||
|
||
/** | ||
* Vector appender that can be explicitly blocked. | ||
*/ | ||
final class BlockableVectorAppender extends VectorAppender { | ||
/** | ||
* Monitor object used to block appender. | ||
*/ | ||
private final Object monitor = new Object(); | ||
|
||
/** | ||
* Create new instance. | ||
*/ | ||
public BlockableVectorAppender() { | ||
super(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void append(final LoggingEvent event) { | ||
synchronized (monitor) { | ||
super.append(event); | ||
// | ||
// if fatal, echo messages for testLoggingInDispatcher | ||
// | ||
if (event.getLevel() == Level.FATAL) { | ||
Logger logger = Logger.getLogger(event.getLoggerName()); | ||
logger.error(event.getMessage().toString()); | ||
logger.warn(event.getMessage().toString()); | ||
logger.info(event.getMessage().toString()); | ||
logger.debug(event.getMessage().toString()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get monitor object. | ||
* | ||
* @return monitor. | ||
*/ | ||
public Object getMonitor() { | ||
return monitor; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.apache.log4j; | ||
|
||
/** | ||
* Logging request runnable. | ||
*/ | ||
final class Greeter implements Runnable { | ||
/** | ||
* Logger. | ||
*/ | ||
private final Logger logger; | ||
|
||
/** | ||
* Repetitions. | ||
*/ | ||
private final int repetitions; | ||
|
||
/** | ||
* Create new instance. | ||
* | ||
* @param logger logger, may not be null. | ||
* @param repetitions repetitions. | ||
*/ | ||
public Greeter(final Logger logger, final int repetitions) { | ||
if (logger == null) { | ||
throw new IllegalArgumentException("logger"); | ||
} | ||
|
||
this.logger = logger; | ||
this.repetitions = repetitions; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void run() { | ||
try { | ||
for (int i = 0; i < repetitions; i++) { | ||
logger.info("Hello, World"); | ||
Thread.sleep(1); | ||
} | ||
} catch (InterruptedException ex) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} |
Oops, something went wrong.