-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contributions coming from SourceForge. http://wonder.svn.sourceforge.net/wonder/?rev=12080&view=rev
- Loading branch information
Pascal Robert
committed
May 21, 2012
1 parent
71f46ad
commit 6aa52e2
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Frameworks/Core/ERExtensions/Sources/er/extensions/logging/ERXThreadStorageAppender.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,55 @@ | ||
/* | ||
* Copyright (C) NetStruxr, Inc. All rights reserved. | ||
* | ||
* This software is published under the terms of the NetStruxr | ||
* Public Software License version 0.5, a copy of which has been | ||
* included with this distribution in the LICENSE.NPL file. */ | ||
package er.extensions.logging; | ||
|
||
import org.apache.log4j.AppenderSkeleton; | ||
import org.apache.log4j.spi.LoggingEvent; | ||
|
||
import er.extensions.appserver.ERXSession; | ||
import er.extensions.foundation.ERXThreadStorage; | ||
|
||
/** | ||
* Appends all logging in this thread to thread storage if ERXSession.session() | ||
* is set. In case of an exception (or whenever you want to), you can call | ||
* <code>ERXThreadStorageAppender.messages()</code> to get the full log. <br> | ||
* This is useful because you don't clutter up your log with stuff you don't | ||
* really need most of the time, but still get full logging in case something | ||
* bad happens. | ||
* | ||
* @author ak | ||
*/ | ||
|
||
public class ERXThreadStorageAppender extends AppenderSkeleton { | ||
|
||
public void append(LoggingEvent event) { | ||
if (ERXSession.session() != null) { | ||
StringBuffer buf = buffer(); | ||
//buf.append(getLayout().format(event)); | ||
} | ||
} | ||
|
||
protected static StringBuffer buffer() { | ||
StringBuffer buf = (StringBuffer) ERXThreadStorage.valueForKey("ERXThreadStorageAppender.buffer"); | ||
if(buf == null) { | ||
buf = new StringBuffer(); | ||
ERXThreadStorage.takeValueForKey(buf, "ERXThreadStorageAppender.buffer"); | ||
} | ||
return buf; | ||
} | ||
|
||
public void close() { | ||
// nothing | ||
} | ||
|
||
public static String message() { | ||
return buffer().toString(); | ||
} | ||
|
||
public boolean requiresLayout() { | ||
return true; | ||
} | ||
} |