001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.db;
015
016import ch.qos.logback.classic.spi.ILoggingEvent;
017
018/**
019 * @author Ceki Gülcü
020 * 
021 */
022public class DBHelper {
023
024    public static final short PROPERTIES_EXIST = 0x01;
025    public static final short EXCEPTION_EXISTS = 0x02;
026
027    public static short computeReferenceMask(ILoggingEvent event) {
028        short mask = 0;
029
030        int mdcPropSize = 0;
031        if (event.getMDCPropertyMap() != null) {
032            mdcPropSize = event.getMDCPropertyMap().keySet().size();
033        }
034        int contextPropSize = 0;
035        if (event.getLoggerContextVO().getPropertyMap() != null) {
036            contextPropSize = event.getLoggerContextVO().getPropertyMap().size();
037        }
038
039        if (mdcPropSize > 0 || contextPropSize > 0) {
040            mask = PROPERTIES_EXIST;
041        }
042        if (event.getThrowableProxy() != null) {
043            mask |= EXCEPTION_EXISTS;
044        }
045        return mask;
046    }
047}