You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2018/11/08 21:34:00 UTC

[jira] [Commented] (LOG4J2-2502) Support ContextListener like in Logback

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

Ralph Goers commented on LOG4J2-2502:
-------------------------------------

Virtually anything you would want to do can be done with a Lookup.

{code}
<File name="JSON" fileName="${OSUTIL:basePath}/logs" ,,,>
{code}


> Support ContextListener like in Logback
> ---------------------------------------
>
>                 Key: LOG4J2-2502
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2502
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Web/Servlet
>    Affects Versions: 2.11.1
>            Reporter: Michele Preti
>            Priority: Major
>
> Hi,
> i'm trying to switch to Log4j from Logback.
> In the configuration (the file appender), i'm using a system property that does not exist and is created in the contextListener (the logs path is generated at runtime and can't be set staticly in the config file)
> {code:java}
> <configuration debug="true">
>  <contextListener class="it.my.LoggerStartupListener"/>
>  <appender name="JSON" class="ch.qos.logback.core.rolling.RollingFileAppender">
>   <File>${LOG_PATH}/app.log</File>
>  <FileNamePattern>${LOG_PATH}/app.%d{yyyy-MM-dd}.%i.log.gz
>  </FileNamePattern>
> ...{code}
> {code:java}
> public class LoggerStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle {
>  private static final String LOG_PATH = "LOG_PATH";
>  @Override
>  public void start() {
>     getContext().putProperty(LOG_PATH, Paths.get(OSUtils.getBasePath(), "logs").toString());
>   }
> }{code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)