[logback-dev] [JIRA] Commented: (LBCLASSIC-117) Log context based log splitting in SocketServer

Ceki Gulcu (JIRA) noreply-jira at qos.ch
Mon Mar 23 17:19:10 CET 2009


    [ http://jira.qos.ch/browse/LBCLASSIC-117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=11097#action_11097 ] 

Ceki Gulcu commented on LBCLASSIC-117:
--------------------------------------

SiftingAppender is a perfect match for separating configurations per logging context. See  http://logback.qos.ch/manual/appenders.html#SiftingAppender for documentation on SiftingAppender .

You would need a new discriminator class based on application name.

Here is a possible discriminator implementation:

public class ContextBasedDiscriminator extends ContextAwareBase implements
    Discriminator<LoggingEvent> {

  // assume a fixed key set to "contextName"
  static final String KEY = "contextName";
  private String defaultValue;
  private boolean started = false;

  public ContextBasedDiscriminator() {
  }

  public String getDiscriminatingValue(ILoggingEvent event) {
    // code valid only for logback version 0.9.15. 
    // In logback version 0.9.16,  ContextBasedDiscriminator will be part of the standard distribution. More importantly,
    // the structure of LoggingEvent will change considerably so that the next line of code
    // will no longer be valid.
   String contextName = event.getLoggerRemoteView().getLoggerContextView().getName();
    if (contextName == null) {
      return defaultValue;
    } else {
      return contextName;
    }
  }

  public boolean isStarted() {
    return started;
  }

  public void start() {
    started = true;
  }

  public void stop() {
    started = false;
  }

  public String getKey() {
    return KEY ;
  }

  public void setKey(String key) {
    throw new UnsupportedOperationException("Key cannot be set. Using fixed key "+KEY);
  }

  public String getDefaultValue() {
    return defaultValue;
  }

  public void setDefaultValue(String defaultValue) {
    this.defaultValue = defaultValue;
  }
}

And here is a sample configuration fie on the socket server end.

<configuration> 
  <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender"> 

    <discriminator class="ch.qos.logback.classic.sift.ContextBasedDiscriminator">
      <DefaultValue>unknown</DefaultValue>
    </discriminator> 
    <sift> 
      <appender name="FILE-${contextName}" class="ch.qos.logback.core.FileAppender"> 
        <File>${contextName}.log</File>
        <layout class="ch.qos.logback.classic.PatternLayout"> 
        <Pattern>%d [%thread] %level %mdc %logger{35} - %msg%n</Pattern> </layout> 
      </appender>
    </sift> 
  </appender> 
  <root level="DEBUG"> 
    <appender-ref ref="SIFT" />
  </root> 
</configuration>

Please let me know if the above works for you.


> Log context based log splitting in SocketServer
> -----------------------------------------------
>
>                 Key: LBCLASSIC-117
>                 URL: http://jira.qos.ch/browse/LBCLASSIC-117
>             Project: logback-classic
>          Issue Type: New Feature
>          Components: Other
>    Affects Versions: unspecified
>            Reporter: Rick Janda
>            Assignee: Ceki Gulcu
>
> Hello logback team,
> I have the following setup:
> I have several web applications running in the same Tomcat instance.
> The JNDIContextSelector is used to give every deployed webapp its own logging context.
> The logging events are transmitted to a SocketServer.
> On the side of the SocketServer I want to split the logging events based on their log context to different files.
> My idea was to use filters, that filter according the logging context name. But this context name seems to be not reachable from within a filter.
> Would it be possible to add the logging context name as property to the LoggingEvent class that the name is available on the socket server side?
> Or add another means to accomplish the logging event splitting on the SocketServer side?
> This would really simplify our setup as of we would only need one SocketServer for all the Webapps.
> Thanks in advance for your help.
> Kind regards, 
> Rick

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the logback-dev mailing list