Java Code Examples for org.apache.log4j.ConsoleAppender#SYSTEM_ERR

The following examples show how to use org.apache.log4j.ConsoleAppender#SYSTEM_ERR . 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: TestLocalImhotepServiceCore.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initLog4j() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();

    final Layout LAYOUT = new PatternLayout("[ %d{ISO8601} %-5p ] [%c{1}] %m%n");

    LevelRangeFilter ERROR_FILTER = new LevelRangeFilter();
    ERROR_FILTER.setLevelMin(Level.ERROR);
    ERROR_FILTER.setLevelMax(Level.FATAL);

    // everything including ERROR
    final Appender STDOUT = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_OUT);

    // just things <= ERROR
    final Appender STDERR = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_ERR);
    STDERR.addFilter(ERROR_FILTER);

    final Logger ROOT_LOGGER = Logger.getRootLogger();

    ROOT_LOGGER.removeAllAppenders();

    ROOT_LOGGER.setLevel(Level.WARN); // don't care about higher

    ROOT_LOGGER.addAppender(STDOUT);
    ROOT_LOGGER.addAppender(STDERR);
}
 
Example 2
Source File: AbstractFTGSMergerCase.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initLog4j() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();

    final Layout LAYOUT = new PatternLayout("[ %d{ISO8601} %-5p ] [%c{1}] %m%n");

    LevelRangeFilter ERROR_FILTER = new LevelRangeFilter();
    ERROR_FILTER.setLevelMin(Level.ERROR);
    ERROR_FILTER.setLevelMax(Level.FATAL);

    // everything including ERROR
    final Appender STDOUT = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_OUT);

    // just things <= ERROR
    final Appender STDERR = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_ERR);
    STDERR.addFilter(ERROR_FILTER);

    final Logger ROOT_LOGGER = Logger.getRootLogger();

    ROOT_LOGGER.removeAllAppenders();

    ROOT_LOGGER.setLevel(Level.WARN); // don't care about higher

    ROOT_LOGGER.addAppender(STDOUT);
    ROOT_LOGGER.addAppender(STDERR);
}
 
Example 3
Source File: TestSimpleFlamdexDocWriter.java    From imhotep with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initLog4j() {
    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();

    final Layout LAYOUT = new PatternLayout("[ %d{ISO8601} %-5p ] [%c{1}] %m%n");

    LevelRangeFilter ERROR_FILTER = new LevelRangeFilter();
    ERROR_FILTER.setLevelMin(Level.ERROR);
    ERROR_FILTER.setLevelMax(Level.FATAL);

    // everything including ERROR
    final Appender STDOUT = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_OUT);

    // just things <= ERROR
    final Appender STDERR = new ConsoleAppender(LAYOUT, ConsoleAppender.SYSTEM_ERR);
    STDERR.addFilter(ERROR_FILTER);

    final Logger ROOT_LOGGER = Logger.getRootLogger();

    ROOT_LOGGER.removeAllAppenders();

    ROOT_LOGGER.setLevel(Level.WARN); // don't care about higher

    ROOT_LOGGER.addAppender(STDOUT);
    ROOT_LOGGER.addAppender(STDERR);
}
 
Example 4
Source File: Logging.java    From swift-t with Apache License 2.0 5 votes vote down vote up
/**
 * Configures Log4j to log warnings to stderr
 *
 * @param stcLogger
 */
private static void setupLoggingToStderr(Logger stcLogger) {
  Layout layout = new PatternLayout("%-5p %m%n");
  ConsoleAppender appender = new ConsoleAppender(layout,
      ConsoleAppender.SYSTEM_ERR);
  appender.setThreshold(Level.WARN);
  stcLogger.addAppender(appender);
  stcLogger.setLevel(Level.WARN);
}
 
Example 5
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());
}