7max/log4cl

Log levels of parent loggers are not applied to messages of children.

naryl opened this issue · 3 comments

I have several packages with different log levels writing to different files and I create a file appender for root logger which should write all ERROR messages from all loggers to error.log. Currently messages are only filtered by the logger they're initiated at so if one package's logger is set to DEBUG root logger would write debug messages to error.log even if it's set to ERROR.

Here's my (log:config)

ROOT, ERROR
|
+-(1)-#<DAILY-FILE-APPENDER {131D9559}>
|     with #<PATTERN-LAYOUT {EC39B39}>
|          :conversion-pattern
|            "%&%<{nopretty}%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase} (%C{}{ }{:downcase})%2.2N - %:_%m%>%n"
|     :immediate-flush       NIL
|     :flush-interval        1
|     :stream-owner          T
|     :rollover-check-period 60
|     :name-format           #P"/home/naryl/eshop-logs/eshop.log"
|     :backup-name-format    NIL
|     :utc                   NIL
|     :message-count         2962
|
+-ESHOP, DEBUG
| |
| +-(1)-#<THIS-CONSOLE-APPENDER {131E4B31}>
|       with #<PATTERN-LAYOUT {BB97C89}>
|            :conversion-pattern
|              "%&%<{nopretty}%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase} (%C{}{ }{:downcase})%2.2N - %:_%m%>%n"
|       :immediate-flush NIL
|       :flush-interval  1
|       :stream-owner    NIL
|       :stream          #<SB-SYS:FD-STREAM for "the terminal" {B322409}>
|       :message-count   2962
|
+-SEARCH-TIPS, TRACE
  |
  +-(1)-#<DAILY-FILE-APPENDER {11BC4DE9}>
        with #<PATTERN-LAYOUT {11BC2651}>
             :conversion-pattern
               "%&%<%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase}%:; ;F (%C{}{ }{:downcase})%2.2N - %:_%m%>%n"
        :immediate-flush       NIL
        :flush-interval        1
        :stream-owner          T
        :rollover-check-period 60
        :name-format           "/home/naryl/eshop-logs/search-tips.log"
        :backup-name-format    NIL
        :utc                   NIL
        :message-count         0
7max commented

Yes the log messages are filtered against log level once at the point of
entry, and then are propagated to parents.

Perhaps /additivity/ functionality can help you implement what you want?

A logger that is set as non-additive, does not forward messages to parent
loggers at all. (These are intended for big packages that want to have their
own log files).

For example if you set your search-tips and e-shop loggers as non-additive, none of
their messages will appear in appenders attached to the root logger.

You can set them non-additive by adding :own or :noadditive flag to (log:config)
in the same place where you add the rolling file appender.

If that is not flexible enough, then what you want is to have an appender that
filters on log level. Interestingly enough Log4J has this functionality but
since I never used it personally nor known anyone who used it, I thought it
was over-design and did not implement it in log4cl.

Regards,
Max

At Fri, 23 Aug 2013 03:18:15 -0700,
naryl wrote:

I have several packages with different log levels writing to different files and I create a file appender for root logger which
should write all ERROR messages from all loggers to error.log. Currently messages are only filtered by the logger they're
initiated at so if one package's logger is set to DEBUG root logger would write debug messages to error.log even if it's set to
ERROR.

Here's my (log:config)

ROOT, ERROR
|
+-(1)-#<DAILY-FILE-APPENDER {131D9559}>
| with #<PATTERN-LAYOUT {EC39B39}>
| :conversion-pattern
| "%&%<{nopretty}%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase} (%C{}{ }{:downcase})%2.2N - %:%m%>%n"
| :immediate-flush NIL
| :flush-interval 1
| :stream-owner T
| :rollover-check-period 60
| :name-format #P"/home/naryl/eshop-logs/eshop.log"
| :backup-name-format NIL
| :utc NIL
| :message-count 2962
|
+-ESHOP, DEBUG
| |
| +-(1)-#<THIS-CONSOLE-APPENDER {131E4B31}>
| with #<PATTERN-LAYOUT {BB97C89}>
| :conversion-pattern
| "%&%<{nopretty}%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase} (%C{}{ }{:downcase})%2.2N - %:
%m%>%n"
| :immediate-flush NIL
| :flush-interval 1
| :stream-owner NIL
| :stream #<SB-SYS:FD-STREAM for "the terminal" {B322409}>
| :message-count 2962
|
+-SEARCH-TIPS, TRACE
|
+-(1)-#<DAILY-FILE-APPENDER {11BC4DE9}>
with #<PATTERN-LAYOUT {11BC2651}>
:conversion-pattern
"%&%<%I%;<;;>;-5p [%D{%H:%M:%S}] %g{}{}{:downcase}%:; ;F (%C{}{ }{:downcase})%2.2N - %:_%m%>%n"
:immediate-flush NIL
:flush-interval 1
:stream-owner T
:rollover-check-period 60
:name-format "/home/naryl/eshop-logs/search-tips.log"
:backup-name-format NIL
:utc NIL
:message-count 0


Reply to this email directly or view it on GitHub.*

Ok, mark it invalid. I'll write a level-filtering appender.

7max commented

Cool, it should be a one liner :around method for APPENDER-DO-APPEND for a quick fix.

If you happen to implement a larger patch, with LOG:CONFIG hookup for it, I
would gladly merge it, something like. (LOG:CONFIG ...stuff that adds an
appender... :filter :error). Adding a filter slot to base appender class is
good too, making it NIL by default.

At Fri, 23 Aug 2013 04:28:21 -0700,
naryl wrote:

[1 <text/plain; UTF-8 (7bit)>]

[2 <text/html; UTF-8 (7bit)>]
Ok, mark it invalid. I'll write a level-filtering appender.


Reply to this email directly or view it on GitHub.*