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.util;
12  
13  import ch.qos.logback.classic.Level;
14  import ch.qos.logback.classic.spi.LoggingEvent;
15  import ch.qos.logback.core.net.SyslogConstants;
16  
17  public class LevelToSyslogSeverity {
18  
19    /*
20     * Convert a level to equivalent syslog severity. Only levels for printing
21     * methods i.e TRACE, DEBUG, WARN, INFO and ERROR are converted.
22     * 
23     */
24    static public int convert(LoggingEvent event) {
25  
26      Level level = event.getLevel();
27  
28      switch (level.levelInt) {
29      case Level.ERROR_INT:
30        return SyslogConstants.ERROR_SEVERITY;
31      case Level.WARN_INT:
32        return SyslogConstants.WARNING_SEVERITY;
33      case Level.INFO_INT:
34        return SyslogConstants.INFO_SEVERITY;
35      case Level.DEBUG_INT:
36        return SyslogConstants.DEBUG_SEVERITY;
37      case Level.TRACE_INT:
38        return SyslogConstants.DEBUG_SEVERITY;
39      default:
40        throw new IllegalArgumentException("Level " + level
41            + " is not a valid level for a printing method");
42      }
43    }
44  }