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 chapters.architecture;
015
016import ch.qos.logback.classic.Level;
017import org.slf4j.Logger;
018import org.slf4j.LoggerFactory;
019
020/**
021 * @author Ceki Gülcü
022 */
023public class SelectionRule {
024
025    public static void main(String[] args) {
026        // get a logger instance named "com.foo". Let us further assume that the
027        // logger is of type ch.qos.logback.classic.Logger so that we can
028        // set its level
029        ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.foo");
030        // set its Level to INFO. The setLevel() method requires a logback logger
031        logger.setLevel(Level.INFO);
032
033        Logger barlogger = LoggerFactory.getLogger("com.foo.Bar");
034
035        // This request is enabled, because WARN >= INFO
036        logger.warn("Low fuel level.");
037
038        // This request is disabled, because DEBUG < INFO.
039        logger.debug("Starting search for nearest gas station.");
040
041        // The logger instance barlogger, named "com.foo.Bar",
042        // will inherit its level from the logger named
043        // "com.foo" Thus, the following request is enabled
044        // because INFO >= INFO.
045        barlogger.info("Located nearest gas station.");
046
047        // This request is disabled, because DEBUG < INFO.
048        barlogger.debug("Exiting gas station search");
049
050    }
051}