Log4J experts?

9 views
Skip to first unread message

Amit_Agwal

unread,
Nov 18, 2009, 1:11:20 PM11/18/09
to Bangalore Open Java Users Group- BOJUG
Hi,
Can someone help me out here.

My requirement is to set up a call back mechanism from the Log4J
framework into my application when the last log file is about to be
created. I basically want to notify that the logs are nearing full via
an email when the last file is just being written.
Is this possible to achieve in the Log4J framework? How would I
approach this.

Amit

Raghavan.30May1981_GMail

unread,
Nov 20, 2009, 4:27:13 AM11/20/09
to bo...@googlegroups.com
I don't think so whether there is an inbuilt mechanism for this. However the other plausible alternatives would be

1. Write a 'cron' job for monitoring the log file size and then send an email appropriately
2. Write a Quartz Job for monitoring and triggering a mailing component (which could be on JavaMail API) to send an email.

1st method works only in case the application server running in *nix box (Unix/Linux flavors).

Cheers,
Raghavan alias Saravanan M.
http://groups.google.com/group/S_H_a_D_E

"Life's harsh truth is that people come when in need that is not 'ours' but 'theirs'." - Wisemen




--

You received this message because you are subscribed to the Google Groups "Bangalore Open Java Users Group- BOJUG" group.
To post to this group, send email to bo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bojug?hl=.



Scorpion

unread,
Nov 23, 2009, 9:06:37 AM11/23/09
to bo...@googlegroups.com
Yes, you can.  Instead of using log4j.xml or log4j.properties,
if you write your own classes which will extend the features of log4j.  
or There is one RollingFileappender which will create every day one log file based on the filename pattern.
In this you can define what is the maximum size of the file for the logfile.

below the basic configuration for rollingfileappender

<appender class="RollingFileAppender" name="appender-name">
<param name="Append" value="TRUE | FALSE"/>
<param name="Encoding" value="encoding-value"/>
<param name="File" value="path-and-filename"/>
<param name="ImmediateFlush" value="TRUE | FALSE"/>
<param name="Locale" value="locale"/>
<param name="Threshold" value="TRACE | DEBUG | INFO | WARN | ERROR | FATAL"/>
<param name="Unique" value=""TRUE | FALSE"/>
<filter>
<filter-definitions>
</filter>
<layout>
<param name="ConversionPattern" value="conversion-pattern"/>
</layout>
<rollingPolicy class="FixedWindowRollingPolicy | TimeBasedRollingPolicy">
<rollingPolicy-parameters>
</rollingPolicy>
<triggeringPolicy class="SizeBasedTriggeringPolicy | FilterBasedTriggeringPolicy">
<triggeringPolicy-parameters>
</triggeringPolicy>
  </appender>


To unsubscribe from this group, send email to bojug+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/bojug?hl=.



--
Thanks & Regards,

Sakthivel Thangasamy,
+91 - 9901969798


Excellence is a drive from inside, not outside.

Scorpion

unread,
Nov 23, 2009, 9:08:31 AM11/23/09
to bo...@googlegroups.com
Check the file configuration we are using 

<appender name="FILE"
class="org.apache.log4j.DailyRollingFileAppender">
<param name="Append" value="true" />
<param name="File" value="D:/my_projects/error.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{dd MMM yyyy HH:mm:ss}] [%p] [%C{1} - %M:%L] - %m%n" />
</layout>
</appender>

this will create one log file every day based on the server system date

Ketan Padegaonkar

unread,
Nov 23, 2009, 11:37:09 PM11/23/09
to bo...@googlegroups.com
You could consider writing your own appender that extends from log4j's
RollingFileAppender to send out notifications.

--
Ketan
studios.thoughtworks.com | twitter.com/ketanpkr

On Wed, Nov 18, 2009 at 11:41 PM, Amit_Agwal <ami...@gmail.com> wrote:

Scorpion

unread,
Nov 24, 2009, 12:20:48 AM11/24/09
to bo...@googlegroups.com
Yes, thats what am telling, write your own custom classes which extends log4j features

To unsubscribe from this group, send email to bojug+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bojug?hl=en.


Reply all
Reply to author
Forward
0 new messages