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

The following examples show how to use org.apache.log4j.Level#WARN . 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 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: MainWindow.java    From ripme with MIT License 5 votes vote down vote up
private void setLogLevel(String level) {
    Level newLevel = Level.ERROR;
    level = level.substring(level.lastIndexOf(' ') + 1);
    switch (level) {
    case "Debug":
        newLevel = Level.DEBUG;
        break;
    case "Info":
        newLevel = Level.INFO;
        break;
    case "Warn":
        newLevel = Level.WARN;
        break;
    case "Error":
        newLevel = Level.ERROR;
        break;
    }
    Logger.getRootLogger().setLevel(newLevel);
    LOGGER.setLevel(newLevel);
    ConsoleAppender ca = (ConsoleAppender) Logger.getRootLogger().getAppender("stdout");
    if (ca != null) {
        ca.setThreshold(newLevel);
    }
    FileAppender fa = (FileAppender) Logger.getRootLogger().getAppender("FILE");
    if (fa != null) {
        fa.setThreshold(newLevel);
    }
}
 
Example 10
Source File: AbstractLoggingBoltTest.java    From cognition with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogWarn(@Injectable Logger logger) throws Exception {
  bolt.level = Level.WARN;
  new Expectations() {{
    logger.warn("msg");

  }};
  bolt.log(logger, "msg");
}
 
Example 11
Source File: KubernetesClusterManagerImpl.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private void logMessage(final Level logLevel, final String message, final Exception e) {
    if (logLevel == Level.WARN) {
        if (e != null) {
            LOGGER.warn(message, e);
        } else {
            LOGGER.warn(message);
        }
    } else {
        if (e != null) {
            LOGGER.error(message, e);
        } else {
            LOGGER.error(message);
        }
    }
}
 
Example 12
Source File: OrRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * Test deserialized Or when neither rule match.
 */
@Test public void test8() throws IOException, ClassNotFoundException {
    Stack<Object> stack = new Stack<>();
    stack.push(LevelEqualsRule.getRule("INFO"));
    stack.push(TimestampInequalityRule.getRule(">=", "2009-05-21 00:44:45"));
    Rule rule = (Rule) SerializationTestHelper.serializeClone(OrRule.getRule(stack));
    AssertJUnit.assertEquals(0, stack.size());
    Calendar cal = new GregorianCalendar(2008, 4, 21, 0, 45, 44);
    LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
            Logger.getRootLogger(), cal.getTimeInMillis(), Level.WARN,
            "Hello, World", null);
    AssertJUnit.assertFalse(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}
 
Example 13
Source File: NotRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * Test Not of Level when Level does not match.
 */
@Test public void test4() {
    Stack<Object> stack = new Stack<>();
    stack.push(LevelEqualsRule.getRule("INFO"));
    Rule rule = NotRule.getRule(stack);
    AssertJUnit.assertEquals(0, stack.size());
    Calendar cal = new GregorianCalendar(2008, 4, 21, 0, 45, 44);
    LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
            Logger.getRootLogger(), cal.getTimeInMillis(), Level.WARN,
            "Hello, World", null);
    AssertJUnit.assertTrue(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}
 
Example 14
Source File: SpliceDatabase.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
private void configureCustomAuth(SConfiguration configuration){
    System.setProperty("derby.connection.requireAuthentication","true");
    System.setProperty("derby.database.sqlAuthorization","true");
    String authenticationCustomProvider = configuration.getAuthenticationCustomProvider();
    Level logLevel = Level.INFO;
    if(authenticationCustomProvider.equals(AuthenticationConfiguration.DEFAULT_AUTHENTICATION_CUSTOM_PROVIDER)){
        logLevel=Level.WARN;
    }
    LOG.log(logLevel,String.format("using custom authentication for SpliceMachine using class %s",authenticationCustomProvider));
    System.setProperty("derby.authentication.provider",authenticationCustomProvider);
}
 
Example 15
Source File: NotRuleTest.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
/**
 * Test deserialized Not.
 */
@Test public void test6() throws IOException, ClassNotFoundException {
    Stack<Object> stack = new Stack<>();
    stack.push(LevelEqualsRule.getRule("INFO"));
    Rule rule = (Rule) SerializationTestHelper.serializeClone(NotRule.getRule(stack));
    AssertJUnit.assertEquals(0, stack.size());
    Calendar cal = new GregorianCalendar(2008, 4, 21, 0, 45, 44);
    LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
            Logger.getRootLogger(), cal.getTimeInMillis(), Level.WARN,
            "Hello, World", null);
    AssertJUnit.assertTrue(rule.evaluate(Log4jUtil.translateLog4j(event), null));
}
 
Example 16
Source File: KubernetesClusterActionWorker.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
protected void logMessage(final Level logLevel, final String message, final Exception e) {
    if (logLevel == Level.INFO) {
        if (LOGGER.isInfoEnabled()) {
            if (e != null) {
                LOGGER.info(message, e);
            } else {
                LOGGER.info(message);
            }
        }
    } else if (logLevel == Level.DEBUG) {
        if (LOGGER.isDebugEnabled()) {
            if (e != null) {
                LOGGER.debug(message, e);
            } else {
                LOGGER.debug(message);
            }
        }
    } else if (logLevel == Level.WARN) {
        if (e != null) {
            LOGGER.warn(message, e);
        } else {
            LOGGER.warn(message);
        }
    } else {
        if (e != null) {
            LOGGER.error(message, e);
        } else {
            LOGGER.error(message);
        }
    }
}
 
Example 17
Source File: DBase.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.WARN) || (l == Level.ERROR) || (l == Level.FATAL)) {
		return Filter.ACCEPT;
	}
	return Filter.NEUTRAL;
}
 
Example 18
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 19
Source File: Log4JStopWatch.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public Log4JStopWatch(String tag, String message, Logger logger, Level normalPriority) {
   this(tag, message, logger, normalPriority, Level.WARN);
}
 
Example 20
Source File: Log4JStopWatch.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public Log4JStopWatch() {
   this("", (String)null, Logger.getLogger("org.perf4j.TimingLogger"), Level.INFO, Level.WARN);
}