Exemplo n.º 1
0
  private static void initialize() {
    if (initialized) {
      return;
    }
    try {
      logger = Logger.getLogger("SE450");
      HTMLLayout layout = new HTMLLayout();
      layout.setTitle("Application Log File");
      FileOutputStream output = new FileOutputStream("AppLogFile.html");

      // Create the first Appender - for HTML file output
      WriterAppender htmlFileAppender = new WriterAppender(layout, output);
      String pattern = "%d{ISO8601}  %-5p %m %n";
      PatternLayout layout2 = new PatternLayout(pattern);

      // Create the second Appender - for Console file output
      ConsoleAppender consoleAppender = new ConsoleAppender(layout2);

      logger.addAppender(consoleAppender);
      logger.addAppender(htmlFileAppender);

    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.exit(0);
    }
    initialized = true;
  }
  static {
    new SystemEnvironment().setProperty(GoConstants.USE_COMPRESSED_JAVASCRIPT, "false");
    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    try {
      Filter filter =
          new Filter() {
            @Override
            public int decide(LoggingEvent loggingEvent) {
              return loggingEvent.getLoggerName().startsWith("com.thoughtworks.go.util.PerfTimer")
                      || loggingEvent
                          .getLoggerName()
                          .startsWith(
                              "com.thoughtworks.go.server.service.PipelineConfigServicePerformanceTest")
                  ? 0
                  : -1;
            }
          };
      ConsoleAppender consoleAppender =
          new ConsoleAppender(new PatternLayout("%d [%p|%c|%C{1}] %m%n"));
      consoleAppender.addFilter(filter);
      consoleAppender.setName(consoleAppenderForPerformanceTest);

      RollingFileAppender rollingFileAppender =
          new RollingFileAppender(
              new PatternLayout("%d [%p|%c|%C{1}] %m%n"), "/tmp/config-save-perf.log", false);
      rollingFileAppender.addFilter(filter);
      rollingFileAppender.setName(rollingFileAppenderForPerformanceTest);
      rootLogger.addAppender(rollingFileAppender);
      rootLogger.addAppender(consoleAppender);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Test
  public void appenderTest() {
    final CountingAppender appender = new CountingAppender();
    final StringAppender stringAppender = new StringAppender();

    log4jLogger.addAppender(appender);
    log4jLogger.addAppender(stringAppender);
    log4jLogger.info(MESSAGE);

    org.jboss.logging.Logger.getLogger(getClass()).info(JBL_MESSAGE);
    java.util.logging.Logger.getLogger(getClass().getName()).info(JUL_MESSAGE);

    final String stringFormat = "This is a %s format test.";
    org.jboss.logging.Logger.getLogger(getClass()).infof(stringFormat, "string");

    final String msgFormat = "This is a {} format test.";
    org.jboss.logging.Logger.getLogger(getClass()).infof(stringFormat, "message");

    assertEquals(5, appender.counter);
    assertEquals(5, stringAppender.messages.size());
    assertEquals(MESSAGE, stringAppender.messages.get(0));
    assertEquals(JBL_MESSAGE, stringAppender.messages.get(1));
    assertEquals(JUL_MESSAGE, stringAppender.messages.get(2));
    assertFalse(stringFormat.equals(stringAppender.messages.get(3)));
    assertFalse(msgFormat.equals(stringAppender.messages.get(4)));
  }
Exemplo n.º 4
0
  /**
   * Configures the Logger (log4j) class used by the entire library to log what happens at run time.
   *
   * @param logToConsole determines if log4j engine should log to the standard output or not.
   * @return a Logger class used to log events and functional meanings of the application.
   */
  public Logger configure(boolean logToConsole) {
    Logger log = Logger.getLogger(clazz);
    boolean loadDefaults = false;
    String logPath = null;
    PatternLayout layout = null;
    Strings str = Strings.getOne();
    String logLevel = "", logConsoleLevel = "", logFileLevel = "";
    try {
      Constants c = Constants.getOne(clazz);
      Properties log4j = c.getLog4j();
      loadDefaults = log4j.isEmpty();
      if (!loadDefaults) {
        PropertyConfigurator.configure(log4j);
      } else {
        logLevel = c.getConstant("log.level");
        logConsoleLevel = c.getConstant("log.console.level");
        logFileLevel = c.getConstant("log.file.level");
        logPath = str.safeConcatPaths(c.getConstant("log.dir"), c.getConstant("log.file"));
        if (!str.checkPathExistence(logPath)) {
          str.createPath(logPath);
          new File(logPath).createNewFile();
        }
        layout = new PatternLayout(c.getConstant("log.pattern"));
      }
    } catch (Throwable e) {
      logPath = str.safeConcatPaths(Constants.USER_HOME, "." + Constants.FPM_DIR);
      if (!str.checkPathExistence(logPath)) {
        str.createPath(logPath);
      }
      logPath = str.safeConcatPaths(logPath, Constants.MAIN_LOG_FILE);
      layout = new PatternLayout(Constants.DEFAULT_LOG_PATTERN);
      loadDefaults = true;
    }

    if (loadDefaults) {
      log.setLevel(Level.toLevel(logLevel));

      if (logToConsole) {
        ConsoleAppender consapp = new ConsoleAppender(layout);
        consapp.setTarget("System.out");
        consapp.setThreshold(Level.toLevel(logConsoleLevel));
        log.addAppender(consapp);
      }

      FileAppender fileapp;
      try {
        fileapp = new FileAppender(layout, logPath);
        fileapp.setThreshold(Level.toLevel(logFileLevel));
        log.addAppender(fileapp);
      } catch (IOException e) {
        log.warn("FileAppender not initialized! ".concat(e.getMessage()));
      }
    }
    log.trace("Logger initialized!");
    return log;
  }
Exemplo n.º 5
0
 public static void configLogger(int nbVms, int nbMachines, String algo) throws IOException {
   Date d = new Date();
   FileAppender rfa;
   rfa = new FileAppender(new PatternLayout(), logDir + nbMachines + "x" + nbVms + d + ".config");
   logger1.addAppender(rfa);
   rfa =
       new FileAppender(
           new PatternLayout(), logDir + nbMachines + "x" + nbVms + d + "_" + algo + ".exp");
   logger2.addAppender(rfa);
 }
 protected void setUp() throws Exception {
   // http://wagadugu/nagios/xml/status2xml_v2.cgi
   logger.setLevel(Level.ALL);
   PatternLayout layout = new PatternLayout("%d [%t] %-5p %m%n");
   ConsoleAppender cAppender = new ConsoleAppender(layout);
   logger.addAppender(cAppender);
   logger.addAppender(new ConsoleAppender());
   boolean b = addCols();
   super.setUp();
 }
Exemplo n.º 7
0
 /** Constructs a new object. */
 public TestRecorder() {
   remoteAppender = new SystemTestAppender();
   final LoggerNameFilter filter = new LoggerNameFilter();
   filter.setName("org.jvoicexml.systemtest");
   remoteAppender.addFilter(filter);
   final Logger jvxmlLogger = Logger.getLogger("org.jvoicexml");
   jvxmlLogger.addAppender(remoteAppender);
   localAppender = new SystemTestAppender();
   final Logger systemtestLogger = Logger.getLogger("org.jvoicexml.systemtest");
   systemtestLogger.addAppender(localAppender);
   resourceAppender = new SystemTestAppender();
   final Logger resourceLogger = Logger.getLogger("org.jvoicexml.implementation.pool");
   resourceLogger.addAppender(resourceAppender);
 }
  /**
   * @verifies log error if rouding item id is set but item cannot be found (and hence is null)
   * @see CashierOptionsServiceGpImpl#getOptions()
   */
  @Test
  public void getOptions_shouldLogErrorIfRoundingItemIsNullDespiteIdGiven() throws Exception {

    when(adminService.getGlobalProperty(ModuleSettings.RECEIPT_REPORT_ID_PROPERTY))
        .thenReturn(null);
    when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_MODE_PROPERTY))
        .thenReturn(CashierOptions.RoundingMode.FLOOR.toString());
    when(adminService.getGlobalProperty(ModuleSettings.ROUND_TO_NEAREST_PROPERTY)).thenReturn("5");
    when(adminService.getGlobalProperty(ModuleSettings.ROUNDING_ITEM_ID)).thenReturn("273423");
    when(adminService.getGlobalProperty(ModuleSettings.TIMESHEET_REQUIRED_PROPERTY))
        .thenReturn(null);

    Logger logger = Logger.getLogger(CashierOptionsServiceGpImpl.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Layout layout = new SimpleLayout();
    Appender appender = new WriterAppender(layout, out);
    logger.addAppender(appender);

    try {
      optionsService.getOptions();
      String logMsg = out.toString();
      assertNotNull(logMsg);
      assertFalse((logMsg.trim()).equals(""));
    } finally {
      logger.removeAppender(appender);
    }
  }
 /** create a gzip file */
 @BeforeClass
 public static void init() {
   SWTBotUtils.failIfUIThread();
   zipTrace();
   fLogger.removeAllAppenders();
   fLogger.addAppender(new NullAppender());
 }
Exemplo n.º 10
0
 /**
  * Sets the Luntbuild HTML log.
  *
  * @param installDir the luntbuild installation directory
  * @throws IOException from {@link FileAppender#FileAppender(org.apache.log4j.Layout,
  *     java.lang.String, boolean)}
  */
 public final void setLuntbuildHtmlLog(Appender app) {
   if (app != null) {
     ((FileAppender) app)
         .setFile(
             new File(Luntbuild.installDir + "/logs/" + Luntbuild.log4jFileName)
                 .getAbsolutePath());
     ((FileAppender) app).activateOptions();
   } else {
     logger.warn("Can not find luntbuild_logfile appender, creating...");
     HTMLLayout layout = new HTMLLayout();
     layout.setTitle("Luntbuild System Log");
     layout.setLocationInfo(true);
     try {
       app =
           new FileAppender(
               layout,
               new File(Luntbuild.installDir + "/logs/" + Luntbuild.log4jFileName)
                   .getAbsolutePath(),
               true);
       ((FileAppender) app).setAppend(false);
       Logger log = LogManager.getLogger("com.luntsys.luntbuild");
       log.setLevel(Level.INFO);
       log.addAppender(app);
       ((FileAppender) app).activateOptions();
     } catch (Exception e) {
       logger.error("Can not create luntbuild_logfile appender");
     }
   }
 }
Exemplo n.º 11
0
  private void crossover(String scenario, String crossoverLogFile) {
    try {

      WindScenario ws = new WindScenario("Scenarios/" + scenario + ".xml");
      KusiakLayoutEvaluator wfle = new KusiakLayoutEvaluator();
      wfle.initialize(ws);

      // Crossover Operation
      crossoverLogger.removeAllAppenders();
      FileAppender crossoverAppender = new FileAppender(layout, crossoverLogFile, false);
      crossoverAppender.setImmediateFlush(true);
      crossoverLogger.addAppender(crossoverAppender);

      System.out.println(crossoverLogFile);

      for (int i = 0; i < runs; i++) {
        MuLambdaES es = new MuLambdaES(wfle);
        es.setMaxEvaluations(maxEvaluations);
        es.setNum_Turbines(num_T);
        es.setMu(mu);
        es.setLambda(lambda);
        es.setOperatorFlag("crossover");

        String bestResult = String.valueOf(es.run_Dot_ES());
        crossoverLogger.info(bestResult);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 12
0
  public void testOverflowHandling() throws Exception {
    Logger logger = Logger.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.setAdditivity(false);
    logger.setLevel(Level.INFO);
    appender.activateOptions();

    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.close();
    assertTrue(
        "Expected some stop watch messages to get discarded",
        appender.getNumDiscardedMessages() > 0);
  }
Exemplo n.º 13
0
 /**
  * Sets the Luntbuild text log.
  *
  * @param installDir the luntbuild installation directory
  * @throws IOException from {@link FileAppender#FileAppender(org.apache.log4j.Layout,
  *     java.lang.String, boolean)}
  */
 public final void setLuntbuildTextLog(Appender app) {
   if (app != null) {
     ((FileAppender) app)
         .setFile(
             new File(Luntbuild.installDir + "/logs/" + Luntbuild.log4jFileNameTxt)
                 .getAbsolutePath());
     ((FileAppender) app).activateOptions();
   } else {
     logger.warn("Can not find luntbuild_txt_logfile appender, creating...");
     Layout layout = new PatternLayout("%5p [%t] (%F:%L) - %m%n");
     try {
       app =
           new FileAppender(
               layout,
               new File(Luntbuild.installDir + "/logs/" + Luntbuild.log4jFileNameTxt)
                   .getAbsolutePath(),
               true);
       Logger log = LogManager.getLogger("com.luntsys.luntbuild");
       log.setLevel(Level.INFO);
       log.addAppender(app);
       ((FileAppender) app).activateOptions();
     } catch (Exception e) {
       logger.error("Can not create luntbuild_txt_logfile appender");
     }
   }
 }
Exemplo n.º 14
0
 private static void configureLogging() {
   BasicConfigurator.configure();
   Logger root = Logger.getRootLogger();
   root.removeAllAppenders();
   Layout layout = new PatternLayout(LOG_LAYOUT);
   root.addAppender(new ConsoleAppender(layout));
   logger.info("Console logging started");
   String logFileName = getLogFileName();
   String logFilePath = Paths.LOGS_DIR + "/" + logFileName;
   try {
     root.addAppender(new FileAppender(layout, logFilePath));
     logger.info("File logging started");
   } catch (IOException e) {
     logger.warn("Failed to create FileAppender: " + e.getMessage());
   }
 }
Exemplo n.º 15
0
 static {
   appender = new ListAppender(new PatternLayout("%d{DATE} - %m"), list);
   appender.setName("ListAppender");
   appender.setThreshold(Level.INFO);
   log = log.getLogger(ControllerLogger.class);
   log.addAppender(appender);
 }
  public void deny() throws Exception {

    // set up appender
    Layout layout = new SimpleLayout();
    Appender appender = new FileAppender(layout, DENY_FILE, false);

    // create LevelMatchFilter, set to deny matches
    LevelMatchFilter matchFilter = new LevelMatchFilter();
    matchFilter.setAcceptOnMatch(false);

    // attach match filter to appender
    appender.addFilter(matchFilter);

    // set appender on root and set level to debug
    root.addAppender(appender);
    root.setLevel(Level.TRACE);

    Level[] levelArray =
        new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL};
    for (int x = 0; x < levelArray.length; x++) {
      // set the level to match
      matchFilter.setLevelToMatch(levelArray[x].toString());
      common("pass " + x + "; filter set to deny only " + levelArray[x].toString() + " msgs");
    }

    Transformer.transform(DENY_FILE, DENY_FILTERED, new LineNumberFilter());
    assertTrue(Compare.compare(DENY_FILTERED, DENY_WITNESS));
  }
  public void accept() throws Exception {

    // set up appender
    Layout layout = new SimpleLayout();
    Appender appender = new FileAppender(layout, ACCEPT_FILE, false);

    // create LevelMatchFilter
    LevelMatchFilter matchFilter = new LevelMatchFilter();

    // attach match filter to appender
    appender.addFilter(matchFilter);

    // attach DenyAllFilter to end of filter chain to deny neutral
    // (non matching) messages
    appender.addFilter(new DenyAllFilter());

    // set appender on root and set level to debug
    root.addAppender(appender);
    root.setLevel(Level.TRACE);

    Level[] levelArray =
        new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL};
    for (int x = 0; x < levelArray.length; x++) {
      // set the level to match
      matchFilter.setLevelToMatch(levelArray[x].toString());
      common("pass " + x + "; filter set to accept only " + levelArray[x].toString() + " msgs");
    }

    Transformer.transform(ACCEPT_FILE, ACCEPT_FILTERED, new LineNumberFilter());
    assertTrue(Compare.compare(ACCEPT_FILTERED, ACCEPT_WITNESS));
  }
Exemplo n.º 18
0
 /** Ctor. */
 private Drain() {
   super();
   final Logger root = Logger.getRootLogger();
   root.addAppender(this);
   this.setLayout(new PatternLayout("%c %m\n"));
   com.jcabi.log.Logger.info(Drain.class, "drain configured for %s", root);
 }
Exemplo n.º 19
0
 public Logger createLogger(Writer writer) {
   TestLoggerRepository repo = new TestLoggerRepository();
   Logger logger = repo.getLogger("test");
   Log4Json layout = new Log4Json();
   WriterAppender appender = new WriterAppender(layout, writer);
   logger.addAppender(appender);
   return logger;
 }
Exemplo n.º 20
0
  public static void main(String[] args) {
    // A JDBCIDHandler
    MyIDHandler idhandler = new MyIDHandler();

    // A JDBCColumnHandler
    MyColumnHandler colHandler = new MyColumnHandler();

    // Ensure to have all necessary drivers installed !
    try {
      Driver d = (Driver) (Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
      DriverManager.registerDriver(d);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // Set the priority which messages have to be logged
    logger.setLevel(Level.INFO);

    // Create a new instance of JDBCAppender
    JDBCAppender ja = new JDBCAppender();

    // Set options with method setOption()
    ja.setConnector("org.apache.log4j.jdbcplus.examples.OracleConnectionHandler");
    ja.setUrl(
        "jdbc:oracle:thin:@"
            + "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 62.52.100.41)(PORT = 1521)))"
            + "(CONNECT_DATA = (SERVICE_NAME = oracle8i)))");
    ja.setUsername("danko");
    ja.setPassword("danko");

    ja.setTable("logtest");

    ja.setColumn("id", JDBCLogType.ID, idhandler, "INTEGER", Types.INTEGER);
    ja.setColumn("prio", JDBCLogType.PRIO, "", "VARCHAR", Types.VARCHAR);
    ja.setColumn("cat", JDBCLogType.CAT, "", "VARCHAR", Types.VARCHAR);
    ja.setColumn("msg", JDBCLogType.MSG, "", "VARCHAR", Types.VARCHAR);
    ja.setColumn("info", JDBCLogType.DYNAMIC, colHandler, "VARCHAR", Types.VARCHAR);
    ja.setColumn("addon", JDBCLogType.EMPTY, "", "VARCHAR", Types.VARCHAR);
    ja.setColumn("the_timestamp", JDBCLogType.TIMESTAMP, "", "TIMESTAMP", Types.TIMESTAMP);
    ja.setColumn("created_by", JDBCLogType.STATIC, "ME", "VARCHAR", Types.VARCHAR);

    // other options
    // ja.setBuffer("1");
    // ja.setCommit("Y");

    // Add the appender to a category
    logger.addAppender(ja);

    // These messages with Priority >= setted priority will be logged to the database.
    logger.debug("debug");
    logger.info("info");
    logger.error("error");
    logger.fatal("fatal");

    // not required
    logger.removeAppender(ja);
  }
Exemplo n.º 21
0
  @Test(timeout = 20000)
  public void testWarnCommandOpts() throws Exception {
    Logger logger = Logger.getLogger(YARNRunner.class);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Layout layout = new SimpleLayout();
    Appender appender = new WriterAppender(layout, bout);
    logger.addAppender(appender);

    JobConf jobConf = new JobConf();

    jobConf.set(
        MRJobConfig.MR_AM_ADMIN_COMMAND_OPTS,
        "-Djava.net.preferIPv4Stack=true -Djava.library.path=foo");
    jobConf.set(MRJobConfig.MR_AM_COMMAND_OPTS, "-Xmx1024m -Djava.library.path=bar");

    YARNRunner yarnRunner = new YARNRunner(jobConf);

    File jobxml = new File(testWorkDir, MRJobConfig.JOB_CONF_FILE);
    OutputStream out = new FileOutputStream(jobxml);
    conf.writeXml(out);
    out.close();

    File jobsplit = new File(testWorkDir, MRJobConfig.JOB_SPLIT);
    out = new FileOutputStream(jobsplit);
    out.close();

    File jobsplitmetainfo = new File(testWorkDir, MRJobConfig.JOB_SPLIT_METAINFO);
    out = new FileOutputStream(jobsplitmetainfo);
    out.close();

    File appTokens = new File(testWorkDir, MRJobConfig.APPLICATION_TOKENS_FILE);
    out = new FileOutputStream(appTokens);
    out.close();

    @SuppressWarnings("unused")
    ApplicationSubmissionContext submissionContext =
        yarnRunner.createApplicationSubmissionContext(
            jobConf, testWorkDir.toString(), new Credentials());

    String logMsg = bout.toString();
    assertTrue(
        logMsg.contains(
            "WARN - Usage of -Djava.library.path in "
                + "yarn.app.mapreduce.am.admin-command-opts can cause programs to no "
                + "longer function if hadoop native libraries are used. These values "
                + "should be set as part of the LD_LIBRARY_PATH in the app master JVM "
                + "env using yarn.app.mapreduce.am.admin.user.env config settings."));
    assertTrue(
        logMsg.contains(
            "WARN - Usage of -Djava.library.path in "
                + "yarn.app.mapreduce.am.command-opts can cause programs to no longer "
                + "function if hadoop native libraries are used. These values should "
                + "be set as part of the LD_LIBRARY_PATH in the app master JVM env "
                + "using yarn.app.mapreduce.am.env config settings."));
  }
Exemplo n.º 22
0
  @Override
  protected void attach(final LoggerConfig config, final LoggerReporter reporter) {

    // initialize
    final Logger rootLogger = LogManager.getLoggerRepository().getRootLogger();

    // attach
    myAppender = new CrashAppender(config, reporter);
    rootLogger.addAppender(myAppender);
  }
  @Test
  public void rootAppenderTest() {
    final CountingAppender appender = new CountingAppender();
    final StringAppender stringAppender = new StringAppender();

    root.addAppender(appender);
    root.addAppender(stringAppender);
    root.info(ROOT_LOGGER_MSG);

    final String msg = JBL_MESSAGE + " root logger";
    org.jboss.logmanager.Logger.getLogger(JBossLogManagerFacade.JBL_ROOT_NAME).info(msg);
    org.jboss.logging.Logger.getLogger(JBossLogManagerFacade.JBL_ROOT_NAME).info(msg);

    assertEquals(3, appender.counter);
    assertEquals(3, stringAppender.messages.size());
    assertEquals(ROOT_LOGGER_MSG, stringAppender.messages.get(0));
    assertEquals(msg, stringAppender.messages.get(1));
    assertEquals(msg, stringAppender.messages.get(2));
  }
Exemplo n.º 24
0
  static void initializeLogging() throws SipXOpenfirePluginException {
    try {
      String javaClassPaths = System.getProperty("java.class.path");
      String openfireHome = System.getProperty("openfire.home");
      StringBuilder sb =
          new StringBuilder(javaClassPaths).append(":" + openfireHome + "/lib/sipxcommons.jar");
      System.setProperty("java.class.path", sb.toString());
      String log4jPropertiesFile = configurationPath + "/log4j.properties";

      if (new File(log4jPropertiesFile).exists()) {
        /*
         * Override the file configuration setting.
         */
        Properties props = new Properties();
        props.load(new FileInputStream(log4jPropertiesFile));
        String level = props.getProperty("log4j.category.org.sipfoundry.openfire");
        if (level != null) {
          watcherConfig.setLogLevel(level);
        }
      }
      setLogAppender(new SipFoundryAppender(new SipFoundryLayout(), logFile));
      // TODO -- this should be org.sipfoundry.openfire.
      Logger applicationLogger = Logger.getLogger("org.sipfoundry");

      /*
       * Set the log level.
       */
      if (watcherConfig.getLogLevel().equals("TRACE")) {
        applicationLogger.setLevel(org.apache.log4j.Level.DEBUG);
      } else {
        applicationLogger.setLevel(org.apache.log4j.Level.toLevel(watcherConfig.getLogLevel()));
      }

      applicationLogger.addAppender(getLogAppender());
      if (System.getProperty("output.console") != null) {
        applicationLogger.addAppender(new ConsoleAppender(new PatternLayout()));
      }

      CallWatcher.setLogAppender(getLogAppender());
    } catch (Exception ex) {
      throw new SipXOpenfirePluginException(ex);
    }
  }
Exemplo n.º 25
0
 public static void setLevel(String[] allLoggers, Level level) {
   Appender app = Logger.getLogger("jrds").getAppender(JrdsLoggerConfiguration.APPENDERNAME);
   for (String loggerName : allLoggers) {
     Logger l = Logger.getLogger(loggerName);
     l.setLevel(level);
     if (l.getAppender(JrdsLoggerConfiguration.APPENDERNAME) != null) {
       l.addAppender(app);
     }
   }
 }
Exemplo n.º 26
0
  /**
   * Create an appender that directs all log messages to a file with given name and replace all
   * current appenders with it.
   *
   * @param fileName Name of the log file to use.
   * @param append Value indicating if messages will be appended to the given file or it will be
   *     truncated.
   */
  public static void logToFile(String fileName, boolean append) throws IOException {
    final Appender newAppender = new FileAppender(new PatternLayout(), fileName, append);

    final List<Logger> loggers = Collections.list(LogManager.getCurrentLoggers());
    loggers.add(LogManager.getRootLogger());

    for (Logger logger : loggers) {
      logger.removeAllAppenders();
      logger.addAppender(newAppender);
    }
  }
Exemplo n.º 27
0
  public FontParserTest() {
    logger.addAppender(ca);
    FileAppender fa;
    try {
      fa = new FileAppender(l, "logs/logfile.txt", false);
      fileLogger.addAppender(fa);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    fileLogger.addAppender(ca);

    pc = new CSSParserConnection("fonttest.css", app);
    styles = pc.getCssh().getStyles();
    hm.clear();
    for (CSSStyle s : styles) {
      hm.put(s.getSelector(), s.getFont());
    }
  }
Exemplo n.º 28
0
  public void setUp() throws Exception {
    super.setUp();

    // start from a clean slate for each test

    listAppender = new ListAppender();
    listAppender.extractLocationInfo = true;
    log4jRoot = org.apache.log4j.Logger.getRootLogger();
    log4jRoot.addAppender(listAppender);
    log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
  }
Exemplo n.º 29
0
  /**
   * For command-line usage, user can specify a log file with an optional argument. log4j is used as
   * the actual logging mechanism, and is configured here.
   */
  public void setupLogging() throws Exception {
    // setup logging
    if (logFilename == null) {
      return;
    }

    SimpleLayout layout = new SimpleLayout();
    FileAppender appender = new FileAppender(layout, logFilename, false);

    logger.addAppender(appender);
    logger.setLevel((Level) Level.DEBUG);
  }
Exemplo n.º 30
0
 private SystemLogger() {
   systemLogger = Logger.getLogger("System");
   /* System verbosity (Standard Out) */
   consoleAppender = new ConsoleAppender(new PatternLayout("%m"), ConsoleAppender.SYSTEM_ERR);
   consoleAppender.setEncoding("UTF-16");
   systemLogger.addAppender(consoleAppender);
   if (System.getProperty("Malt.verbosity") != null) {
     setSystemVerbosityLevel(System.getProperty("Malt.verbosity").toUpperCase());
   } else {
     setSystemVerbosityLevel("INFO");
   }
 }