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.util;
015
016import ch.qos.logback.classic.Level;
017import ch.qos.logback.classic.spi.ILoggingEvent;
018import ch.qos.logback.core.net.SyslogConstants;
019
020public class LevelToSyslogSeverity {
021
022    /*
023     * Convert a level to equivalent syslog severity. Only levels for printing
024     * methods i.e. TRACE, DEBUG, WARN, INFO and ERROR are converted.
025     */
026    static public int convert(ILoggingEvent event) {
027
028        Level level = event.getLevel();
029
030        switch (level.levelInt) {
031        case Level.ERROR_INT:
032            return SyslogConstants.ERROR_SEVERITY;
033        case Level.WARN_INT:
034            return SyslogConstants.WARNING_SEVERITY;
035        case Level.INFO_INT:
036            return SyslogConstants.INFO_SEVERITY;
037        case Level.DEBUG_INT:
038        case Level.TRACE_INT:
039            return SyslogConstants.DEBUG_SEVERITY;
040        default:
041            throw new IllegalArgumentException("Level " + level + " is not a valid level for a printing method");
042        }
043    }
044}