Configure SLF4J.

@param is input stream to logback configuration xml
764841
public static void configure(InputStream is) {

		ClassLoader cl = Thread.currentThread().getContextClassLoader();

		try {

			String[] names = {
				"ch.qos.logback.classic.LoggerContext",
				"ch.qos.logback.classic.joran.JoranConfigurator",
			};
			for (String name : names) {
				Class.forName(name, false, cl);
			}

			ch.qos.logback.classic.LoggerContext context = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
			ch.qos.logback.classic.joran.JoranConfigurator configurator = new ch.qos.logback.classic.joran.JoranConfigurator();
			configurator.setContext(context);
			context.reset();
			configurator.doConfigure(is);

		} catch (ClassNotFoundException e) {
			System.err.println("WLogC: Logback JARs are missing in classpath");
		} catch (NoClassDefFoundError e) {
			System.err.println("WLogC: Logback JARs are missing in classpath");
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
181498
@Override
	public void validateSetup(Server server, Query query) throws ValidationException {
		// Check if we've already created a logger for this file. If so, use it.
		Logger logger;
		if (loggers.containsKey(outputFile)) {
			logger = getLogger(outputFile);
		}else{
			// need to create a logger
			try {
				logger = buildLogger(outputFile);
				loggers.put(outputFile, logger);
			} catch (IOException e) {
				throw new ValidationException("Failed to setup logback", query, e);
			}
		}
		logwriter = new LogWriter(logger,delimiter);
	}
108994
public void configure(Properties props) {
        this.refreshCount.set(0);
        this.overrideProps.clear();
        
        this.originalAsyncAppenderNameMap.clear();
       // First try to load the log4j configuration file from the classpath
        String log4jConfigurationFile = System.getProperty(PROP_LOG4J_CONFIGURATION);
        
        NFHierarchy nfHierarchy = null;
        
        // Make log4j use blitz4j implementations
        if ((!NFHierarchy.class.equals(LogManager.getLoggerRepository().getClass()))) {
            nfHierarchy = new NFHierarchy(new NFRootLogger(org.apache.log4j.Level.INFO));
            org.apache.log4j.LogManager.setRepositorySelector(new NFRepositorySelector(nfHierarchy), guard);
        }
        
        String log4jLoggerFactory = System.getProperty(PROP_LOG4J_LOGGER_FACTORY);
        if (log4jLoggerFactory != null) {
            this.initialProps.setProperty(PROP_LOG4J_LOGGER_FACTORY, log4jLoggerFactory);
            if (nfHierarchy != null) {
                try {
                    LoggerFactory loggerFactory = (LoggerFactory) Class.forName(log4jLoggerFactory).newInstance();
                    nfHierarchy.setLoggerFactory(loggerFactory);
                } catch (Exception e) {
                    System.err.println("Cannot set the logger factory. Hence reverting to default.");
                    e.printStackTrace();
                }
            }
        } else {
            this.initialProps.setProperty(PROP_LOG4J_LOGGER_FACTORY, BLITZ_LOGGER_FACTORY);

        }
        if (log4jConfigurationFile != null) {
            loadLog4jConfigurationFile(log4jConfigurationFile);
            // First configure without async so that we can capture the output
            // of dependent libraries
            clearAsyncAppenderList();
            PropertyConfigurator.configure(this.initialProps);
        }

        this.blitz4jConfig = new DefaultBlitz4jConfig(props);

        if ((log4jConfigurationFile == null) && (blitz4jConfig.shouldLoadLog4jPropertiesFromClassPath())) {
            try {
                URL url = Loader.getResource(LOG4J_PROPERTIES);
                if (url != null) {
                    try (InputStream in = url.openStream()) {
                        this.initialProps.load(in);
                    }
                }
            } catch (Exception t) {
                System.err.println("Error loading properties from " + LOG4J_PROPERTIES);
            } 
        }   
        
        Enumeration enumeration = props.propertyNames();
        while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            String propertyValue = props.getProperty(key);
            this.initialProps.setProperty(key, propertyValue);
        }
        
        this.blitz4jConfig = new DefaultBlitz4jConfig(this.initialProps);
    
        String[] asyncAppenderArray = blitz4jConfig.getAsyncAppenders();
        if (asyncAppenderArray == null) {
            return;
        }
        for (int i = 0; i < asyncAppenderArray.length; i++) {
            String oneAppenderName = asyncAppenderArray[i];
            if ((i == 0) || (oneAppenderName == null)) {
                continue;
            }
            oneAppenderName = oneAppenderName.trim();
            String oneAsyncAppenderName = oneAppenderName + ASYNC_APPENDERNAME_SUFFIX;
            originalAsyncAppenderNameMap.put(oneAppenderName, oneAsyncAppenderName);
        }
        try {
            convertConfiguredAppendersToAsync(this.initialProps);
        } catch (Exception e) {
            throw new RuntimeException("Could not configure async appenders ",
                    e);
        }
        // Yes second time init required as properties would have been during async appender conversion
        this.blitz4jConfig = new DefaultBlitz4jConfig(this.initialProps);
        clearAsyncAppenderList();
        PropertyConfigurator.configure(this.initialProps);
        closeNonexistingAsyncAppenders();
        this.logger = org.slf4j.LoggerFactory.getLogger(LoggingConfiguration.class);
        ConfigurationManager.getConfigInstance().addConfigurationListener(
                new ExpandedConfigurationListenerAdapter(this));
    }
1248200
@Override
   protected void dumpJFapServerStatus(final IncidentStream is)
   {
      if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "dumpJFapServerStatus", is);
      
      dumpMEtoMEConversations(is);
      dumpInboundConversations(is);
      
      if(TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "dumpJFapServerStatus");
   }
1339905
public void configureLogging(final LoggingSettings loggingSettings) {

        final Logger root = (Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        final LoggerContext context = root.getLoggerContext();

        // Reset prior configuration
        context.reset();

        // Propagate level changes to java.util.logging
        final LevelChangePropagator propagator = new LevelChangePropagator();
        propagator.setContext(context);
        propagator.setResetJUL(true);

        // Set base threshold for all other loggers.
        root.setLevel(loggingSettings.getLevel());

        // Loop through explicitly configured loggers and set the levels
        for (final Map.Entry<String, Level> entry : loggingSettings.getLoggers().entrySet()) {
            ((Logger)LoggerFactory.getLogger(entry.getKey())).setLevel(entry.getValue());
        }

        if (loggingSettings.getLogFile().isEnabled()) {
            root.addAppender(getFileAppender(loggingSettings.getLogFile(), context));
        }

        if (loggingSettings.getConsole().isEnabled()) {
            root.addAppender(getConsoleAppender(loggingSettings.getConsole(), context));
        }
    }
101399
void configure(InputStream config,int nargs) throws Exception
    {
        BufferedReader cfg=new BufferedReader(new InputStreamReader(config,"ISO-8859-1"));
        Version java_version=new Version(System.getProperty("java.version"));
        Version ver=new Version();
        // JAR's already processed
        java.util.Hashtable done=new Hashtable();
        // Initial classpath
        String classpath=System.getProperty("CLASSPATH");
        if(classpath!=null)
        {
            StringTokenizer tok=new StringTokenizer(classpath,File.pathSeparator);
            while(tok.hasMoreTokens())
                _classpath.addComponent(tok.nextToken());
        }
        // Handle line by line
        String line=null;
        while(true)
        {
            line=cfg.readLine();
            if(line==null)
                break;
            if(line.length()==0||line.startsWith("#"))
                continue;
            try
            {
                StringTokenizer st=new StringTokenizer(line);
                String subject=st.nextToken();
                subject=expand(subject);
                boolean expression=true;
                boolean not=false;
                String condition=null;
                // Evaluate all conditions
                while(st.hasMoreTokens())
                {
                    condition=st.nextToken();
                    if(condition.equalsIgnoreCase("!"))
                    {
                        not=true;
                        continue;
                    }
                    if(condition.equalsIgnoreCase("OR"))
                    {
                        if(expression)
                            break;
                        expression=true;
                        continue;
                    }
                    if(condition.equalsIgnoreCase("AND"))
                    {
                        if(!expression)
                            break;
                        continue;
                    }
                    boolean eval=true;
                    if(condition.equals("true")||condition.equals("always"))
                    {
                        eval=true;
                    }
                    else if(condition.equals("false")||condition.equals("never"))
                    {
                        eval=false;
                    }
                    else if(condition.equals("available"))
                    {
                        String class_to_check=st.nextToken();
                        eval=isAvailable(class_to_check);
                    }
                    else if(condition.equals("exists"))
                    {
                        try
                        {
                            eval=false;
                            File file=new File(expand(st.nextToken()));
                            eval=file.exists();
                        }
                        catch(Exception e)
                        {
                            if(_debug)
                                e.printStackTrace();
                        }
                    }
                    else if(condition.equals("property"))
                    {
                        String property = System.getProperty(st.nextToken());
                        eval=property!=null && property.length()>0;
                    }
                    else if(condition.equals("java"))
                    {
                        String operator=st.nextToken();
                        String version=st.nextToken();
                        ver.parse(version);
                        eval=(operator.equals("<")&&java_version.compare(ver)<0)
                                ||(operator.equals(">")&&java_version.compare(ver)>0)
                                ||(operator.equals("<=")&&java_version.compare(ver)<=0)
                                ||(operator.equals("=<")&&java_version.compare(ver)<=0)
                                ||(operator.equals("=>")&&java_version.compare(ver)>=0)
                                ||(operator.equals(">=")&&java_version.compare(ver)>=0)
                                ||(operator.equals("==")&&java_version.compare(ver)==0)
                                ||(operator.equals("!=")&&java_version.compare(ver)!=0);
                    }
                    else if(condition.equals("nargs"))
                    {
                        String operator=st.nextToken();
                        int number=Integer.parseInt(st.nextToken());
                        eval=(operator.equals("<")&&nargs<number)||(operator.equals(">")&&nargs>number)
                                ||(operator.equals("<=")&&nargs<=number)||(operator.equals("=<")&&nargs<=number)
                                ||(operator.equals("=>")&&nargs>=number)||(operator.equals(">=")&&nargs>=number)
                                ||(operator.equals("==")&&nargs==number)||(operator.equals("!=")&&nargs!=number);
                    }
                    else
                    {
                        System.err.println("ERROR: Unknown condition: "+condition);
                        eval=false;
                    }
                    expression&=not?!eval:eval;
                    not=false;
                }
                
                String file=subject.replace('/',File.separatorChar);
                if(_debug)
                    System.err.println((expression?"T ":"F ")+line+" subject="+subject);
                if(!expression)
                {
                    done.put(file,file);
                    continue;
                }
                // Handle the subject
                if(subject.indexOf("=")>0)
                {
                    int i=file.indexOf("=");
                    String property=file.substring(0,i);
                    String value=file.substring(i+1);
                    if(_debug)
                        System.err.println("  "+property+"="+value);
                    System.setProperty(property,value);
                }
                else if(subject.endsWith("/*"))
                {
                    // directory of JAR files
                    File extdir=new File(file.substring(0,file.length()-1));
                    File[] jars=extdir.listFiles(new FilenameFilter()
                    {
                        public boolean accept(File dir,String name)
                        {
                            String namelc=name.toLowerCase();
                            return namelc.endsWith(".jar")||name.endsWith(".zip");
                        }
                    });
                    for(int i=0;jars!=null&&i<jars.length;i++)
                    {
                        String jar=jars[i].getCanonicalPath();
                        if(!done.containsKey(jar))
                        {
                            done.put(jar,jar);
                            boolean added=_classpath.addComponent(jar);
                            if(_debug)
                                System.err.println((added?"  CLASSPATH+=":"  !")+jar);
                        }
                    }
                }
                else if(subject.endsWith("/"))
                {
                    // class directory
                    File cd=new File(file);
                    String d=cd.getCanonicalPath();
                    if(!done.containsKey(d))
                    {
                        done.put(d,d);
                        boolean added=_classpath.addComponent(d);
                        if(_debug)
                            System.err.println((added?"  CLASSPATH+=":"  !")+d);
                    }
                }
                else if(subject.toLowerCase().endsWith(".xml"))
                {
                    // Config file
                    File f=new File(file);
                    if(f.exists())
                        _xml.add(f.getCanonicalPath());
                    if(_debug)
                        System.err.println("  ARGS+="+f);
                }
                else if(subject.toLowerCase().endsWith(".class"))
                {
                    // Class
                    String cn=expand(subject.substring(0,subject.length()-6));
                    if(cn!=null&&cn.length()>0)
                    {
                        if(_debug)
                            System.err.println("  CLASS="+cn);
                        _classname=cn;
                    }
                }
                else if (subject!=null && subject.length()>0)
                {
                    // single JAR file
                    File f=new File(file);
                    String d=f.getCanonicalPath();
                    if(!done.containsKey(d))
                    {
                        done.put(d,d);
                        boolean added=_classpath.addComponent(d);
                        if(!added)
                        {
                            added=_classpath.addClasspath(expand(subject));
                            if(_debug)
                                System.err.println((added?"  CLASSPATH+=":"  !")+d);
                        }
                        else if(_debug)
                            System.err.println((added?"  CLASSPATH+=":"  !")+d);
                    }
                }
            }
            catch(Exception e)
            {
                System.err.println("on line: '"+line+"'");
                e.printStackTrace();
            }
        }
    }
812622
public static String applyFromInputStream(InputStream is) throws ConverterException {		
		String xml = converters.get(0).convertFromInputStream(is, false);						
		xml = applyFromSecond(xml);
		if (conversionDone()) {
			return converters.get(converters.size()-1).changeVersion(xml);
		} else {
			return xml;
		}
	}
435856
public void setInput(int index, InputStream is) {
        if (index >= inputStreams.length) {
            inputStreams = Arrays.copyOf(inputStreams, index + 1);
        }
        this.inputStreams[index] = is;
    }
1196439
@SuppressWarnings("unchecked")
  public static void init(boolean mustLog) {
    if ((hasToLog == null || hasToLog != mustLog) && mustLog) {
      synchronized (LoggerFactory.class) {
        if (hasToLog == null || hasToLog != mustLog) {
          try {
            Class.forName("org.slf4j.LoggerFactory");
            hasToLog = Boolean.TRUE;
          } catch (ClassNotFoundException classNotFound) {
            System.out.println("Logging cannot be activated, missing slf4j dependency");
            hasToLog = Boolean.FALSE;
          }
        }
      }
    }

  }
1314074
@Override
	public void configure(final LoggerContext loggerContext) {
		addInfo("Setting up custom configuration.");
		final LoggerContext context = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();
		final JoranConfigurator jc = new JoranConfigurator();
		jc.setContext(context);
		context.reset();
		context.putProperty("application-name", appName);
		openStream(jc);
	}
192165
public void init(InputStream is, OutputStream os, boolean isClient)
    {
        this.is = is;
        this.os = os;
        this.isClient = isClient;
    }
929669
public static void reconfigure(InputStream config) {
        if (CONTEXT == null) {
            log.warn("当前日志上下文不是logback，不能使用该配置器重新配置");
            return;
        }
        reconfigure(config, CONTEXT);
    }
636292
public ConfigBase fromXml(final InputStream is,
                            final Class cl) throws ConfigException {
    try {
      return fromXml(parseXml(is), cl);
    } catch (final ConfigException ce) {
      throw ce;
    } catch (final Throwable t) {
      throw new ConfigException(t);
    }
  }
1320943
private void configureDirectToConsoleLoggers(LoggerContext context, String... loggerNames) {
    RootLoggerConfig config = newRootLoggerConfigBuilder()
      .setProcessId(ProcessId.APP)
      .setThreadIdFieldPattern("")
      .build();
    String logPattern = helper.buildLogPattern(config);
    ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(context, "CONSOLE", logPattern);

    for (String loggerName : loggerNames) {
      Logger consoleLogger = context.getLogger(loggerName);
      consoleLogger.setAdditive(false);
      consoleLogger.addAppender(consoleAppender);
    }
  }
600480
private boolean hasSlf4jBinding(File file) throws MojoExecutionException {
        try (JarFile jarFile = new JarFile(file)){
            return jarFile.getEntry("org/slf4j/impl/StaticLoggerBinder.class") != null;
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
1303959
public static void configureLog4J() {
        String log4jConf = System.getProperty("log4j.configuration");
        if (null != log4jConf) {
            PropertyConfigurator.configure(log4jConf);
        } else {
            System.err.println("No log4j.configuration property specified. Using defaults.");
            BasicConfigurator.configure();
        }
    }
41121
public void configureForSubprocessGobbler(Props props, String logPattern) {
    if (isAllLogsToConsoleEnabled(props)) {
      LoggerContext ctx = getRootContext();
      ctx.getLogger(ROOT_LOGGER_NAME).addAppender(newConsoleAppender(ctx, "root_console", logPattern));
    }
  }