@Override
  protected void configure(String logFile) {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();
    lc.putProperty("se.trillian.goodies.hostname", getHostName());
    lc.putProperty("se.trillian.goodies.hostname.full", getFullHostName());

    try {
      JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(lc);
      configurator.doConfigure(logFile);
    } catch (JoranException je) {
      StatusPrinter.print(lc);
    }
  }
Beispiel #2
0
  protected TestProtocolServer newTestProtocolServer(URI serverId) {
    LoggerContext loggerContext = new LoggerContext();
    loggerContext.putProperty("host", serverId.toString());

    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);
    try {
      configurator.doConfigure(getClass().getResource("/test-logback.xml"));
    } catch (JoranException e) {
      throw new IllegalStateException("Failed to configure logging", e);
    }

    Logging logging = new LogbackService(null, loggerContext);

    ProtocolServerFactory protocolServerFactory =
        new MultiPaxosServerFactory(new ClusterConfiguration("default"), logging);

    ServerIdElectionCredentialsProvider electionCredentialsProvider =
        new ServerIdElectionCredentialsProvider();
    electionCredentialsProvider.listeningAt(serverId);
    TestProtocolServer protocolServer =
        new TestProtocolServer(
            timeoutStrategy,
            protocolServerFactory,
            serverId,
            new InMemoryAcceptorInstanceStore(),
            electionCredentialsProvider);
    protocolServer.addStateTransitionListener(new StateTransitionLogger(logging));
    return protocolServer;
  }
Beispiel #3
0
  public static void enableLogging(boolean enable) {

    // get the context
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {

      // create a new configurator
      JoranConfigurator configurator = new JoranConfigurator();

      // set context and reset it
      configurator.setContext(loggerContext);
      loggerContext.reset();

      // if logging should be enabled
      if (enable) {

        // add the correct properties and load the XML file
        loggerContext.putProperty("araraLogName", AraraConstants.LOGNAME);
        configurator.doConfigure(
            AraraLogging.class.getResourceAsStream("/com/github/arara/conf/logback.xml"));
      }

    } catch (JoranException joranException) {
      // do nothing
    }
  }
  @Test
  public void contextProperty() {
    pl.setPattern("%property{a}");
    pl.start();
    lc.putProperty("a", "b");

    String val = pl.doLayout(getEventObject());
    assertEquals("b", val);
  }
  public static LoggerContext buildLoggerContext(Map<String, String> props) {
    if (loggerContext == null) {
      ILoggerFactory lcObject = LoggerFactory.getILoggerFactory();

      if (!(lcObject instanceof LoggerContext)) {
        throw new LogbackException(
            "Expected LOGBACK binding with SLF4J, but another log system has taken the place: "
                + lcObject.getClass().getSimpleName());
      }

      loggerContext = (LoggerContext) lcObject;
      if (props != null) {
        for (Map.Entry<String, String> entry : props.entrySet()) {
          loggerContext.putProperty(entry.getKey(), entry.getValue());
        }
      }
    }

    return loggerContext;
  }
Beispiel #6
0
  @SuppressWarnings("rawtypes")
  @Test
  public void conditionalConsoleApp_IF_THEN_True()
      throws JoranException, IOException, InterruptedException {
    InetAddress localhost = InetAddress.getLocalHost();
    System.out.println(
        "In conditionalConsoleApp_IF_THEN_True, canonicalHostName=\""
            + localhost.getCanonicalHostName()
            + "] and hostNmae=\""
            + localhost.getHostName()
            + "\"");
    context.putProperty("aHost", localhost.getHostName());

    String configFileAsStr =
        ClassicTestConstants.JORAN_INPUT_PREFIX + "conditional/conditionalConsoleApp.xml";
    configure(configFileAsStr);
    FileAppender fileAppender = (FileAppender) root.getAppender("FILE");
    assertNotNull(fileAppender);

    ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
    assertNotNull(consoleAppender);
    StatusChecker checker = new StatusChecker(context);
    checker.assertIsErrorFree();
  }
  @Test
  public void testContextInfo() throws SQLException {
    lc.putProperty("testKey1", "testValue1");
    MDC.put("k" + diff, "v" + diff);
    ILoggingEvent event = createLoggingEvent();

    appender.append(event);

    Statement stmt = connectionSource.getConnection().createStatement();
    ResultSet rs = null;
    rs = stmt.executeQuery("SELECT * FROM LOGGING_EVENT_PROPERTY  WHERE EVENT_ID = 0");
    Map<String, String> map = appender.mergePropertyMaps(event);
    System.out.println("ma.size=" + map.size());
    int i = 0;
    while (rs.next()) {
      String key = rs.getString(2);
      assertEquals(map.get(key), rs.getString(3));
      i++;
    }
    assertTrue(map.size() != 0);
    assertEquals(map.size(), i);
    rs.close();
    stmt.close();
  }
 private void configure(String file) throws JoranException {
   JoranConfigurator jc = new JoranConfigurator();
   jc.setContext(loggerContext);
   loggerContext.putProperty("port", "" + port);
   jc.doConfigure(file);
 }
Beispiel #9
0
 @Before
 public void setUp() throws UnknownHostException {
   context.setName("c" + diff);
   context.putProperty("randomOutputDir", randomOutputDir);
 }