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

The following examples show how to use org.apache.log4j.Level#FATAL . 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: 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 2
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 3
Source File: EventCounter.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
public void append(LoggingEvent event) {
    Level level = event.getLevel();
    if (level == Level.INFO) {
        counts.incr(INFO);
    }
    else if (level == Level.WARN) {
        counts.incr(WARN);
    }
    else if (level == Level.ERROR) {
        counts.incr(ERROR);
    }
    else if (level == Level.FATAL) {
        counts.incr(FATAL);
    }

}
 
Example 4
Source File: Log4jSyslogBackLogHandler.java    From syslog4j-graylog2 with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected static Level getLog4jLevel(int level) {
    switch (level) {
        case SyslogConstants.LEVEL_DEBUG:
            return Level.DEBUG;
        case SyslogConstants.LEVEL_INFO:
            return Level.INFO;
        case SyslogConstants.LEVEL_NOTICE:
            return Level.INFO;
        case SyslogConstants.LEVEL_WARN:
            return Level.WARN;
        case SyslogConstants.LEVEL_ERROR:
            return Level.ERROR;
        case SyslogConstants.LEVEL_CRITICAL:
            return Level.ERROR;
        case SyslogConstants.LEVEL_ALERT:
            return Level.ERROR;
        case SyslogConstants.LEVEL_EMERGENCY:
            return Level.FATAL;

        default:
            return Level.WARN;
    }
}
 
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: EventCounter.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public void append(LoggingEvent event) {
    Level level = event.getLevel();
    if (level == Level.INFO) {
        counts.incr(INFO);
    }
    else if (level == Level.WARN) {
        counts.incr(WARN);
    }
    else if (level == Level.ERROR) {
        counts.incr(ERROR);
    }
    else if (level == Level.FATAL) {
        counts.incr(FATAL);
    }

}
 
Example 7
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 8
Source File: PropertyFileReader.java    From SeleniumCucumber with GNU General Public License v3.0 6 votes vote down vote up
public Level getLoggerLevel() {
	
	switch (prop.getProperty("Logger.Level")) {
	
	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;
	}
	return Level.ALL;
}
 
Example 9
Source File: DBase.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void append (LoggingEvent e) {
	Level	l = e.getLevel ();
	int lvl = -1;

	if (l == Level.WARN) {
		lvl = Log.WARNING;
	} else if (l == Level.ERROR) {
		lvl = Log.ERROR;
	} else if (l == Level.FATAL) {
		lvl = Log.FATAL;
	}
	if (lvl != -1) {
		String	loggerName = e.getLoggerName ();

		if ((loggerName == null) || loggerName.startsWith ("org.springframework.jdbc")) {
			log.out (lvl, "jdbc", e.getRenderedMessage ());
		}
	}
}
 
Example 10
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 11
Source File: Log4jSyslogBackLogHandler.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static Level getLog4jLevel(int level) {
	switch(level) {
		case SyslogConstants.LEVEL_DEBUG: 		return Level.DEBUG;
		case SyslogConstants.LEVEL_INFO: 		return Level.INFO;
		case SyslogConstants.LEVEL_NOTICE: 		return Level.INFO;
		case SyslogConstants.LEVEL_WARN: 		return Level.WARN;
		case SyslogConstants.LEVEL_ERROR: 		return Level.ERROR;
		case SyslogConstants.LEVEL_CRITICAL: 	return Level.ERROR;
		case SyslogConstants.LEVEL_ALERT: 		return Level.ERROR;
		case SyslogConstants.LEVEL_EMERGENCY: 	return Level.FATAL;
		
		default:
			return Level.WARN;
	}
}
 
Example 12
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 13
Source File: AbstractLoggingBoltTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogDefault(@Injectable Logger logger) throws Exception {
  bolt.level = Level.FATAL;
  new Expectations() {{
    logger.debug("msg");
  }};
  bolt.log(logger, "msg");
}
 
Example 14
Source File: Log.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public int decide (LoggingEvent e) {
	Level	l = e.getLevel ();

	if ((l == Level.DEBUG) || (l == Level.INFO) || (l == Level.WARN) || (l == Level.ERROR) || (l == Level.FATAL)) {
		return Filter.ACCEPT;
	}
	return Filter.NEUTRAL;
}
 
Example 15
Source File: TajoLogEventCounter.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void append(LoggingEvent event) {
  Level level = event.getLevel();
  String levelStr = level.toString();

  if (level == Level.INFO || "INFO".equalsIgnoreCase(levelStr)) {
    counts.incr(INFO);
  } else if (level == Level.WARN || "WARN".equalsIgnoreCase(levelStr)) {
    counts.incr(WARN);
  } else if (level == Level.ERROR || "ERROR".equalsIgnoreCase(levelStr)) {
    counts.incr(ERROR);
  } else if (level == Level.FATAL || "FATAL".equalsIgnoreCase(levelStr)) {
    counts.incr(FATAL);
  }
}
 
Example 16
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 17
Source File: TajoLogEventCounter.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void append(LoggingEvent event) {
  Level level = event.getLevel();
  String levelStr = level.toString();

  if (level == Level.INFO || "INFO".equalsIgnoreCase(levelStr)) {
    counts.incr(INFO);
  } else if (level == Level.WARN || "WARN".equalsIgnoreCase(levelStr)) {
    counts.incr(WARN);
  } else if (level == Level.ERROR || "ERROR".equalsIgnoreCase(levelStr)) {
    counts.incr(ERROR);
  } else if (level == Level.FATAL || "FATAL".equalsIgnoreCase(levelStr)) {
    counts.incr(FATAL);
  }
}
 
Example 18
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 19
Source File: Log4j.java    From pegasus with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the debug level. All those messages are logged which have a level less than equal to the
 * debug level. In case the boolean info is set, all the info messages are also logged.
 *
 * @param level the level to which the debug level needs to be set to.
 * @param info boolean denoting whether the INFO messages need to be logged or not.
 */
protected void setLevel(int level, boolean info) {
    Level l = Level.ALL;
    switch (level) {
        case LogManager.FATAL_MESSAGE_LEVEL:
            l = Level.FATAL;
            break;

        case LogManager.ERROR_MESSAGE_LEVEL:
            l = Level.ERROR;
            break;

        case LogManager.WARNING_MESSAGE_LEVEL:
            l = Level.WARN;
            break;

        case LogManager.CONFIG_MESSAGE_LEVEL:
            l = Level.INFO;
            break;

        case LogManager.INFO_MESSAGE_LEVEL:
            l = Level.INFO;
            break;

        case LogManager.DEBUG_MESSAGE_LEVEL:
            l = Level.DEBUG;
            break;
    }
    mLogger.setLevel(l);
}
 
Example 20
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());
}