Java Code Examples for org.apache.log4j.ConsoleAppender#setThreshold()
The following examples show how to use
org.apache.log4j.ConsoleAppender#setThreshold() .
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: BaseEvolutionaryTest.java From astor with GNU General Public License v2.0 | 6 votes |
public Logger createCustomFileLogger(String file) throws IOException { // ---- ConsoleAppender console = new ConsoleAppender(); String PATTERN = "%m%n-%c: "; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.INFO); console.activateOptions(); Logger log = Logger.getLogger(Thread.currentThread().getName()); log.getLoggerRepository().resetConfiguration(); log.removeAllAppenders(); log.addAppender(console); // ---- org.apache.log4j.RollingFileAppender rfa = new RollingFileAppender(new org.apache.log4j.PatternLayout(PATTERN), file); log.addAppender(rfa); rfa.setImmediateFlush(true); return log; }
Example 2
Source File: LogUtil.java From yb-sample-apps with Apache License 2.0 | 6 votes |
public static void configureLogLevel(boolean verbose) { // First remove all appenders. Logger.getLogger("com.yugabyte.sample").removeAppender("YBConsoleLogger"); Logger.getRootLogger().removeAppender("YBConsoleLogger");; // Create the console appender. ConsoleAppender console = new ConsoleAppender(); console.setName("YBConsoleLogger"); String PATTERN = "%d [%p|%c|%C{1}] %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(verbose ? Level.DEBUG : Level.INFO); console.activateOptions(); // Set the desired logging level. if (verbose) { // If verbose, make everything DEBUG log level and output to console. Logger.getRootLogger().addAppender(console); Logger.getRootLogger().setLevel(Level.DEBUG); } else { // If not verbose, allow YB sample app and driver INFO logs go to console. Logger.getLogger("com.yugabyte.sample").addAppender(console); Logger.getLogger("com.yugabyte.driver").addAppender(console); Logger.getLogger("com.datastax.driver").addAppender(console); Logger.getRootLogger().setLevel(Level.WARN); } }
Example 3
Source File: LogUtil.java From lumongo with Apache License 2.0 | 6 votes |
public static void loadLogConfig() throws Exception { synchronized (lock) { if (!loaded) { ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender String PATTERN = "%d [%t] <%p> %c{2}: %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.INFO); console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); //String propPath = "/etc/loglevel.properties"; //URL url = LogUtil.class.getResource(propPath); //if (url == null) { // throw new Exception("Cannot find log properties file: " + propPath); //} //PropertyConfigurator.configure(url); loaded = true; } } }
Example 4
Source File: Test.java From cpsolver with GNU Lesser General Public License v3.0 | 6 votes |
/** * Setup log4j logging * * @param logFile log file * @param debug true if debug messages should be logged (use -Ddebug=true to enable debug message) */ public static void setupLogging(File logFile, boolean debug) { Logger root = Logger.getRootLogger(); ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n")); console.setThreshold(Level.INFO); root.addAppender(console); if (logFile != null) { try { FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false); file.setThreshold(Level.DEBUG); root.addAppender(file); } catch (IOException e) { sLogger.fatal("Unable to configure logging, reason: " + e.getMessage(), e); } } if (!debug) root.setLevel(Level.INFO); }
Example 5
Source File: Test.java From cpsolver with GNU Lesser General Public License v3.0 | 6 votes |
/** * Setup log4j logging * * @param logFile * log file * @param debug * true if debug messages should be logged (use -Ddebug=true to * enable debug message) */ public static void setupLogging(File logFile, boolean debug) { Logger root = Logger.getRootLogger(); ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n")); console.setThreshold(Level.INFO); root.addAppender(console); if (logFile != null) { try { FileAppender file = new FileAppender(new PatternLayout( "%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false); file.setThreshold(Level.DEBUG); root.addAppender(file); } catch (IOException e) { sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e); } } if (!debug) root.setLevel(Level.INFO); }
Example 6
Source File: Test.java From cpsolver with GNU Lesser General Public License v3.0 | 6 votes |
/** * Setup log4j logging * * @param logFile log file */ public static void setupLogging(File logFile) { Logger root = Logger.getRootLogger(); ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n")); console.setThreshold(Level.INFO); root.addAppender(console); if (logFile != null) { try { FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false); file.setThreshold(Level.DEBUG); root.addAppender(file); } catch (IOException e) { sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e); } } }
Example 7
Source File: Log4JInitServlet.java From olat with Apache License 2.0 | 6 votes |
@Override public void init() { String file = getInitParameter("log4j-init-file"); ClassPathResource res = new ClassPathResource(file); if (!res.exists()) { // creating basic log4j configuration which writes to console out, Only called when not yet configured ConsoleAppender appender = new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %5p %c{1}:%L - %m%n"), ConsoleAppender.SYSTEM_OUT); appender.setThreshold(Level.INFO); BasicConfigurator.configure(appender); log.info("*****************************************************************************************"); log.info("You don't provide a log4j config file for your OLAT instance. OLAT will just log to standard out (e.g. catalina.out)." + " Please provide a proper log config file (log4j.xml, see olat/conf for an example or read the installation guide) " + "and place it into the root of the classpath e.g. tomcat/lib or WEB-INF/classes"); log.info("*****************************************************************************************"); } }
Example 8
Source File: ExampleHelpers.java From Wikidata-Toolkit-Examples with Apache License 2.0 | 5 votes |
/** * Defines how messages should be logged. This method can be modified to * restrict the logging messages that are shown on the console or to change * their formatting. See the documentation of Log4J for details on how to do * this. */ public static void configureLogging() { // Create the appender that will write log messages to the console. ConsoleAppender consoleAppender = new ConsoleAppender(); // Define the pattern of log messages. // Insert the string "%c{1}:%L" to also show class name and line. String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n"; consoleAppender.setLayout(new PatternLayout(pattern)); // Change to Level.ERROR for fewer messages: consoleAppender.setThreshold(Level.INFO); consoleAppender.activateOptions(); Logger.getRootLogger().addAppender(consoleAppender); }
Example 9
Source File: UnitTestHelper.java From metron with Apache License 2.0 | 5 votes |
public static void verboseLogging(String pattern, Level level) { ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender console.setLayout(new PatternLayout(pattern)); console.setThreshold(level); console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); }
Example 10
Source File: UnitTestHelper.java From metron with Apache License 2.0 | 5 votes |
public static void verboseLogging(String pattern, Level level) { ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender console.setLayout(new PatternLayout(pattern)); console.setThreshold(level); console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); }
Example 11
Source File: BaseTest.java From AndroidMvc with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender String PATTERN = "%d [%p] %C{1}: %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.DEBUG); console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); }
Example 12
Source File: Logging.java From swift-t with Apache License 2.0 | 5 votes |
/** * 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 13
Source File: BaseTest.java From AndroidMvc with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() { ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender String PATTERN = "%d [%p] %C{1}: %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.DEBUG); console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); }
Example 14
Source File: DGALoggingUtil.java From distributed-graph-analytics with Apache License 2.0 | 5 votes |
public static void setDGALogLevel(String logLevel) { //System.out.println("Setting DGA Log level to: " + logLevel); Level level = Level.toLevel(logLevel, Level.INFO); ConsoleAppender console = new ConsoleAppender(); //configure the appender String pattern = "%d [%p|%c] %m%n"; console.setLayout(new PatternLayout(pattern)); console.setThreshold(Level.DEBUG); console.activateOptions(); //add appender to any Logger Logger.getLogger("com.soteradefense").addAppender(console); Logger.getLogger("com.soteradefense").setLevel(level); }
Example 15
Source File: GadgetInspector.java From gadgetinspector with MIT License | 5 votes |
private static void configureLogging() { ConsoleAppender console = new ConsoleAppender(); String PATTERN = "%d %c [%p] %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.DEBUG); console.activateOptions(); org.apache.log4j.Logger.getRootLogger().addAppender(console); }
Example 16
Source File: ExampleHelpers.java From Wikidata-Toolkit with Apache License 2.0 | 5 votes |
/** * Defines how messages should be logged. This method can be modified to * restrict the logging messages that are shown on the console or to change * their formatting. See the documentation of Log4J for details on how to do * this. */ public static void configureLogging() { // Create the appender that will write log messages to the console. ConsoleAppender consoleAppender = new ConsoleAppender(); // Define the pattern of log messages. // Insert the string "%c{1}:%L" to also show class name and line. String pattern = "%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n"; consoleAppender.setLayout(new PatternLayout(pattern)); // Change to Level.ERROR for fewer messages: consoleAppender.setThreshold(Level.INFO); consoleAppender.activateOptions(); Logger.getRootLogger().addAppender(consoleAppender); }
Example 17
Source File: ZeppelinApplicationDevServer.java From zeppelin with Apache License 2.0 | 5 votes |
void setLogger() { ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender String PATTERN = "%d [%p|%c|%C{1}] %m%n"; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.DEBUG); console.activateOptions(); //add appender to any Logger (here is root) org.apache.log4j.Logger.getRootLogger().addAppender(console); }
Example 18
Source File: MainWindow.java From ripme with MIT License | 5 votes |
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 19
Source File: QueryBenchmark.java From rya with Apache License 2.0 | 4 votes |
@Setup public void setup() throws Exception { // Setup logging. final ConsoleAppender console = new ConsoleAppender(); console.setLayout(new PatternLayout("%d [%p|%c|%C{1}] %m%n")); console.setThreshold(Level.INFO); console.activateOptions(); Logger.getRootLogger().addAppender(console); // Load the benchmark's configuration file. final InputStream queriesStream = Files.newInputStream(QUERY_BENCHMARK_CONFIGURATION_FILE); final QueriesBenchmarkConf benchmarkConf = new QueriesBenchmarkConfReader().load(queriesStream); // Create the Rya Configuration object using the benchmark's configuration. final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration(); final Rya rya = benchmarkConf.getRya(); ryaConf.setTablePrefix(rya.getRyaInstanceName()); final Accumulo accumulo = rya.getAccumulo(); ryaConf.set(ConfigUtils.CLOUDBASE_USER, accumulo.getUsername()); ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, accumulo.getPassword()); ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, accumulo.getZookeepers()); ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, accumulo.getInstanceName()); // Print the query plan so that you can visually inspect how PCJs are being applied for each benchmark. ryaConf.set(ConfigUtils.DISPLAY_QUERY_PLAN, "true"); // Turn on PCJs if we are configured to use them. final SecondaryIndexing secondaryIndexing = rya.getSecondaryIndexing(); if(secondaryIndexing.isUsePCJ()) { ryaConf.set(ConfigUtils.USE_PCJ, "true"); ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString()); ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.NO_UPDATE.toString()); } else { ryaConf.set(ConfigUtils.USE_PCJ, "false"); } // Create the connections used to execute the benchmark. sail = RyaSailFactory.getInstance( ryaConf ); sailConn = sail.getConnection(); }
Example 20
Source File: AbstractScriptRunner.java From sailfish-core with Apache License 2.0 | 3 votes |
private Logger createScriptLogger(ScriptSettings scriptSettings, String reportFolder) throws IOException, WorkspaceStructureException { org.apache.log4j.Logger scriptLogger = org.apache.log4j.Logger.getLogger("TestScript_" + RandomStringUtils.randomAlphanumeric(10)); scriptLogger.removeAllAppenders(); PatternLayout layout = new PatternLayout(scriptSettings.getFileLayout()); RollingFileAppender fileAppender = new RollingFileAppender(layout, workspaceDispatcher.createFile(FolderType.REPORT, true, reportFolder, "script.log").getPath()); fileAppender.setName("TESTSCRIPTFILEAPPENDER"); fileAppender.setThreshold(Level.toLevel(scriptSettings.getFileLoggerLevel())); fileAppender.activateOptions(); HTMLLayout htmlLayout = new HTMLLayout(); RollingFileAppender htmlFileAppender = new RollingFileAppender(htmlLayout, workspaceDispatcher.createFile(FolderType.REPORT, true, reportFolder, "scriptlog.html").getPath()); htmlFileAppender.setName("HTMLTESTSCRIPTFILEAPPENDER"); htmlFileAppender.setThreshold(Level.toLevel(scriptSettings.getFileLoggerLevel())); PatternLayout conLayout = new PatternLayout(scriptSettings.getConsoleLayout()); ConsoleAppender conAppender = new ConsoleAppender(conLayout); conAppender.setThreshold(Level.toLevel(scriptSettings.getConsoleLoggerLevel())); conAppender.activateOptions(); scriptLogger.addAppender(fileAppender); scriptLogger.addAppender(conAppender); scriptLogger.addAppender(htmlFileAppender); return LoggerFactory.getLogger(scriptLogger.getName()); }