logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LOG4J2-79) Log Levels & Appenders
Date Tue, 11 Sep 2012 02:26:07 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-79?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13452652#comment-13452652
] 

Ralph Goers edited comment on LOG4J2-79 at 9/11/12 1:24 PM:
------------------------------------------------------------

In log4j 2 you can code

<logger name="myLogger" level="debug>
  <appender-ref ref="Console"/>
</logger>

This is exactly equivalent to

<logger name="myLogger" level="trace">
  <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
</logger>

The logger always has an implicit filter that checks for the log level that works exactly
as the ThresholdFilter does. The ThresholdFilter is checked after the implicit log level check
is performed.

In the case for what you are doing you can do:

logger.info(MarkerManager.getMarker("EMAIL"), "This is my email text");

and then configure

<logger name="myLogger" level="trace" additivity="false">
  <MarkerFilter marker="EMAIL" onMatch="ACCEPT" onMismatch="DENY"/>
  <appender-ref ref="Console"/>
</logger>

in this case any log event that has an email marker, such as the one above, will be handled
by the myLogger logger and passed to the Console appender. Note that you can still independently
modify the log level in the configuration to get exactly the behavior you desire.

This provides much more flexibility than adding custom a custom level does. Furthermore, despite
your description above I have to agree that EMAIL is not a log level as it is not even close
to being obvious where in the level list EMAIL would fall. Why wouldn't SMS or VOICE also
be levels and where would they fall respective to EMAIL?  To be honest, if I was the architect
for your system (as you've described it) I wouldn't even be using a Marker called EMAIL, but
one called ALERT or NOTIFY or something similar. I would then create a custom Appender that
gets these events (in the manner I described) and then that appender would figure out who
to deliver the event to and whether the event should be delivered via Email, SMS or phone.



                
      was (Author: ralph.goers@dslextreme.com):
    In log4j 2 you can code

<logger name="myLogger" level="debug>
  <appender-ref ref="Console"/>
</logger>

This is exactly equivalent to

<logger name="myLogger" level="trace">
  <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
</logger>

The logger always has an implicit filter that checks for the log level that works exactly
as the ThresholdFilter does. However, the ThresholdFilter is actually checked before the implicit
level check is done.

In the case for what you are doing you can do:

logger.info(MarkerManager.getMarker("EMAIL"), "This is my email text");

and then configure

<logger name="myLogger" level="trace" additivity="false">
  <MarkerFilter marker="EMAIL" onMatch="ACCEPT" onMismatch="DENY"/>
  <appender-ref ref="Console"/>
</logger>

in this case any log event that has an email marker, such as the one above, will be handled
by the myLogger logger and passed to the Console appender. Note that you can still independently
modify the log level in the configuration to get exactly the behavior you desire.

This provides much more flexibility than adding custom a custom level does. Furthermore, despite
your description above I have to agree that EMAIL is not a log level as it is not even close
to being obvious where in the level list EMAIL would fall. Why wouldn't SMS or VOICE also
be levels and where would they fall respective to EMAIL?  To be honest, if I was the architect
for your system (as you've described it) I wouldn't even be using a Marker called EMAIL, but
one called ALERT or NOTIFY or something similar. I would then create a custom Appender that
gets these events (in the manner I described) and then that appender would figure out who
to deliver the event to and whether the event should be delivered via Email, SMS or phone.



                  
> Log Levels & Appenders
> ----------------------
>
>                 Key: LOG4J2-79
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-79
>             Project: Log4j 2
>          Issue Type: Wish
>          Components: Core
>            Reporter: Chris Stefanic
>            Priority: Minor
>
> I’m currently working in a software development group that uses the Log4j.1.x and I
am looking at upgrading to Log4j.2.x to take advantage of the performance improvements.  In
my previous development groups we wrote our on Logging utilities due to Log4j.1.x performance
problems and it did not support all the functionality required to support our system.  Two
main functions in our homegrown Logging utility was the ability to send email (logger.email)
and record transaction statistical (logger.stat) information.
> In Log4j.1.x there is a SMTPAppender that provides the email capability but I don’t
see that Appender in the Log4j.2.x Appender collection.  When implemented, the SMTPAppender
would publish an email for log levels ERROR and FATAL and could be changed to publish for
the other log levels; WARN, INFO or a self-defined Level.  The Log4j.2.x documentation states
the Logging Levels are now an ENUM and cannot be sub-classed and to use “Markers” for
more granularity.  In our homegrown Logging utility the “EMAIL” level was distinct because
not all ERROR/FATAL require an email to be sent and not all EMAIL are ERROR/FATAL.  Are there
any plains to include or write a new SMTPAppender in Log4j.2.x?  If the SMTPAppender becomes
available in Log4j.2 can you/will create a new Level, “EMAIL” to support a distinct Logging
Level?
> In our homegrown Logging Utility we also had a “STAT” (transactional/statistical)
Logging Level. This Level was used to record relevant data for a unit of work performed by
the system.  These messages were logged to a distinct file and in some cases the data was
also sent to in house Monitoring and Control Diagnostics system.  These log messages were
not INFO, WARN, ERROR etc.  As in the EMAIL log level what is the possibility of adding another
Logging Level, STAT to the defined ENUM or provide the ability to create new Levels?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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


Mime
View raw message