Package ch.qos.logback.classic

Examples of ch.qos.logback.classic.Logger


    appender.setContext(lc);
    appender.setIncludeCallerData(true);
    appender.setRemoteHost("localhost");
    appender.setPort(port.intValue());
    appender.start();
    Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
    root.addAppender(appender);
   
    addInfo("Sending LoggingEvents to the plugin using port " + port);
  }
View Full Code Here


  // System.err.flush();
  // }

  public void run() {
    ILoggingEvent event;
    Logger remoteLogger;

    try {
      while (!closed) {
        // read an event from the wire
        event = (ILoggingEvent) ois.readObject();
        // get a logger from the hierarchy. The name of the logger is taken to
        // be the name contained in the event.
        remoteLogger = context.getLogger(event.getLoggerName());
        // apply the logger-level filter
        if (remoteLogger.isEnabledFor(event.getLevel())) {
          // finally log the event as if was generated locally
          remoteLogger.callAppenders(event);
        }
      }
    } catch (java.io.EOFException e) {
      logger.info("Caught java.io.EOFException closing connection.");
    } catch (java.net.SocketException e) {
View Full Code Here

    ILoggingEvent event;
    try {
      if (message instanceof ObjectMessage) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        event = (ILoggingEvent) objectMessage.getObject();
        Logger log = (Logger) LoggerFactory.getLogger(event.getLoggerName());
        log.callAppenders(event);
      } else {
        logger.warn("Received message is of type " + message.getJMSType()
            + ", was expecting ObjectMessage.");
      }
    } catch (JMSException jmse) {
View Full Code Here

    OutputStream os = new FileOutputStream("exitWoes1.log");
    writerAppender.setWriter(new OutputStreamWriter(os));
    writerAppender.setImmediateFlush(false);
    writerAppender.start();
    Logger root = lc.getLogger(LoggerContext.ROOT_NAME);
    root.addAppender(writerAppender);

    Logger logger = lc.getLogger(ExitWoes1.class);

    logger.debug("Hello world.");
  }
View Full Code Here

        assertEquals(testThreads.length * TestLoggingThread.STOP_WATCH_COUNT, totalCount);
    }
   
    public void testOverflowHandling() throws Exception {
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        Logger logger = lc.getLogger("AppenderTest.overflowTest");
        AsyncCoalescingStatisticsAppender appender = new AsyncCoalescingStatisticsAppender();
        appender.setName("overflowTestAppender");
        appender.setTimeSlice(1000);
        appender.setQueueSize(2); //set low queue size so we overflow
        logger.addAppender(appender);
        logger.setAdditive(false);
        logger.setLevel(Level.INFO);
        appender.start();

        for (int i = 0; i < 1000; i++) {
            StopWatch stopWatch = new StopWatch("testOverflow");
            Math.random(); //this should happen super fast, faster than the appender's Dispatcher thread can drain
            logger.info(stopWatch.stop());
        }

        //again close the appender
        appender.stop();
        assertTrue("Expected some stop watch messages to get discarded", appender.getNumDiscardedMessages() > 0);
View Full Code Here

        // the context was probably already configured by default configuration
        // rules
        lc.reset();
        configurator.doConfigure(getClass().getResource("logbackWCsv.xml"));

        Logger logger = lc.getLogger("org.perf4j.CsvAppenderTest");

        for (int i = 0; i < 20; i++) {
            StopWatch stopWatch = new Slf4JStopWatch(logger);
            Thread.sleep(i * 10);
            stopWatch.stop("csvTest");
        }

        //close the appender
        logger.getAppender("coalescingStatistics").stop();

        //verify the statisticsLog.csv file
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Object line : FileUtils.readLines(new File(
                "./target/statisticsLogback.csv"))) {
View Full Code Here

  }
 
  @Test
  public void test_updateConfig(){
    LogbackConfigManager logbackConfigManager = new LogbackConfigManager(Mockito.mock(MonitoringLogbackDataProvider.class));
    Logger root1 = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root1.setLevel(Level.INFO);
    assertEquals(Level.INFO, root1.getLevel());
    logbackConfigManager.updateLogConfig(
        "<configuration scan=\"true\" scanPeriod=\"15 seconds\">\r\n" +
        "  <appender name=\"CONSOLE\" class=\"ch.qos.logback.core.ConsoleAppender\">\r\n" +
        "     <layout class=\"ch.qos.logback.classic.PatternLayout\">\r\n" +
        "      <Pattern>%d{HH:mm:ss.SSS} [%thread] %.-1level %logger{36} - %msg%n</Pattern>\r\n" +
        "    </layout>\r\n" +
        "  </appender>\r\n" +
        " \r\n" +
        "  <root level=\"DEBUG\">\r\n" +
        "    <appender-ref ref=\"CONSOLE\" />\r\n" +
        "  </root>\r\n" +
        "</configuration>");
    Logger root2 = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    assertEquals(Level.DEBUG, root2.getLevel());
  }
View Full Code Here

  }
 
 
  public void assertLogContent(LogContentAssertion logContentAssertion){
    final ArrayList<MessageAndLogLevel> log = new ArrayList<MessageAndLogLevel>();
    Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    AppenderBase<ILoggingEvent> appender = new AppenderBase<ILoggingEvent>() {

      @Override
      protected void append(ILoggingEvent event) {
        log.add(new MessageAndLogLevel(event.getFormattedMessage(),event.getLevel()));
      }
    };
    appender.start();
    root.addAppender(appender);
    logContentAssertion.executeLogCreatingAction();
    logContentAssertion.assertLogContent(log);
    root.detachAppender(appender);
  }
View Full Code Here

   
    this.setName(APPENDER_NAME);
  }

  public void addToRootLogger() {
    Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    setContext(root.getLoggerContext());
    root.addAppender(this);
    start();
  }
View Full Code Here

    start();
  }
 
  public void removeFromRootLogger() {
    stop();
    Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    setContext(root.getLoggerContext());
    root.detachAppender(this);
  }
View Full Code Here

TOP

Related Classes of ch.qos.logback.classic.Logger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.