You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by rovelgoenne <ro...@merentis.com> on 2007/05/14 16:54:30 UTC

DailyRollingFileAppender for multiple threads

I start multiple threads where every thread should log to his own file.
Therefor I did:
- every thread has a number
- for every thread I get a logger with "name" + number
- in every logger I add an DailyRollingFileAppender
- in the thread I log to the connected logger
So everything works fine. Every thread logs to his file.

Code (initialization):
DailyRollingFileAppender fileAppender;
            for ( int i = 0; i < multiplicity; i++ )
            {
                fileAppender = new DailyRollingFileAppender( layout, 
"c:/log/temp" + i + ".log" "'.'yyyy-MM-dd" );              
                Logger logger = Logger.getLogger( "logger" + i );
                logger.addAppender( fileAppender );
            }

There is only a problem in heavy logging in all threads. In this situation
sometimes logging entries (or parts of it) from one thread show up in the
logging file of another thread. 
Has someone an idea about the reason of such an behavour? Is my solution not
suitable for such a problem?
Do I have to use a different appender (because of the amount of logging
entries I have to use something like DailyRollingFileAppender)? 
I searched the hole mailing list for an answer but I didn't found something
about these exact problem.
-- 
View this message in context: http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10605350
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: DailyRollingFileAppender for multiple threads

Posted by rovelgoenne <ro...@merentis.com>.
I read the posts and I tested some options.
Through the tests I found something interesting:
The error I describted only appears on a machine with multiple dual core
processors. On a single processor machine everything works fine with my
first solution.

Does anyone has an idea what is the reason for this?



James Stauffer wrote:
> 
> Starting points:
> http://marc.info/?l=log4j-user&m=116732761011115&w=2
> http://marc.info/?l=log4j-user&m=116056967826476&w=2
> http://marc.info/?l=log4j-user&m=114105274201875&w=2
> 
> It is similar to the problem of one file per user.
> 
> On 5/15/07, rovelgoenne <ro...@merentis.com> wrote:
>>
>> Thanks for your reply. I searched around in this forum for this topic the
>> last days. I found some topics very simular to the one I described. But I
>> didn't find a good solution or an appender.
>> Perhaps someone can give me an advice.
>>
>>
>> James Stauffer wrote:
>> >
>> > Search the archives.  One file per thread has been discussed and I
>> > think someone made an appender that does it.
>> >
>> > On 5/14/07, rovelgoenne <ro...@merentis.com> wrote:
>> >>
>> >> I start multiple threads where every thread should log to his own
>> file.
>> >> Therefor I did:
>> >> - every thread has a number
>> >> - for every thread I get a logger with "name" + number
>> >> - in every logger I add an DailyRollingFileAppender
>> >> - in the thread I log to the connected logger
>> >> So everything works fine. Every thread logs to his file.
>> >>
>> >> Code (initialization):
>> >> DailyRollingFileAppender fileAppender;
>> >>             for ( int i = 0; i < multiplicity; i++ )
>> >>             {
>> >>                 fileAppender = new DailyRollingFileAppender( layout,
>> >> "c:/log/temp" + i + ".log" "'.'yyyy-MM-dd" );
>> >>                 Logger logger = Logger.getLogger( "logger" + i );
>> >>                 logger.addAppender( fileAppender );
>> >>             }
>> >>
>> >> There is only a problem in heavy logging in all threads. In this
>> >> situation
>> >> sometimes logging entries (or parts of it) from one thread show up in
>> the
>> >> logging file of another thread.
>> >> Has someone an idea about the reason of such an behavour? Is my
>> solution
>> >> not
>> >> suitable for such a problem?
>> >> Do I have to use a different appender (because of the amount of
>> logging
>> >> entries I have to use something like DailyRollingFileAppender)?
>> >> I searched the hole mailing list for an answer but I didn't found
>> >> something
>> >> about these exact problem.
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10605350
>> >> Sent from the Log4j - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > James Stauffer        http://www.geocities.com/stauffer_james/
>> > Are you good? Take the test at http://www.livingwaters.com/good/
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> > For additional commands, e-mail: log4j-user-help@logging.apache.org
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10617864
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
> 
> 
> -- 
> James Stauffer        http://www.geocities.com/stauffer_james/
> Are you good? Take the test at http://www.livingwaters.com/good/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10849999
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: DailyRollingFileAppender for multiple threads

Posted by James Stauffer <st...@gmail.com>.
Starting points:
http://marc.info/?l=log4j-user&m=116732761011115&w=2
http://marc.info/?l=log4j-user&m=116056967826476&w=2
http://marc.info/?l=log4j-user&m=114105274201875&w=2

It is similar to the problem of one file per user.

On 5/15/07, rovelgoenne <ro...@merentis.com> wrote:
>
> Thanks for your reply. I searched around in this forum for this topic the
> last days. I found some topics very simular to the one I described. But I
> didn't find a good solution or an appender.
> Perhaps someone can give me an advice.
>
>
> James Stauffer wrote:
> >
> > Search the archives.  One file per thread has been discussed and I
> > think someone made an appender that does it.
> >
> > On 5/14/07, rovelgoenne <ro...@merentis.com> wrote:
> >>
> >> I start multiple threads where every thread should log to his own file.
> >> Therefor I did:
> >> - every thread has a number
> >> - for every thread I get a logger with "name" + number
> >> - in every logger I add an DailyRollingFileAppender
> >> - in the thread I log to the connected logger
> >> So everything works fine. Every thread logs to his file.
> >>
> >> Code (initialization):
> >> DailyRollingFileAppender fileAppender;
> >>             for ( int i = 0; i < multiplicity; i++ )
> >>             {
> >>                 fileAppender = new DailyRollingFileAppender( layout,
> >> "c:/log/temp" + i + ".log" "'.'yyyy-MM-dd" );
> >>                 Logger logger = Logger.getLogger( "logger" + i );
> >>                 logger.addAppender( fileAppender );
> >>             }
> >>
> >> There is only a problem in heavy logging in all threads. In this
> >> situation
> >> sometimes logging entries (or parts of it) from one thread show up in the
> >> logging file of another thread.
> >> Has someone an idea about the reason of such an behavour? Is my solution
> >> not
> >> suitable for such a problem?
> >> Do I have to use a different appender (because of the amount of logging
> >> entries I have to use something like DailyRollingFileAppender)?
> >> I searched the hole mailing list for an answer but I didn't found
> >> something
> >> about these exact problem.
> >> --
> >> View this message in context:
> >> http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10605350
> >> Sent from the Log4j - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >>
> >
> >
> > --
> > James Stauffer        http://www.geocities.com/stauffer_james/
> > Are you good? Take the test at http://www.livingwaters.com/good/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10617864
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: DailyRollingFileAppender for multiple threads

Posted by rovelgoenne <ro...@merentis.com>.
Thanks for your reply. I searched around in this forum for this topic the
last days. I found some topics very simular to the one I described. But I
didn't find a good solution or an appender.
Perhaps someone can give me an advice.


James Stauffer wrote:
> 
> Search the archives.  One file per thread has been discussed and I
> think someone made an appender that does it.
> 
> On 5/14/07, rovelgoenne <ro...@merentis.com> wrote:
>>
>> I start multiple threads where every thread should log to his own file.
>> Therefor I did:
>> - every thread has a number
>> - for every thread I get a logger with "name" + number
>> - in every logger I add an DailyRollingFileAppender
>> - in the thread I log to the connected logger
>> So everything works fine. Every thread logs to his file.
>>
>> Code (initialization):
>> DailyRollingFileAppender fileAppender;
>>             for ( int i = 0; i < multiplicity; i++ )
>>             {
>>                 fileAppender = new DailyRollingFileAppender( layout,
>> "c:/log/temp" + i + ".log" "'.'yyyy-MM-dd" );
>>                 Logger logger = Logger.getLogger( "logger" + i );
>>                 logger.addAppender( fileAppender );
>>             }
>>
>> There is only a problem in heavy logging in all threads. In this
>> situation
>> sometimes logging entries (or parts of it) from one thread show up in the
>> logging file of another thread.
>> Has someone an idea about the reason of such an behavour? Is my solution
>> not
>> suitable for such a problem?
>> Do I have to use a different appender (because of the amount of logging
>> entries I have to use something like DailyRollingFileAppender)?
>> I searched the hole mailing list for an answer but I didn't found
>> something
>> about these exact problem.
>> --
>> View this message in context:
>> http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10605350
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
> 
> 
> -- 
> James Stauffer        http://www.geocities.com/stauffer_james/
> Are you good? Take the test at http://www.livingwaters.com/good/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10617864
Sent from the Log4j - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: DailyRollingFileAppender for multiple threads

Posted by James Stauffer <st...@gmail.com>.
Search the archives.  One file per thread has been discussed and I
think someone made an appender that does it.

On 5/14/07, rovelgoenne <ro...@merentis.com> wrote:
>
> I start multiple threads where every thread should log to his own file.
> Therefor I did:
> - every thread has a number
> - for every thread I get a logger with "name" + number
> - in every logger I add an DailyRollingFileAppender
> - in the thread I log to the connected logger
> So everything works fine. Every thread logs to his file.
>
> Code (initialization):
> DailyRollingFileAppender fileAppender;
>             for ( int i = 0; i < multiplicity; i++ )
>             {
>                 fileAppender = new DailyRollingFileAppender( layout,
> "c:/log/temp" + i + ".log" "'.'yyyy-MM-dd" );
>                 Logger logger = Logger.getLogger( "logger" + i );
>                 logger.addAppender( fileAppender );
>             }
>
> There is only a problem in heavy logging in all threads. In this situation
> sometimes logging entries (or parts of it) from one thread show up in the
> logging file of another thread.
> Has someone an idea about the reason of such an behavour? Is my solution not
> suitable for such a problem?
> Do I have to use a different appender (because of the amount of logging
> entries I have to use something like DailyRollingFileAppender)?
> I searched the hole mailing list for an answer but I didn't found something
> about these exact problem.
> --
> View this message in context: http://www.nabble.com/DailyRollingFileAppender-for-multiple-threads-tf3752882.html#a10605350
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org