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.receivers.socket; 015 016import org.slf4j.LoggerFactory; 017 018import ch.qos.logback.classic.LoggerContext; 019import ch.qos.logback.classic.joran.JoranConfigurator; 020 021/** 022 * This application loads a configuration containing a 023 * receiver component and logs events received from the remote 024 * appender according to the local configuration. 025 */ 026public class ReceiverExample { 027 028 static void usage(String msg) { 029 System.err.println(msg); 030 System.err.println("Usage: java " + ReceiverExample.class.getName() + " configFile\n" + " configFile a logback configuration file" 031 + " in XML format."); 032 System.exit(1); 033 } 034 035 static public void main(String[] args) throws Exception { 036 if (args.length != 1) { 037 usage("Wrong number of arguments."); 038 } 039 040 String configFile = args[0]; 041 042 if (configFile.endsWith(".xml")) { 043 LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); 044 lc.reset(); 045 JoranConfigurator configurator = new JoranConfigurator(); 046 configurator.setContext(lc); 047 configurator.doConfigure(configFile); 048 } 049 050 Thread.sleep(Long.MAX_VALUE); 051 } 052 053}