Java Code Examples for org.apache.log4j.Level#TRACE

The following examples show how to use org.apache.log4j.Level#TRACE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log4jLoggerAdapter.java    From HttpSessionReplacer with MIT License 6 votes vote down vote up
@Override
public void log(Marker marker, String callerFQCN, int level, String msg, Object[] argArray, Throwable t) {
    Level log4jLevel;
    switch (level) {
    case LocationAwareLogger.TRACE_INT:
        log4jLevel = traceCapable ? Level.TRACE : Level.DEBUG;
        break;
    case LocationAwareLogger.DEBUG_INT:
        log4jLevel = Level.DEBUG;
        break;
    case LocationAwareLogger.INFO_INT:
        log4jLevel = Level.INFO;
        break;
    case LocationAwareLogger.WARN_INT:
        log4jLevel = Level.WARN;
        break;
    case LocationAwareLogger.ERROR_INT:
        log4jLevel = Level.ERROR;
        break;
    default:
        throw new IllegalStateException("Level number " + level + " is not recognized.");
    }
    logger.log(callerFQCN, log4jLevel, msg, t);
}
 
Example 2
Source File: IngestUtilities.java    From cognition with Apache License 2.0 6 votes vote down vote up
public static Level levelFromString(String level) {
  String ulevel = level.toUpperCase();
  if (ulevel.equals("ALL")) {
    return Level.ALL;
  } else if (ulevel.equals("DEBUG")) {
    return Level.DEBUG;
  } else if (ulevel.equals("ERROR")) {
    return Level.ERROR;
  } else if (ulevel.equals("FATAL")) {
    return Level.FATAL;
  } else if (ulevel.equals("INFO")) {
    return Level.INFO;
  } else if (ulevel.equals("OFF")) {
    return Level.OFF;
  } else if (ulevel.equals("TRACE")) {
    return Level.TRACE;
  } else if (ulevel.equals("WARN")) {
    return Level.WARN;
  }
  return Level.INFO;
}
 
Example 3
Source File: Log.java    From clust4j with Apache License 2.0 6 votes vote down vote up
public static void setLogLevel(int log_level) throws IllegalArgumentException {
	Level l;
	
	switch(log_level) {
		case 1: l = Level.TRACE; break;
		case 2: l = Level.DEBUG; break;
		case 3: l = Level.INFO;	 break;
		case 4: l = Level.WARN;  break;
		case 5: l = Level.ERROR; break;
		case 6: l = Level.FATAL; break;
		default:
			throw new IllegalArgumentException("Illegal log level: "+ log_level);
	}
	
	_logger.setLevel(l);
	String inf = "Set log level to " + l;
	System.out.println(inf);
	_logger.info(inf);
}
 
Example 4
Source File: Logging.java    From swift-t with Apache License 2.0 6 votes vote down vote up
private static void setupLoggingToFile(Logger stcLogger, String logfile,
    boolean trace) {
  Layout layout = new PatternLayout("%-5p %m%n");
  boolean append = false;
  try {
    FileAppender appender = new FileAppender(layout, logfile, append);
    Level threshold;
    if (trace) {
      threshold = Level.TRACE;
    } else {
      threshold = Level.DEBUG;
    }
    appender.setThreshold(threshold);
    stcLogger.addAppender(appender);
    stcLogger.setLevel(threshold);
  } catch (IOException e) {
    System.out.println(e.getMessage());
    System.exit(ExitCode.ERROR_IO.code());
  }
}
 
Example 5
Source File: Log.java    From h2o-2 with Apache License 2.0 6 votes vote down vote up
public static void setLogLevel(int log_level) throws IllegalArgumentException {
  Level l;

  switch(log_level) {
    case 1: l = Level.TRACE; break;
    case 2: l = Level.DEBUG; break;
    case 3: l = Level.INFO;  break;
    case 4: l = Level.WARN;  break;
    case 5: l = Level.ERROR; break;
    case 6: l = Level.FATAL; break;
    default:
      throw new IllegalArgumentException("Log level " + log_level + " is invalid");
  }

  _logger.setLevel(l);
  System.out.println("Set log level to " + l);
  _logger.info("Set log level to " + l);
}
 
Example 6
Source File: SpliceLevel2OptimizerImpl.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT",justification = "Intentional")
public void trace(TraceLevel level, String traceString){

    Priority prio = Level.INFO;
    switch(level){
        case TRACE:
            prio =  Level.TRACE;
            break;
        case DEBUG:
            prio =  Level.DEBUG;
            break;
        case WARN:
            prio =  Level.WARN;
            break;
        case ERROR:
            prio =  Level.ERROR;
            break;
    }

    if (TRACE_LOGGER.isTraceEnabled()) {
        TRACE_LOGGER.log(prio,traceString);
    }
}
 
Example 7
Source File: OptionConverter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public static Level convertLevel(org.apache.logging.log4j.Level level) {
    if (level == null) {
        return Level.ERROR;
    }
    switch (level.getStandardLevel()) {
        case FATAL:
            return Level.FATAL;
        case WARN:
            return Level.WARN;
        case INFO:
            return Level.INFO;
        case DEBUG:
            return Level.DEBUG;
        case TRACE:
            return Level.TRACE;
        case ALL:
            return Level.ALL;
        case OFF:
            return Level.OFF;
        default:
            return Level.ERROR;
    }
}
 
Example 8
Source File: LogEventAdapter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the level of this event. Use this form instead of directly
 * accessing the <code>level</code> field.
 */
@Override
public Level getLevel() {
    switch (StandardLevel.getStandardLevel(event.getLevel().intLevel())) {
        case TRACE:
            return Level.TRACE;
        case DEBUG:
            return Level.DEBUG;
        case INFO:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case FATAL:
            return Level.FATAL;
        case OFF:
            return Level.OFF;
        case ALL:
            return Level.ALL;
        default:
            return Level.ERROR;
    }
}
 
Example 9
Source File: LogEventAdapter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the level of this event. Use this form instead of directly
 * accessing the <code>level</code> field.  */
@Override
public Level getLevel() {
    switch (StandardLevel.getStandardLevel(event.getLevel().intLevel())) {
        case TRACE:
            return Level.TRACE;
        case DEBUG:
            return Level.DEBUG;
        case INFO:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        case FATAL:
            return Level.FATAL;
        case OFF:
            return Level.OFF;
        case ALL:
            return Level.ALL;
        default:
            return Level.ERROR;
    }
}
 
Example 10
Source File: LevelMatchFilterTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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));
}
 
Example 11
Source File: LevelMatchFilterTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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));
}
 
Example 12
Source File: AbstractLoggingBoltTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogTrace(@Injectable Logger logger) throws Exception {
  bolt.level = Level.TRACE;
  new Expectations() {{
    logger.trace("msg");

  }};
  bolt.log(logger, "msg");
}
 
Example 13
Source File: Log4jMessageLogger.java    From knox with Apache License 2.0 5 votes vote down vote up
private static Level toLevel( final MessageLevel level ) {
  switch( level ) {
    case FATAL: return Level.FATAL;
    case ERROR: return Level.ERROR;
    case WARN: return Level.WARN;
    case INFO: return Level.INFO;
    case DEBUG: return Level.DEBUG;
    case TRACE: return Level.TRACE;
    default: return Level.OFF;
  }
}
 
Example 14
Source File: LogInitializer.java    From DataGenerator with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes log4j
 *
 * @param loggerLevel log level to initialize to
 */
public static void initialize(String loggerLevel) {
    if (!INIT.compareAndSet(false, true)) {
        return;
    }

    BasicConfigurator.resetConfiguration();
    ConsoleAppender consoleAppender = new ConsoleAppender(
        new PatternLayout("<%d{yyMMdd HHmmss} %5p %C{1}:%L> %m%n"), ConsoleAppender.SYSTEM_ERR);
    BasicConfigurator.configure(consoleAppender);

    Level level;

    String logLevel;

    if (loggerLevel != null) {
        logLevel = loggerLevel.toLowerCase();
    } else {
        logLevel = "default";
    }

    switch (logLevel) {
        case "all":
            level = Level.ALL;
            break;
        case "debug":
            level = Level.DEBUG;
            break;
        case "error":
            level = Level.ERROR;
            break;
        case "fatal":
            level = Level.FATAL;
            break;
        case "info":
            level = Level.INFO;
            break;
        case "off":
            level = Level.OFF;
            break;
        case "trace":
            level = Level.TRACE;
            break;
        case "warn":
            level = Level.WARN;
            break;
        default:
            level = Level.INFO;
            break;
    }

    Logger.getRootLogger().setLevel(Level.OFF);
    Logger.getLogger("org.finra").setLevel(level);

    System.err.println("Set loglevel to " + level.toString());
}