= Log4j wiki migrated to a [http://wiki.apache.org/logging-log4j/Log4JProjectPages new home]. This page is no longer updated! =
Log4J - AsyncAppender - posted by marc.oesch@gmx.net Additional/optional parameter which defines a time (in seconds) to pause after subsequent waves of logEvents are released to the Appenders (and if not yet available specifiy the size of the circular buffer). In combination with an SMTPAppender this avoids to have mail flooding. Events can be grouped in mail messages. In my opinion only very small changes need to be done to the AsyncAppender like for ex.: Run method in inner class Dispatcher
public void run() {
{{{ //Category cat = Category.getInstance(Dispatcher.class.getName());
LoggingEvent event; }}}
>> long lastCycle = 0L;
while(true) {
synchronized(bf) { - if(bf.length() == 0) {
- // Exit loop if interrupted but only if the the buffer is empty. if(interrupted) {
- //cat.info("Exiting."); break;
- //LogLog.debug("Waiting for new event to dispatch."); bf.wait();
- // Exit loop if interrupted but only if the the buffer is empty. if(interrupted) {
{{{ // wait at least a given amount of time: waitMin. Interesting
- // if the appender are mail or messaging appenders // waitMin optional by configuration settings or 0 // would be usefull to test if buffer is full before waiting more time }}}
>> if((System.currentTimeMillis() - lastCycle)/1000 < waitMin) >> bf.wait(waitMin*1000 -(System.currentTimeMillis()-lastCycle);
} catch(InterruptedException e) {
LogLog.error("The dispathcer should not be interrupted."); break;
- }
...more lines
if(aai != null && event != null) {
- aai.appendLoopOnAppenders(event);
} >> lastCycle = System.currentTimeMillis(); } // while
Log4J - Requested Features
- Add an attribute to all appenders that specifies whether the stacktrace should be excluded in the log message.
- Add the customized filtering ability to the '.properties' config file (since today it exists only for the XML config file).
- Add the ability to truncate an attribute from its right side. Say we want to truncate the priority (have only the first left-most character). Non of the following meets our request: %1p / %-1p / %.1p / %-.1p / %-1.1p
- Add localization support. HERE HERE!
- Document log4j's support/behavior when used from multiple JVMs.
DailyRollingFileAppender should have an optinal parametr to limit the maximun number of rotated files ( i.e. MaxBackupIndex )
DailyRollingFileAppender should be able to put the datepattern as any part of the name, preferably by just using a date-pattern inside the File-property.
- Both (all) rolling appenders should be able to put rolled files in another directory.
Assign LogLevels to Appender rather than Logger. So it could be possible to log TRACES, DEBUG to console only, while other logs (WARNINGS and above) go to a file. The method Logger.isEnabled(LogLevel) (or similar, don't remember the correct call) would subsequently ask all appenders.
Add a pattern layout element that logs the hostname that the application is running on. YES! I agree! (Possibly using java.net.InetAddress.getLocalHost().getHostName(), or something similar) It's especially needed if you want multiple servers to log to a single place.
- Add a pattern layout element that logs the username of the person who is logged into the application at the time of the logging event.
- Add a pattern layout element that logs the exception as a stack trace.
- Document JMX Supportx
Add a method to AsyncAppender that waits until the buffer is empty... like close method but without closing the appender.
- Delete loggers that are removed from the property file, if log4j is initialized using configureAndWatch
Create directory for FileAppender if it doesn't already exist: So, if we configure a file appender like so: lo4j.appender.myFileAppender.File=${user.home}/.MYAPP/myapp.log and the directory ${user.home}/.MYAPP doesn't exist, create it.
Name the threads that Log4J creates. Simple request, but useful info. new Thread(runnable, "Log4j Socket Appender") or something... SimpleSocketServer, SocketHubAppender, SocketHubReceiver, SocketReceiver, SocketServer, XMLSocketReceiver
LogFactor 5 - Requested Features
- Allow Log Factor 5 to read log files based on the customer pattern for that file, instead of the logfile having to follow Log Factor 5's format.
LogFactor 5 could read logfiles from disk, now it must read it "online".
Allow LogFactor 5 / Chainsaw to display log messages from a JMS queue.
Add Filtering to LogFactor 5. Would like to see filters for Date, Level, NDC, Thread, etc.
Log4J - Requested Features
- Remove synchronization on the Logger object while doing an append. Have the appender list inside a Logger be redone as a copy-on-write array rather than as a Vector.
Remove synchronization on the Appender when rendering an Object as a String. These will fix my reoccuring deadlock problems: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24159
- Add basic support for localization. Idea:
static LogText lt = LogText.getLogText("com.example.app.MyApp");
Or
{{{ static LogText lt = LogText.getLogText(MyApp.class);
Have LogText hold a reference to a ResourceBundle called "MyApp.LogMessage.properties" in the com/example/app directory. }}}
Example contents:
{{{ # MyApp.properties
- msg1 = Hello, {0} msg2 = Goodbye {0} and {1}! }}}
Example usage:
{{{ String name = "George";
- String name2 = "Larry"; log.debug(lt.get("msg1", name)); log.debug(lt.get("msg2", name, name2)); }}}
Example output:
{{{ Hello, George
- Goodbye George and Larry! }}}
Class signature:
{{{ public class LogText {
public static LogText getLogText(Class class); public static LogText getLogText(String class); public Message get(String key); public Message get(String key, Object v1); public Message get(String key, Object v1, Object v2); public Message get(String key, Object v[]); public class Message {
- private String text; private Object v[]; public String toString() {
- // Might want to cache toString result here
return java.text.MessageFormat.format(text, p);
- // Might want to cache toString result here
- private String text; private Object v[]; public String toString() {
- } }}}
Benefits:
We don't generate a String object until the object is rendered, saving StringBuffer objects and lots of copying. For example:
{{{ if (log.isDebugEnabled())
- log.debug("Using " + bar + " to do " + foo); }}}
Can be written instead as log.debug(lt.get("using", bar, foo));
- Localizable.