Java 类ch.qos.logback.core.util.StatusPrinter 实例源码

项目:CampusHelp    文件:LogBackConfigLoader.java   
public static void load(String externalConfigFileLocation) throws IOException, JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

    File externalConfigFile = new File(externalConfigFileLocation);
    if (!externalConfigFile.exists()) {
        throw new IOException("Logback External Config File Parameter does not reference a file that exists");
    } else {
        if (!externalConfigFile.isFile()) {
            throw new IOException("Logback External Config File Parameter exists, but does not reference a file");
        } else {
            if (!externalConfigFile.canRead()) {
                throw new IOException("Logback External Config File exists and is a file, but cannot be read.");
            } else {
                JoranConfigurator configurator = new JoranConfigurator();
                configurator.setContext(lc);
                lc.reset();
                configurator.doConfigure(externalConfigFileLocation);
                StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
            }
        }
    }
}
项目:graviteeio-access-management    文件:Container.java   
private void initializeLogging() {
    String graviteeHome = System.getProperty("gravitee.home");
    String logbackConfiguration = graviteeHome + File.separator + "config" + File.separator + "logback.xml";
    File logbackConfigurationfile = new File(logbackConfiguration);

    // If logback configuration available, load it, else, load default logback configuration
    if (logbackConfigurationfile.exists()) {
        System.setProperty("logback.configurationFile", logbackConfigurationfile.getAbsolutePath());
        StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton();
        LoggerContext loggerContext = (LoggerContext) loggerBinder.getLoggerFactory();
        loggerContext.reset();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        try {
            configurator.doConfigure(logbackConfigurationfile);
        } catch( JoranException e ) {
            e.printStackTrace();
        }

        // Internal status data is printed in case of warnings or errors.
        StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
    }
}
项目:konker-platform    文件:KonkerStaticLoggerBinder.java   
void init() {
    try {
        try {
            (new KonkerContextInitializer(this.defaultLoggerContext)).autoConfig();
        } catch (JoranException var2) {
            Util.report("Failed to auto configure default logger context", var2);
        }

        if(!StatusUtil.contextHasStatusListener(this.defaultLoggerContext)) {
            StatusPrinter.printInCaseOfErrorsOrWarnings(this.defaultLoggerContext);
        }

        this.contextSelectorBinder.init(this.defaultLoggerContext, KEY);
        this.initialized = true;
    } catch (Throwable var3) {
        Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", var3);
    }

}
项目:acme_client    文件:Application.java   
private static void configureLogger(String logDir, String logLevel, String logbackConf) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        context.reset();
        if (!logDir.endsWith(File.separator))
            logDir+= File.separator;
        context.putProperty("LOG_DIR", logDir);
        context.putProperty("LOG_LEVEL", logLevel);

        InputStream is = classloader.getResourceAsStream(logbackConf);
        configurator.doConfigure(is);
    } catch (JoranException je) {
        LOG.warn("Cannot configure logger. Continue to execute the command.", je);
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
项目:common-libraries    文件:ImprovedAuditorFactory.java   
static void checkSanity(Auditor auditor) throws AuditException {
    StatusManager sm = auditor.getStatusManager();

    if (getHighestLevel(0, sm) > Status.INFO) {
        StatusPrinter.print(sm);
    }

    if (auditor.getClientApplication() == null) {
        throw new AuditException("Client application has not been set");
    }

    if (auditor.getAuditAppender() == null) {
        throw new AuditException("No audit appender. Please see "
                + NULL_AUDIT_APPENDER_URL);
    }
}
项目:TranskribusSwtGui    文件:GuiUtil.java   
private static void configureLogbackFromLocalFile() {
    boolean localLogFileExists = Files.exists(Paths.get("./logback.xml"));
    if (!localLogFileExists) {
        System.out.println("logback.xml not found in local path - defaulting to packaged one");
        return;
    }

    // assume SLF4J is bound to logback in the current environment
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {
      JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(context);
      // Call context.reset() to clear any previous configuration, e.g. default 
      // configuration. For multi-step configuration, omit calling context.reset().
      context.reset();
      configurator.doConfigure("./logback.xml");
    } catch (JoranException je) {
      // StatusPrinter will handle this
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);       

}
项目:waltz    文件:LoggingUtilities.java   
public static void configureLogging() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        context.reset();
        configurator.setContext(context);
        System.out.println("Attempting to load logback configuration file: " + LOG_CONFIG_FILE_NAME
                            + " from classpath or " + System.getProperty("user.home") + "/.waltz/");

        Resource logbackConfigFile = IOUtilities.getFileResource(LOG_CONFIG_FILE_NAME);
        if (logbackConfigFile.exists()) {
            System.out.println("Found logback configuration file at: " + logbackConfigFile.getFile().getAbsolutePath());
            configurator.doConfigure(logbackConfigFile.getFile());
        } else {
            System.out.println("Logback configuration file not found..");
        }
    } catch (IOException | JoranException e) {
        // StatusPrinter will handle this
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
项目:gravitee-management-rest-api    文件:Container.java   
private void initializeLogging() {
    String graviteeHome = System.getProperty("gravitee.home");
    String logbackConfiguration = graviteeHome + File.separator + "config" + File.separator + "logback.xml";
    File logbackConfigurationfile = new File(logbackConfiguration);

    // If logback configuration available, load it, else, load default logback configuration
    if (logbackConfigurationfile.exists()) {
        System.setProperty("logback.configurationFile", logbackConfigurationfile.getAbsolutePath());
        StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton();
        LoggerContext loggerContext = (LoggerContext) loggerBinder.getLoggerFactory();
        loggerContext.reset();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        try {
            configurator.doConfigure(logbackConfigurationfile);
        } catch( JoranException e ) {
            e.printStackTrace();
        }

        // Internal status data is printed in case of warnings or errors.
        StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
    }
}
项目:gravitee-gateway    文件:Container.java   
private void initializeLogging() {
    String graviteeHome = System.getProperty("gravitee.home");
    String logbackConfiguration = graviteeHome + File.separator + "config" + File.separator + "logback.xml";
    File logbackConfigurationfile = new File(logbackConfiguration);

    // If logback configuration available, load it, else, load default logback configuration
    if (logbackConfigurationfile.exists()) {
        System.setProperty("logback.configurationFile", logbackConfigurationfile.getAbsolutePath());
        StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton();
        LoggerContext loggerContext = (LoggerContext) loggerBinder.getLoggerFactory();
        loggerContext.reset();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        try {
            configurator.doConfigure(logbackConfigurationfile);
        } catch( JoranException e ) {
            LoggerFactory.getLogger(Container.class).error("An error occurs while initializing logging system", e);
        }

        // Internal status data is printed in case of warnings or errors.
        StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
    }
}
项目:bartleby    文件:RollingFileAppenderTest.java   
@Test
public void stopTimeBasedRollingPolicy() {
  rfa.setContext(context);

  tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log.zip");
  tbrp.start();
  rfa.setRollingPolicy(tbrp);
  rfa.start();

  StatusPrinter.print(context);
  assertTrue(tbrp.isStarted());
  assertTrue(rfa.isStarted());
  rfa.stop();
  assertFalse(rfa.isStarted());
  assertFalse(tbrp.isStarted());

}
项目:bartleby    文件:TimeBasedRollingTest.java   
@Test
public void failed_rename() throws IOException {
  if (!EnvUtilForTests.isWindows())
    return;

  FileOutputStream fos = null;
  try {
    String fileName = testId2FileName("failed_rename");
    File file = new File(fileName);
    file.getParentFile().mkdirs();

    fos = new FileOutputStream(fileName);

    String testId = "failed_rename";
    rolloverChecker = new ZRolloverChecker(testId);
    genericTest(testId, "failed_rename", "", FILE_OPTION_SET, NO_RESTART);


  } finally {
    StatusPrinter.print(context);
    if (fos != null) fos.close();
  }
}
项目:subshare    文件:SubShareGui.java   
private static void initLogging() throws IOException, JoranException {
    final File logDir = ConfigDir.getInstance().getLogDir();
    DerbyUtil.setLogFile(createFile(logDir, "derby.log"));

    final String logbackXmlName = "logback.client.xml";
    final File logbackXmlFile = createFile(ConfigDir.getInstance().getFile(), logbackXmlName);
    if (!logbackXmlFile.exists()) {
        AppIdRegistry.getInstance().copyResourceResolvingAppId(
                SubShareGui.class, logbackXmlName, logbackXmlFile);
    }

    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
      final JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(context);
      // Call context.reset() to clear any previous configuration, e.g. default
      // configuration. For multi-step configuration, omit calling context.reset().
      context.reset();
      configurator.doConfigure(logbackXmlFile.getIoFile());
    } catch (final JoranException je) {
        // StatusPrinter will handle this
        doNothing();
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
项目:bartleby    文件:FruitConfigurationTest.java   
public List<FruitShell> doFirstPart(String filename) throws Exception {

    try {
      HashMap<ElementSelector, Action> rulesMap = new HashMap<ElementSelector, Action>();
      rulesMap.put(new ElementSelector("group/fruitShell"), new FruitShellAction());
      rulesMap.put(new ElementSelector("group/fruitShell/fruit"),
          new FruitFactoryAction());
      rulesMap.put(new ElementSelector("group/fruitShell/fruit/*"), new NOPAction());
      SimpleConfigurator simpleConfigurator = new SimpleConfigurator(rulesMap);

      simpleConfigurator.setContext(fruitContext);

      simpleConfigurator.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/replay/"
          + filename);

      return fruitContext.getFruitShellList();
    } catch (Exception je) {
      StatusPrinter.print(fruitContext);
      throw je;
    }
  }
项目:Telemarketer    文件:Context.java   
private static boolean loadLogConfiguration() { // TODO 抽离加载配置的方法 使系统统一扫描加载
    String logConfigurationPath = System.getProperty("logback.configurationFile");
    if (StringUtils.isBlank(logConfigurationPath)) {
        logConfigurationPath = "conf/logback-tele.xml";
    }
    URL configPath = ClassLoader.getSystemResource(logConfigurationPath);
    if (configPath == null) {
        System.err.println("无可用日志配置,将使用缺省配置");
        return true;
    }
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    try {
        configurator.doConfigure(configPath);
        StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
    } catch (JoranException e) {
        System.err.println("配置日志配置出错");
        return false;
    }
    return true;
}
项目:bartleby    文件:StaticLoggerBinder.java   
/**
 * Package access for testing purposes.
 */
void init() {
  try {
    try {
      new ContextInitializer(defaultLoggerContext).autoConfig();
    } catch (JoranException je) {
      Util.report("Failed to auto configure default logger context", je);
    }
    // logback-292
    if(!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
      StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
    }
    contextSelectorBinder.init(defaultLoggerContext, KEY);
    initialized = true;
  } catch (Throwable t) {
    // we should never get here
    Util.report("Failed to instantiate [" + LoggerContext.class.getName()
        + "]", t);
  }
}
项目:bartleby    文件:JMXConfigurator.java   
public void reloadByURL(URL url) throws JoranException {
  StatusListenerAsList statusListenerAsList = new StatusListenerAsList();

  addStatusListener(statusListenerAsList);
  addInfo("Resetting context: " + loggerContext.getName());
  loggerContext.reset();
  // after a reset the statusListenerAsList gets removed as a listener
  addStatusListener(statusListenerAsList);

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);
    configurator.doConfigure(url);
    addInfo("Context: " + loggerContext.getName() + " reloaded.");
  } finally {
    removeStatusListener(statusListenerAsList);
    if (debug) {
      StatusPrinter.print(statusListenerAsList.getStatusList());
    }
  }
}
项目:bartleby    文件:Activator.java   
public void start(BundleContext context) {
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    // the context was probably already configured by default configuration 
    // rules
    lc.reset(); 
    configurator.doConfigure("src/test/input/osgi/simple.xml");
  } catch (JoranException je) {
     je.printStackTrace();
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(lc);


  Logger logger = LoggerFactory.getLogger(this.getClass());
  logger.info("Activator.start()");
  m_context = context;
}
项目:bartleby    文件:SafeModeRollingFileAppender.java   
static void writeContinously(String stamp, String filename, boolean safetyMode)
    throws Exception {
  LoggerContext lc = buildLoggerContext(stamp, filename, safetyMode);
  Logger logger = lc.getLogger(SafeModeRollingFileAppender.class);

  long before = System.nanoTime();
  for (int i = 0; i < LEN; i++) {
    logger.debug(LoggingThread.msgLong + " " + i);
  }
  lc.stop();
  StatusPrinter.print(lc);
  double durationPerLog = (System.nanoTime() - before) / (LEN * 1000.0);

  System.out.println("Average duration of " + (durationPerLog)
      + " microseconds per log. Safety mode " + safetyMode);
  System.out.println("------------------------------------------------");
}
项目:members_cuacfm    文件:ApplicationConfig.java   
/**
 * Change log back.
 *
 * @param pathConfig the path config
 * @param atribute the atribute
 */
private static void changeLogBack(String pathConfig, String atribute) {
    // Assume SLF4J is bound to logback in the current environment
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {
        File config = new File(pathConfig + properties.getProperty(atribute));
        if (config.exists()) {
            JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            // Call context.reset() to clear any previous configuration, e.g. default
            context.reset();
            configurator.doConfigure(config);
        }
    } catch (Exception e) {
        logger.error("changeLogBack " + atribute, e);
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
项目:bartleby    文件:Lbcore211.java   
@Test
public void lbcore211() throws JoranException {

  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  JoranConfigurator configurator = new JoranConfigurator();
  configurator.setContext(lc);
  lc.reset();
  configurator.doConfigure("/home/ceki/lbcore211.xml");

  Logger l = lc.getLogger("file.logger");
  StatusPrinter.print(lc);
  for (int i = 0; i < 10; i++) {
    l.info("hello " + i);
  }

  lc.stop();
}
项目:bartleby    文件:SiftingAppenderTest.java   
@Test
public void zeroNesting() throws JoranException {
  configure(SIFT_FOLDER_PREFIX + "zeroNesting.xml");
  logger.debug("hello");
  logger.debug("hello");
  logger.debug("hello");
  logger.debug("hello");
  logger.debug("hello");
  SiftingAppender sa = (SiftingAppender) root.getAppender("SIFT");

  Appender<ILoggingEvent> appender = getAppenderTracker().find("zeroDefault");
  assertNotNull(appender);
  NOPAppender<ILoggingEvent> nopa = (NOPAppender<ILoggingEvent>) appender;
  StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);

  statusChecker.assertContainsMatch(ErrorStatus.ERROR, "No nested appenders found");
}
项目:bartleby    文件:MyAppWithConfigFile.java   
public static void main(String[] args) {
  Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    lc.reset();
    configurator.setContext(lc);
    configurator.doConfigure(args[0]);
  } catch (JoranException je) {
    StatusPrinter.print(lc.getStatusManager());
  }
  logger.info("Entering application.");
  Bar bar = new Bar();
  bar.doIt();
  logger.info("Exiting application.");

}
项目:bartleby    文件:TrivialMain.java   
public static void main(String[] args) throws InterruptedException {
  Logger logger = LoggerFactory.getLogger(TrivialMain.class);
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(args[0]);
  } catch (JoranException je) {
    // StatusPrinter will handle this
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

  for (int i = 0; i < 6; i++) {
    if (i % 5 == 0) {
      logger.warn("a warning message " + i);
    } else if(i % 3 == 0) {
      logger.info("hello world number" + i);
    } else {
      logger.debug("hello world number" + i);
    }
  }
  logger.error("Finish off with fireworks", new Exception("Just testing"));
}
项目:bartleby    文件:ExceptionEvaluatorExample.java   
public static void main(String[] args) {
  Logger logger = LoggerFactory.getLogger(ExceptionEvaluatorExample.class);
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(args[0]);
  } catch (JoranException je) {
    // StatusPrinter will handle this
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

  for (int i = 0; i < 3; i++) {
    if (i == 1) {
      logger.debug("logging statement " + i, new TestException(
          "do not display this"));
    } else {
      logger.debug("logging statement " + i, new Exception("display"));
    }
  }
}
项目:bartleby    文件:CallerEvaluatorExample.java   
public static void main(String[] args) {
  Logger logger = LoggerFactory.getLogger(CallerEvaluatorExample.class);
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(args[0]);
  } catch (JoranException je) {
    // StatusPrinter will handle this
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

  for (int i = 0; i < 5; i++) {
    if (i == 3) {
      logger.debug("who calls thee?");
    } else {
      logger.debug("I know me " + i);
    }
  }
}
项目:bartleby    文件:SampleLogging.java   
public static void main(String[] args) {

    Logger logger = LoggerFactory.getLogger(SampleLogging.class);
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {
      JoranConfigurator configurator = new JoranConfigurator();
      lc.reset();
      configurator.setContext(lc);
      configurator.doConfigure(args[0]);
    } catch (JoranException je) {
      // StatusPrinter will handle this
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

    logger.debug("Everything's going well");
    logger.error("maybe not quite...");
  }
项目:bartleby    文件:MyApp3.java   
public static void main(String[] args) {
  // assume SLF4J is bound to logback in the current environment
  LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    // Call context.reset() to clear any previous configuration, e.g. default
    // configuration. For multi-step configuration, omit calling context.reset().
    context.reset();
    configurator.doConfigure(args[0]);
  } catch (JoranException je) {
    // StatusPrinter will handle this
  }
  StatusPrinter.printInCaseOfErrorsOrWarnings(context);

  logger.info("Entering application.");

  Foo foo = new Foo();
  foo.doIt();
  logger.info("Exiting application.");
}
项目:bartleby    文件:IOPerformance.java   
public IOPerformance(boolean _immediateFlush, long _len) {
  this.len = _len;
  this.immediateFlush = _immediateFlush;
  context = new LoggerContext();
  logger = context.getLogger("logger-" + getName());

  // A FileAppender is created according to the buffering and
  // immediate flush setting of this IO instance.
  FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
  fa.setName("FILE");
  PatternLayoutEncoder pa = new PatternLayoutEncoder();
  pa.setPattern("%r %5p %c [%t] - %m%n");
  pa.setContext(context);
  pa.start();
  fa.setEncoder(pa);

  fa.setFile(LOG_FILE);
  fa.setAppend(true);
  fa.setContext(context);
  fa.start();

  ((ch.qos.logback.classic.Logger) logger).addAppender(fa);

  StatusPrinter.print(context);
}
项目:bartleby    文件:ConfigurationTester.java   
public static void main(String[] args) throws InterruptedException {
  Logger logger = (Logger) LoggerFactory.getLogger(ConfigurationTester.class);
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(args[0]);
  } catch (JoranException je) {
    je.printStackTrace();
  }
  // After we've called Joran, let's print information about the
  // internal status of logback
  StatusPrinter.print(lc);

  logger.debug("**Hello {}", new Bar());
  MDC.put("testKey", "testValueFromMDC");
  MDC.put("testKey2", "value2");
  for (int i = 0; i < 10; i++) {
    logger.debug("logging statement " + i);
    Thread.sleep(100);
  }
  Bar bar = new Bar();
  bar.createLoggingRequest();
}
项目:bartleby    文件:PrintMe.java   
public static void main(String[] args) throws Exception {
  Context context = new ContextBase();

  Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();

  // we start with the rule for the top-most (root) element
  ruleMap.put(new ElementSelector("*/foo"), new NOPAction());

  // Add an implicit action. 
  List<ImplicitAction> iaList = new ArrayList<ImplicitAction>();
  iaList.add(new PrintMeImplicitAction());
  SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap,
      iaList); 

  // link the configurator with its context
  simpleConfigurator.setContext(context);

  simpleConfigurator.doConfigure(args[0]);
  StatusPrinter.printInCaseOfErrorsOrWarnings(context);

}
项目:bartleby    文件:NewRuleCalculator.java   
public static void main(String[] args) throws Exception {

    Context context = new ContextBase();

    Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();

    // we start with the rule for the top-most (root) element
    ruleMap.put(new ElementSelector("*/computation"), new ComputationAction1());

    // Associate "/new-rule" pattern with NewRuleAction from the
    // org.apache.joran.action package.
    // 
    // We will let the XML file to teach the Joran interpreter about new rules
    ruleMap.put(new ElementSelector("/computation/newRule"), new NewRuleAction());

    SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
    // link the configurator with its context
    simpleConfigurator.setContext(context);

    simpleConfigurator.doConfigure(args[0]);

    // Print any errors that might have occured.
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
  }
项目:bartleby    文件:Calculator2.java   
public static void main(String[] args) throws Exception {
  Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();


  // Note the wild card character '*', in the paterns, signifying any level 
  // of nesting.
  ruleMap.put(new ElementSelector("*/computation"), new ComputationAction2());

  ruleMap.put(new ElementSelector("*/computation/literal"), new LiteralAction());
  ruleMap.put(new ElementSelector("*/computation/add"), new AddAction());
  ruleMap.put(new ElementSelector("*/computation/multiply"), new MultiplyAction());

  Context context = new ContextBase();
  SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
  // link the configurator with its context
  simpleConfigurator.setContext(context);

  try {
    simpleConfigurator.doConfigure(args[0]);
  } catch (JoranException e) {
    // Print any errors that might have occured.
    StatusPrinter.print(context);
  }
}
项目:bartleby    文件:Calculator1.java   
public static void main(String[] args) throws Exception {
  Context context = new ContextBase();

  Map<ElementSelector, Action> ruleMap = new HashMap<ElementSelector, Action>();

  // Associate "/computation" pattern with ComputationAction1
  ruleMap.put(new ElementSelector("/computation"), new ComputationAction1());

  // Other associations
  ruleMap.put(new ElementSelector("/computation/literal"), new LiteralAction());
  ruleMap.put(new ElementSelector("/computation/add"), new AddAction());
  ruleMap.put(new ElementSelector("/computation/multiply"), new MultiplyAction());

  SimpleConfigurator simpleConfigurator = new SimpleConfigurator(ruleMap);
  // link the configurator with its context
  simpleConfigurator.setContext(context);

  simpleConfigurator.doConfigure(args[0]);
  // Print any errors that might have occured.
  StatusPrinter.print(context);
}
项目:bartleby    文件:GoMDC.java   
public static void main(String[] args)  {
  Logger logger = LoggerFactory
      .getLogger(GoMDC.class);
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

  try {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure("mdcFilter.xml");

  } catch (JoranException je) {
    StatusPrinter.print(lc);
  }

  logger.debug("I know me " + 0);
  MDC.put("key", "val");
  logger.debug("I know me " + 1);

  StatusPrinter.print(lc);
}
项目:bartleby    文件:SimpleSocketServer.java   
static void init(String portStr, String configFile) throws JoranException {
  try {
    port = Integer.parseInt(portStr);
  } catch (java.lang.NumberFormatException e) {
    e.printStackTrace();
    usage("Could not interpret port number [" + portStr + "].");
  }

  basicContext = new AccessContext();
  if (configFile.endsWith(".xml")) {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(basicContext);
    configurator.doConfigure(configFile);
    StatusPrinter.print(basicContext);
  }
}
项目:bartleby    文件:DBAppenderHSQLTest.java   
@Test
public void testCheckNoHeadersAreInserted() throws Exception {
  setInsertHeadersAndStart(false);

  IAccessEvent event = createAccessEvent();
  appender.append(event);
  StatusPrinter.print(context.getStatusManager());

  //Check that no headers were inserted
  Statement stmt = connectionSource.getConnection().createStatement();
  ResultSet rs = null;
  rs = stmt.executeQuery("SELECT * FROM access_event_header where EVENT_ID = " + existingEventTableRowCount);

  assertFalse(rs.next());
  rs.close();
  stmt.close();
}
项目:bartleby    文件:DBAppenderHSQLTest.java   
@Test
public void testAppendMultipleEvents() throws SQLException {
  setInsertHeadersAndStart(false);
  String uri = "testAppendMultipleEvents";
  for (int i = 0; i < 10; i++) {
    IAccessEvent event = createAccessEvent(uri);
    appender.append(event);
  }

  StatusPrinter.print(context);

  Statement stmt = connectionSource.getConnection().createStatement();
  ResultSet rs = null;
  rs = stmt.executeQuery("SELECT * FROM access_event where requestURI='" + uri + "'");
  int count = 0;
  while (rs.next()) {
    count++;
  }
  assertEquals(10, count);

  rs.close();
  stmt.close();
}
项目:bartleby    文件:DBAppenderIntegrationTest.java   
public void doTest(String configFile) throws JoranException {
  JoranConfigurator configurator = new JoranConfigurator();
  configurator.setContext(context);
  configurator.doConfigure(configFile);

  Appender<IAccessEvent> appender = context.getAppender("DB");

  for (int i = 0; i < 10; i++) {
    IAccessEvent event = DummyAccessEventBuilder.buildNewAccessEvent();
    appender.doAppend(event);
  }

  StatusPrinter.print(context);

  // check that there were no errors
  assertEquals(Status.INFO,  statusChecker.getHighestLevel(0));

}