Java 类ch.qos.logback.classic.gaffer.GafferUtil 实例源码

项目:bartleby    文件:ReconfigureOnChangeFilter.java   
public void run() {
  if (mainConfigurationURL == null) {
    addInfo("Due to missing top level configuration file, skipping reconfiguration");
    return;
  }
  LoggerContext lc = (LoggerContext) context;
  addInfo(CoreConstants.RESET_MSG_PREFIX + "named [" + context.getName() + "]");
  if (mainConfigurationURL.toString().endsWith("xml")) {
    performXMLConfiguration(lc);
  } else if (mainConfigurationURL.toString().endsWith("groovy")) {
    if (EnvUtil.isGroovyAvailable()) {
      lc.reset();
      // avoid directly referring to GafferConfigurator so as to avoid
      // loading  groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214
      GafferUtil.runGafferConfiguratorOn(lc, this, mainConfigurationURL);
    } else {
      addError("Groovy classes are not available on the class path. ABORTING INITIALIZATION.");
    }
  }
}
项目:bartleby    文件:ContextInitializer.java   
public void configureByResource(URL url) throws JoranException {
  if (url == null) {
    throw new IllegalArgumentException("URL argument cannot be null");
  }
  final String urlString = url.toString();
  if (urlString.endsWith("groovy")) {
    if (EnvUtil.isGroovyAvailable()) {
      // avoid directly referring to GafferConfigurator so as to avoid
      // loading  groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214
      GafferUtil.runGafferConfiguratorOn(loggerContext, this, url);
    } else {
      StatusManager sm = loggerContext.getStatusManager();
      sm.add(new ErrorStatus("Groovy classes are not available on the class path. ABORTING INITIALIZATION.",
              loggerContext));
    }
  } else if (urlString.endsWith("xml")) {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);
    configurator.doConfigure(url);
  } else {
    throw new LogbackException("Unexpected filename extension of file [" + url.toString() + "]. Should be either .groovy or .xml");
  }
}
项目:ameba    文件:Application.java   
/**
 * 设置日志器
 */
private void configureLogger(Properties properties) {
    //set logback config file
    URL loggerConfigFile = getResource("conf/logback_" + getMode().name().toLowerCase() + ".groovy");

    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    context.putObject("properties", properties);

    if (loggerConfigFile != null) {
        GafferUtil.runGafferConfiguratorOn(context, this, loggerConfigFile);
    }

    URL userLoggerConfigFile = getResource(StringUtils.defaultIfBlank(
            properties.getProperty("logger.config.file"), "conf/" + DEFAULT_LOGBACK_CONF));

    if (userLoggerConfigFile != null) {
        GafferUtil.runGafferConfiguratorOn(context, this, userLoggerConfigFile);
    }

    if (ids != null && ids.length > 0) {

        String confDir = "conf/log/";
        String[] logConf = DEFAULT_LOGBACK_CONF.split("\\.");
        String logConfPrefix = logConf[0];
        String logConfSuffix = "." + logConf[1];

        for (String id : ids) {
            URL configFile = getResource(confDir + logConfPrefix + "_" + id + logConfSuffix);
            if (configFile != null)
                GafferUtil.runGafferConfiguratorOn(context, this, configFile);
        }
    }

    //java.util.logging.Logger proxy
    java.util.logging.Logger rootLogger = LogManager.getLogManager().getLogger("");
    Handler[] handlers = rootLogger.getHandlers();
    for (Handler handler : handlers) {
        rootLogger.removeHandler(handler);
    }
    SLF4JBridgeHandler.install();
    rootLogger.setLevel(Level.ALL);

    String appPackage = properties.getProperty("app.package");
    if (StringUtils.isBlank(appPackage)) {
        logger.warn(Messages.get("warn.app.package.not.config"));
    }
}