logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sicker <boa...@gmail.com>
Subject Re: Loggers with same name - how to work around?
Date Fri, 16 Apr 2021 13:32:41 GMT
You should take a look at the routing appender for supporting what you want
to do. You can certainly keep the same logger name. You’d simply route log
events based on other metadata. See:
http://logging.apache.org/log4j/2.x/manual/appenders.html#RoutingAppender

On Fri, Apr 16, 2021 at 06:35 Lars-Fredrik Smedberg <itsmeden@gmail.com>
wrote:

> Hi
>
> We have different appenders, one file appender and one syslog appender
> amongst others. We want the file appender to use a normal Logger and the
> syslog appender using an AsyncLogger. When the different
> applications/functions perform the logging they don't know if it will end
> up in the file appender only or in both the file appender and syslog
> appender. The syslog appender have a filter (AlertFilter) that decides if
> the log event will be accepted or not. The file appender has no filter.
>
> The configuration looks like below (important parts included, some
> attributes masked):
>
> Any suggestion on how to be able to use the same logger name (which
> obviously is not allowed) or achieve something that works the same way?
>
> Best regards, preciate any help
> LF
>
> <Configuration status="debug" packages="xyz">
>   <Appenders>
>     <Console name="ConsoleLogAppender" target="SYSTEM_OUT">
>       <PatternLayout pattern="%m"/>
>     </Console>
>     <Syslog name="AlertLogAppender" host="xyz" port="xyz" protocol="TCP"
> format="RFC5424" facility="LOCAL6"
>         includeMDC="false" enterpriseNumber="xyz" appName="xyz"
> newLine="true" messageId="Alert" id="App">
>       <AlertFilter onMatch="ACCEPT" onMismatch="DENY"/>
>     </Syslog>
>     <RollingFile name="RollingFileAppender" fileName="logs/application.log"
>         filePattern="logs/application.log.%i.gz" immediateFlush="true"  >
>       <PatternLayout pattern =%m%n"/>
>       <Policies>
>         <OnStartupTriggeringPolicy/>
>         <SizeBasedTriggeringPolicy size="10 MB"/>
>       </Policies>
>       <DefaultRolloverStrategy max="2"/>
>     </RollingFile>
>   </Appenders>
>   <Loggers>
>     <AsyncLogger name="foo" level="info" additivity="false">
>       <AppenderRef ref="AlertLogAppender"/>
>     </AsyncLogger>
>     <Logger name="foo" level="info" additivity="false">
>       <AppenderRef ref="RollingFileAppender"/>
>     </Logger>
>     <Root level="warn">
>       <AppenderRef ref="ConsoleLogAppender"/>
>     </Root>
>   </Loggers>
> </Configuration>
>
> --
> Med vänlig hälsning / Best regards
>
> Lars-Fredrik Smedberg
>
> STATEMENT OF CONFIDENTIALITY:
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> address(es) and may contain confidential or privileged information. If
> you are not the intended recipient, please notify Lars-Fredrik Smedberg
> immediately at itsmeden@gmail.com, and destroy all copies of this
> message and any attachments.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message