View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache license, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License. You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the license for the specific language governing permissions and
    15   * limitations under the license.
    16   */
    17
    18  package org.apache.logging.log4j.jul;
    19
    20  import java.util.IdentityHashMap;
    21  import java.util.Map;
    22
    23  import org.apache.logging.log4j.Level;
    24
    25  /**
    26   * Default implementation of LevelConverter strategy.
    27   *
    28   * @since 2.1
    29   */
    30  public class DefaultLevelConverter implements LevelConverter {
    31
    32      private final Map<java.util.logging.Level, Level> JDK_TO_LOG4J =
    33          new IdentityHashMap<java.util.logging.Level, Level>(9);
    34      private final Map<Level, java.util.logging.Level> LOG4J_TO_JDK =
    35          new IdentityHashMap<Level, java.util.logging.Level>(10);
    36
    37      public DefaultLevelConverter() {
    38          JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
    39          JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, LevelTranslator.FINEST);
    40          JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.TRACE);
    41          JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
    42          JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, LevelTranslator.CONFIG);
    43          JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
    44          JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
    45          JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
    46          JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
    47          LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
    48          LOG4J_TO_JDK.put(LevelTranslator.FINEST, java.util.logging.Level.FINEST);
    49          LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINER);
    50          LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
    51          LOG4J_TO_JDK.put(LevelTranslator.CONFIG, java.util.logging.Level.CONFIG);
    52          LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
    53          LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
    54          LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
    55          LOG4J_TO_JDK.put(Level.FATAL, java.util.logging.Level.SEVERE);
    56          LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
    57      }
    58
    59      @Override
    60      public Level toLevel(final java.util.logging.Level javaLevel) {
    61          return JDK_TO_LOG4J.get(javaLevel);
    62      }
    63
    64      @Override
    65      public java.util.logging.Level toJavaLevel(final Level level) {
    66          return LOG4J_TO_JDK.get(level);
    67      }
    68  }