001/*
002 * Copyright 2012-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.loader.tools;
018
019import ch.qos.logback.classic.Level;
020import org.slf4j.ILoggerFactory;
021import org.slf4j.Logger;
022import org.slf4j.impl.StaticLoggerBinder;
023
024import org.springframework.util.ClassUtils;
025
026/**
027 * Utility to initialize logback (when present) to use INFO level logging.
028 *
029 * @author Dave Syer
030 * @since 1.1.0
031 */
032public abstract class LogbackInitializer {
033
034        public static void initialize() {
035                if (ClassUtils.isPresent("org.slf4j.impl.StaticLoggerBinder", null)
036                                && ClassUtils.isPresent("ch.qos.logback.classic.Logger", null)) {
037                        new Initializer().setRootLogLevel();
038                }
039        }
040
041        private static class Initializer {
042
043                public void setRootLogLevel() {
044                        ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
045                        Logger logger = factory.getLogger(Logger.ROOT_LOGGER_NAME);
046                        ((ch.qos.logback.classic.Logger) logger).setLevel(Level.INFO);
047                }
048
049        }
050
051}