[logback-user] Log separation

Dhondt, Edwin edwin.dhondt at hp.com
Thu Apr 29 08:59:27 CEST 2010


That clarifies a lot, I hope ;-).

My comprehension is that the intention of this all is to separate the logfiles in a scenario where you have multiple webapps "sharing" a common library (jar).
In that scenario the intention is to have log messages produced by bóth webapp-specific code ánd log messages produced by log statements in the common library code to appear in distinct logfiles.
E.g.
log statements produced "in the context of" webapp1 (e.g. Yoda) must ALL (that is both log messages produced in yoda ánd log messages produced by code in the common codebase called from yoda) go to yoda.log.
log statements produced "in the context of" webapp2 (e.g. Kenobi) must ALL (that is both log messages produced in kenobi ánd log messages produced by code in the common codebase called from kenobi) go to kenobi.log.

E.g let's say webapp1 and webapp2 invoke common code to create a user (createUser). If a call createUser from "within" webapp1, I want the log messages produced in createUser, like "user x created" to go to the webapp1.log file, when I call createUser from "within" webapp2, I want the log messages to go to the webapp2.log file, and not for some reason or the other (e.g. webapp1 initalized before webapp2), to webapp1's log file.

That is, coming back to the starwars example when I open the yoda.log I only want to see log messages produced in the context of running the Yoda webapp.
That is, when I open the kenobi.log I only want to see log messages produced in the context of running the Kenobi webapp.

Is the above interpretation correct ?

If yes, then I still don't see how the ASCII diagram and the example in the logback manual (***) support the above:
(***)
"
If kenobi and yoda are web-applications ...

Visiting http://localhost:port/kenobi/servlet will output the following in kenobi.log.
DEBUG ch.qos.starwars.kenobi.KenobiServlet          cn=kenobi - in doGet()
DEBUG ch.qos.starwars.shared.Mustafar               cn=yoda - in foo()
Note that even if the ch.qos.starwars.shared.Mustafar logger outputs to kenobi.log it is still attached to 'yoda'. Thus, we have two distinct logging contexts logging to the same file, in this case kenobi.log.
"

>From the diagram and the above excerpt (***) of the example in the manual I can only deduce that log messages produced "in the context of" Kenobi will be scattered over two files because when the Yoda app is initialized the first, the Mustafar logger will be "bound" to the Yoda context, not the Kenobi context. Thereby, log messages produced while running Kenobi will be scattered over yoda.log and Kenobi.log.
Is that correct ? If yes, then there's no log separation.

Please clarify.

Thanks,
Edwin


-----Original Message-----
From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On Behalf Of Ceki Gülcü
Sent: woensdag 28 april 2010 19:34
To: logback users list
Subject: Re: [logback-user] Log separation


Here is an ASCII diagram which might clarify the point.

          +---------------------+           +-------------------------+
          |    yoda context     |           |     kenobi context      |
          +---------------------+           +-------------------------+
              |               |                |            |
+-------------------+   +------------+   +-----------+   +-----------+
|FILE-yoda appender |   |FILE-Kenobi |   | FILE-yoda |   |FILE-kenobi|
+-------------------+   +------------+   +-----------+   +-----------+
       |                    |                   |                |
       |                    |                   |                |
       |                    |                   |                |
       |                    v                   |                |
       |              kenobi.log (file) <-------|--------------- +
       v                                        |
    yoda.log (file) <---------------------------+


Due to SiftingAppenders (one per context) there are two distinct
FileAppenders (one in each context) writing to the same file. There
are four FileAppenders (two per context). Do not cling to the term
"same file" as there is a whole explanatory context. If you still do
not see the point, that's probably because you are unfamiliar with
SiftingAppender.

HTH

On 28/04/2010 6:14 PM, Dhondt, Edwin wrote:
> Isn't the chapter about the situation where you have different web applications that share a common library and more specifically about how to enable logging to go to distinct log files ( a yoda and a Kenobi file) in that particular setting ? If so, then I don't understand why in Kenobi.log, entries with yoda context appear and why it's stated that logging occurs to the same file ? I would have expected that logging within a thread launched "at" yoda would result in log messages to go exclusively to yoda.log, and that logging within a thread launched "at" Kenobi would result in log messages going exclusively to Kenobi.log ? Can you shed a light on that ? What am I not understanding ?
>
>
>
> -----Original Message-----
> From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On Behalf Of Ceki Gülcü
> Sent: woensdag 28 april 2010 17:50
> To: logback users list
> Subject: Re: [logback-user] Log separation
>
>
> The example is not wrong. You probably read the chapter too quickly.
>
> On 28/04/2010 5:41 PM, Dhondt, Edwin wrote:
>> I've just finished reading that chapter.
>>
>> At first glance it seems that using a combination of JNDIBasedContextDiscriminator and SiftingAppender should solve my problem ?
>>
>> But then I read on through the example (Yoda, Kenobi) and now I'm confused.  Especially because of the following sentence from the example "Note that even if the ch.qos.starwars.shared.Mustafar logger outputs to kenobi.log it is still attached to 'yoda'. Thus, we have two distinct logging contexts logging to the same file, in this case kenobi.log. Each of these contexts reference FileAppender instances, nested within distinct SiftingAppender instances, logging to the same file."
>> So although the solution described (JNDIBasedContextDiscriminator and SiftingAppender) is about how to log to different files from within a shared codebase, the example doesn't seem to support that theory because it says that two distinct logging contexts are logging to the same file. Is the example wrong ? What am I missing ?
>>
>> Edwin
>>
>> -----Original Message-----
>> From: logback-user-bounces at qos.ch [mailto:logback-user-bounces at qos.ch] On Behalf Of Ceki Gülcü
>> Sent: woensdag 28 april 2010 17:28
>> To: logback users list
>> Subject: Re: [logback-user] Log separation
>>
>> Hello Edwin,
>>
>> The chapter on logging separation [1] should be helpful, in particular
>> the section entitled "Taming static references in shared libraries".
>>
>> HTH,
>>
>> [1] http://logback.qos.ch/manual/loggingSeparation.html
>>
>> On 28/04/2010 4:56 PM, Dhondt, Edwin wrote:
>>> I've got 4 web applications.  They all have some specific code containing log statements but they also include a common "backend" codebase jar. Code in that common codebase also contains log statements.
>>>
>>> I want each of those 4 applications to have their own log file.  That is, I want all log messages for webapp 1 to appear in webapp 1's log file, messages for webapp2 in webapp 2's file and so on.
>>>
>>> This is not a problem for the log statements appearing in the code specific to each webapp.
>>>
>>> But what about log statements in de common "backend" codebase (included by each of the webapps) ?  How do those log statements "know" when log statements should go to webapp 1's logfile or webapp 2's log file ?  Because that depends on where the calling  thread initiated (in webapp1, 2, ...).
>>> I could augment each of my backend method signatures with a extra context parameter, but I hope there are more transparent solutions ?
>>>
>>> User =>    methodA Webapp1 =>    backend codebase methodX =>    webapp1.log
>>> User =>    methodB Webapp2 =>    backend codebase methodX =>    webapp2.log
>>> ...
>>>
>>> Any advice would be welcome.
>>> Thanks,
>>> EDH
>>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://qos.ch/mailman/listinfo/logback-user
>>
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://qos.ch/mailman/listinfo/logback-user
>
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user

_______________________________________________
Logback-user mailing list
Logback-user at qos.ch
http://qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list