View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  
11  package ch.qos.logback.classic.db;
12  
13  import ch.qos.logback.classic.spi.LoggingEvent;
14  import ch.qos.logback.classic.spi.ThrowableDataPoint;
15  
16  /**
17   * @author Ceki Gülcü
18   * 
19   */
20  public class DBHelper {
21  
22    public static short PROPERTIES_EXIST = 0x01;
23    public static short EXCEPTION_EXISTS = 0x02;
24  
25    public static short computeReferenceMask(LoggingEvent event) {
26      short mask = 0;
27  
28      int mdcPropSize = 0;
29      if (event.getMDCPropertyMap() != null) {
30        mdcPropSize = event.getMDCPropertyMap().keySet().size();
31      }
32      int contextPropSize = 0;
33      if (event.getLoggerRemoteView().getLoggerContextView().getPropertyMap() != null) {
34        contextPropSize = event.getLoggerRemoteView().getLoggerContextView()
35            .getPropertyMap().size();
36      }
37  
38      if (mdcPropSize > 0 || contextPropSize > 0) {
39        mask = PROPERTIES_EXIST;
40      }
41      if (event.getThrowableProxy() != null) {
42        ThrowableDataPoint[] tdpArray = event.getThrowableProxy().getThrowableDataPointArray();
43        if (tdpArray != null) {
44          mask |= EXCEPTION_EXISTS;
45        }
46      }
47      return mask;
48    }
49  }