You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by "RUOFF, LARS (LARS)" <la...@alcatel-lucent.com> on 2014/01/21 16:56:50 UTC
Different loggers writing to same file with different Layouts?
Hi,
Using log4cxx v0.9.7,
I'd like to have two different loggers logging to a same file, but with different Layouts.
I have created two different loggers, part of same hierarchy.
Naively, I have assigned a different FileAppender to each, with a different Layout each.
But I have given the same file name to both.
This works. Both types of logs appear in the file.
However i wonder if this is only a side-effect rather than a feature. Because what would happen if i set different options on the two FileAppenders? What if i use both RollingFileAppender and FileAppender on the same file?
So is there another (safer?) recommended method for having two loggers writing to the same file, but with different layouts?
Actually, i want to have some log entries timestamped, others not.
regards,
Lars R.
RE: Different loggers writing to same file with different Layouts?
Posted by "RUOFF, LARS (LARS)" <la...@alcatel-lucent.com>.
Hi Rhys,
Thanks anyway.
For the record, here's the equivalent question asked for log4j in general:
http://stackoverflow.com/questions/17399610/log4j-set-different-layout-for-same-file
regards,
Lars R.
-----Original Message-----
From: Rhys Ulerich [mailto:rhys.ulerich@gmail.com]
Sent: mercredi 22 janvier 2014 00:44
To: Log4CXX User
Subject: Re: Different loggers writing to same file with different Layouts?
> I'd like to have two different loggers logging to a same file, but with different Layouts.
I suspect, but do not know, that this is not supported.
> I have created two different loggers, part of same hierarchy.
> Naively, I have assigned a different FileAppender to each, with a different Layout each.
> But I have given the same file name to both.
> This works. Both types of logs appear in the file.
>
> However i wonder if this is only a side-effect rather than a feature.
I believe you're right that it is only a side-effect of the implementation.
> Because what would happen if i set different options on the two FileAppenders?
> What if i use both RollingFileAppender and FileAppender on the same file?
I suspect Very Bad Things (TM).
> So is there another (safer?) recommended method for having two loggers writing to the same file, but with different layouts?
I'm unsure of one. I believe a Layout is 1-1 with an Appender and a File is 1-1 with a FileAppender. How to do this is not jumping out at me from browsing the class hierarchy.
Sorry to not be more help,
Rhys
Re: Different loggers writing to same file with different Layouts?
Posted by Rhys Ulerich <rh...@gmail.com>.
> I'd like to have two different loggers logging to a same file, but with different Layouts.
I suspect, but do not know, that this is not supported.
> I have created two different loggers, part of same hierarchy.
> Naively, I have assigned a different FileAppender to each, with a different Layout each.
> But I have given the same file name to both.
> This works. Both types of logs appear in the file.
>
> However i wonder if this is only a side-effect rather than a feature.
I believe you're right that it is only a side-effect of the implementation.
> Because what would happen if i set different options on the two FileAppenders?
> What if i use both RollingFileAppender and FileAppender on the same file?
I suspect Very Bad Things (TM).
> So is there another (safer?) recommended method for having two loggers writing to the same file, but with different layouts?
I'm unsure of one. I believe a Layout is 1-1 with an Appender and a
File is 1-1 with a FileAppender. How to do this is not jumping out at
me from browsing the class hierarchy.
Sorry to not be more help,
Rhys