001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017
018 package org.apache.logging.log4j.jul;
019
020 import java.util.IdentityHashMap;
021 import java.util.Map;
022
023 import org.apache.logging.log4j.Level;
024
025 /**
026 * Default implementation of LevelConverter strategy.
027 *
028 * @since 2.1
029 */
030 public class DefaultLevelConverter implements LevelConverter {
031
032 private final Map<java.util.logging.Level, Level> JDK_TO_LOG4J =
033 new IdentityHashMap<java.util.logging.Level, Level>(9);
034 private final Map<Level, java.util.logging.Level> LOG4J_TO_JDK =
035 new IdentityHashMap<Level, java.util.logging.Level>(10);
036
037 public DefaultLevelConverter() {
038 JDK_TO_LOG4J.put(java.util.logging.Level.OFF, Level.OFF);
039 JDK_TO_LOG4J.put(java.util.logging.Level.FINEST, LevelTranslator.FINEST);
040 JDK_TO_LOG4J.put(java.util.logging.Level.FINER, Level.TRACE);
041 JDK_TO_LOG4J.put(java.util.logging.Level.FINE, Level.DEBUG);
042 JDK_TO_LOG4J.put(java.util.logging.Level.CONFIG, LevelTranslator.CONFIG);
043 JDK_TO_LOG4J.put(java.util.logging.Level.INFO, Level.INFO);
044 JDK_TO_LOG4J.put(java.util.logging.Level.WARNING, Level.WARN);
045 JDK_TO_LOG4J.put(java.util.logging.Level.SEVERE, Level.ERROR);
046 JDK_TO_LOG4J.put(java.util.logging.Level.ALL, Level.ALL);
047 LOG4J_TO_JDK.put(Level.OFF, java.util.logging.Level.OFF);
048 LOG4J_TO_JDK.put(LevelTranslator.FINEST, java.util.logging.Level.FINEST);
049 LOG4J_TO_JDK.put(Level.TRACE, java.util.logging.Level.FINER);
050 LOG4J_TO_JDK.put(Level.DEBUG, java.util.logging.Level.FINE);
051 LOG4J_TO_JDK.put(LevelTranslator.CONFIG, java.util.logging.Level.CONFIG);
052 LOG4J_TO_JDK.put(Level.INFO, java.util.logging.Level.INFO);
053 LOG4J_TO_JDK.put(Level.WARN, java.util.logging.Level.WARNING);
054 LOG4J_TO_JDK.put(Level.ERROR, java.util.logging.Level.SEVERE);
055 LOG4J_TO_JDK.put(Level.FATAL, java.util.logging.Level.SEVERE);
056 LOG4J_TO_JDK.put(Level.ALL, java.util.logging.Level.ALL);
057 }
058
059 @Override
060 public Level toLevel(final java.util.logging.Level javaLevel) {
061 return JDK_TO_LOG4J.get(javaLevel);
062 }
063
064 @Override
065 public java.util.logging.Level toJavaLevel(final Level level) {
066 return LOG4J_TO_JDK.get(level);
067 }
068 }