logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Hook into the RollingFileManager#write / Get notice about written bytes
Date Sun, 13 Mar 2016 00:41:39 GMT
Christian, would a JMX interface to this information suit your needs?
Currently the AppenderAdminMBean does not provide much (if any) statistics
on what was processed. This was partly deliberately because I did not want
to build functionality when there's no real need for them and then later
find that this functionality gets in the way. Now that there is a need we
can start adding methods for getting statistics.

If all you need to know is how many bytes were written, we could add some
counters (number of events processed, number of bytes written) to
AppenderAdminMBean. Your code would look something like this:

String name = String.format(AppenderAdminMBean.PATTERN, loggerContextName,
appenderName);
ObjectName objectName = new ObjectName(name);
MBeanServerConnection connection =
ManagementFactory.getPlatformMBeanServer();
AppenderAdminMBean appender = JMX.newMBeanProxy(connection, objectName,
AppenderAdminMBean.class, false);

// now query the appender MBean to get the information you need
appender.getNumberOfBytesWritten(); // this method does not exist yet


If there are other reasons for overriding RollingFileManager, can you let
us know what these are?

Remko


On Thu, Mar 10, 2016 at 5:07 AM, Matt Sicker <boards@gmail.com> wrote:

> Could be something neat to implement in JMX if it's monitoring he wants.
>
> On 9 March 2016 at 11:51, Paul Benedict <pbenedict@apache.org> wrote:
>
> > Maybe... I think the user is not looking for a call back, per se, but
> that
> > was his initial solution for finding out statistics. Perhaps what he
> really
> > wants is a way to examine the throughput of log4j?
> >
> > Cheers,
> > Paul
> >
> > On Wed, Mar 9, 2016 at 11:46 AM, Gary Gregory <garydgregory@gmail.com>
> > wrote:
> >
> > > Maybe we need some (async?) notification where a call site could
> > registered
> > > a listener of some kind...
> > >
> > > Gary
> > >
> > > On Wed, Mar 9, 2016 at 9:37 AM, Matt Sicker <boards@gmail.com> wrote:
> > >
> > > > Appenders are usually final because the appender itself doesn't do
> much
> > > > work (the managers do that), or at least that's what I gather.
> > > >
> > > > On 16 February 2016 at 10:31, <christian@myvm.de> wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > this is the first time I'm writing to a mailing list - I hope I
> will
> > do
> > > > > it the right way :)
> > > > >
> > > > >
> > > > > I migrated a few days ago from Log4J 1.2 to Log4J 2: In general I
> > must
> > > > > say: nice work guys and nice plugin system!
> > > > >
> > > > > But: I'm struggling with finding a way to get notice about the
> exact
> > > > > size of written bytes. I want to find a way how to do some stuff
> > when X
> > > > > bytes were written in Y seconds. I couldn't use a filter and check
> > the
> > > > > LogEvent because it's not possible to get the actual size of
> written
> > > > > bytes afterwards (because the layout will transform this...)
> > > > >
> > > > > I'm using a RollingFileAppender and could see, that this is using
> the
> > > > > RollingFileManager and the perfect way would be to hook into this
> > > > > write(byte[]) method.. but I can't find how to do this.
> > > > >
> > > > > In general I would create a subclass and overwrite write(byte[])..
> > but
> > > > > this is impossible because everything there is final. All
> appenders,
> > > all
> > > > > appender managers, all layouts, ... and I think it's not the way
it
> > > > > should be when I create a new "MyRollingFileAppender" and copy all
> > the
> > > > > stuff and add the part I need to the write method.
> > > > >
> > > > >
> > > > > So is there anybody who could maybe help and know a solution for
> this
> > > > > problem? And is there a specific reason that everything is final?
> :(
> > > > >
> > > > >
> > > > >
> > > > > Thank you in advance and best regards,
> > > > >
> > > > > Christian
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > > > For additional commands, e-mail:
> log4j-user-help@logging.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Matt Sicker <boards@gmail.com>
> > > >
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
>
>
>
> --
> Matt Sicker <boards@gmail.com>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message