logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dale King" <dalewk...@gmail.com>
Subject Re: Individual logging output of multiple objects to multiple files
Date Thu, 08 May 2008 14:47:56 GMT
You can certainly do it, but I wouldn't recommend it. You would create
creating a new Logger instance for each instance and attaching to it a
file appender unique to each instance. The overhead of object creation
will be nothing compared to the overhead of creating 10000 files!

The question is why do you think you want to create 10000 files as
output. It would be a much better idea to log it all into one file and
then process the log file to see the log for individual instances by
differentiating the log events per instance.

The easiest way to differentiate the logging events is creating a
logger per instance. Diagnostic context (MDC or NDC) can do this as
well, but is really thread centric so probably does not apply here
unless your simulation is such that object lifetimes do not overlap.

If you just need to view them one at a time consider saving a log with
XML Layout and using Chainsaw on the log to focus on individual
loggers. If you really want 10000 files then it would be fairly simple
to postprocess the log and create them.


On Thu, May 8, 2008 at 8:12 AM, Michael Duerr <duerrm@gmail.com> wrote:
> Hallo,
>
> I'm writing a simulation application, that creates and destroys several
> objects
> of the same class during the simulation. I want to perform logging for each
> of
> these objects to a single file (i.e. I want only the output of one object in
> the
> corresponding object's logging file). The application is single threaded.
>
> Can I achieve this behaviour with log4cxx - if so - how? I tried to
> implement
> this behaviour by initializing a new logger for each new object. But since
> there
> are up to 10000 objects this seems to be inefficient. Furthermore I could
> not
> figure out how to delete such a logger in case the associated object gets
> destroyed (how todo this???) and hence I experienced a lot of memory leaks.
> To
> my best knowledge MDC is also no alternative, since it does not allow for
> the
> restricted object->file logging.
>
> Is there any chance to achieve this logging behaviour with log4cxx?
>
> Thank you!
>
> Cheers Michael
>



-- 
Dale King

Mime
View raw message