1 /** 2 * Logback: the reliable, generic, fast and flexible logging framework. 3 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 4 * 5 * This program and the accompanying materials are dual-licensed under 6 * either the terms of the Eclipse Public License v1.0 as published by 7 * the Eclipse Foundation 8 * 9 * or (per the licensee's choosing) 10 * 11 * under the terms of the GNU Lesser General Public License version 2.1 12 * as published by the Free Software Foundation. 13 */ 14 package chapters.architecture; 15 16 import ch.qos.logback.classic.Level; 17 import org.slf4j.Logger; 18 import org.slf4j.LoggerFactory; 19 20 /** 21 * @author Ceki Gülcü 22 */ 23 public class SelectionRule { 24 25 public static void main(String[] args) { 26 // get a logger instance named "com.foo". Let us further assume that the 27 // logger is of type ch.qos.logback.classic.Logger so that we can 28 // set its level 29 ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.foo"); 30 // set its Level to INFO. The setLevel() method requires a logback logger 31 logger.setLevel(Level.INFO); 32 33 Logger barlogger = LoggerFactory.getLogger("com.foo.Bar"); 34 35 // This request is enabled, because WARN >= INFO 36 logger.warn("Low fuel level."); 37 38 // This request is disabled, because DEBUG < INFO. 39 logger.debug("Starting search for nearest gas station."); 40 41 // The logger instance barlogger, named "com.foo.Bar", 42 // will inherit its level from the logger named 43 // "com.foo" Thus, the following request is enabled 44 // because INFO >= INFO. 45 barlogger.info("Located nearest gas station."); 46 47 // This request is disabled, because DEBUG < INFO. 48 barlogger.debug("Exiting gas station search"); 49 50 } 51 }