Java Code Examples for org.apache.log4j.Logger#removeAllAppenders()
The following examples show how to use
org.apache.log4j.Logger#removeAllAppenders() .
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: LoggerBuilder.java From jforgame with Apache License 2.0 | 7 votes |
private static Logger build(String name) { Logger logger = Logger.getLogger(name); logger.removeAllAppenders(); logger.setLevel(Level.INFO); logger.setAdditivity(false); RollingFileAppender appender = new RollingFileAppender(); PatternLayout layout = new PatternLayout(); String conversionPatten = "[%d] %p %t %c - %m%n"; layout.setConversionPattern(conversionPatten); appender.setLayout(layout); appender.setEncoding("utf-8"); appender.setAppend(true); TimeBasedRollingPolicy policy = new TimeBasedRollingPolicy(); String fp = LoggerBuilder.LOG_PATH + name + "/" + name + ".log.%d{yyyy-MM-dd}"; policy.setFileNamePattern(fp); appender.setRollingPolicy(policy); appender.activateOptions(); logger.addAppender(appender); container.put(name,logger); return logger; }
Example 2
Source File: TestAutoLocalMode.java From spork with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception{ pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getProperties()); pigServer.getPigContext().getExecutionEngine().setProperty(PigConfiguration.PIG_OPT_FETCH, "false"); pigServer.getPigContext().getExecutionEngine().setProperty(PigConfiguration.PIG_AUTO_LOCAL_ENABLED, String.valueOf("true")); pigServer.getPigContext().getExecutionEngine().setProperty(PigConfiguration.PIG_AUTO_LOCAL_INPUT_MAXBYTES, "200"); Logger logger = Logger.getLogger(JobControlCompiler.class); logger.removeAllAppenders(); logger.setLevel(Level.INFO); SimpleLayout layout = new SimpleLayout(); logFile = File.createTempFile("log", ""); FileAppender appender = new FileAppender(layout, logFile.toString(), false, false, 0); logger.addAppender(appender); miniFileName = createInputFile("miniFile", 10).getAbsolutePath(); smallFileName = createInputFile("smallFile", 100).getAbsolutePath(); bigFileName = createInputFile("bigFile", 1000).getAbsolutePath(); }
Example 3
Source File: LogUtils.java From stratosphere with Apache License 2.0 | 5 votes |
public static void initializeDefaultConsoleLogger(Level logLevel) { Logger root = Logger.getRootLogger(); root.removeAllAppenders(); PatternLayout layout = new PatternLayout("%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n"); ConsoleAppender appender = new ConsoleAppender(layout, "System.err"); root.addAppender(appender); root.setLevel(logLevel); }
Example 4
Source File: TestPredeployedJar.java From spork with Apache License 2.0 | 5 votes |
@Test public void testPredeployedJar() throws IOException, ClassNotFoundException { Logger logger = Logger.getLogger(JobControlCompiler.class); logger.removeAllAppenders(); logger.setLevel(Level.INFO); SimpleLayout layout = new SimpleLayout(); File logFile = File.createTempFile("log", ""); FileAppender appender = new FileAppender(layout, logFile.toString(), false, false, 0); logger.addAppender(appender); PigServer pigServer = new PigServer(ExecType.MAPREDUCE, cluster.getConfiguration()); pigServer.getPigContext().getProperties().put(PigConfiguration.PIG_OPT_FETCH, "false"); String[] inputData = new String[] { "hello", "world" }; Util.createInputFile(cluster, "a.txt", inputData); String jodaTimeJar = JarManager.findContainingJar(org.joda.time.DateTime.class); pigServer.registerQuery("a = load 'a.txt' as (line:chararray);"); Iterator<Tuple> it = pigServer.openIterator("a"); String content = FileUtils.readFileToString(logFile); Assert.assertTrue(content.contains(jodaTimeJar)); logFile = File.createTempFile("log", ""); // Now let's mark the guava jar as predeployed. pigServer.getPigContext().markJarAsPredeployed(jodaTimeJar); it = pigServer.openIterator("a"); content = FileUtils.readFileToString(logFile); Assert.assertFalse(content.contains(jodaTimeJar)); }
Example 5
Source File: Util.java From spork with Apache License 2.0 | 5 votes |
/** * Delete the existing logFile for the class and set the logging to a * use a new log file and set log level to DEBUG * @param clazz class for which the log file is being set * @param logFile current log file * @return new log file * @throws Exception */ public static File resetLog(Class<?> clazz, File logFile) throws Exception { if (logFile != null) logFile.delete(); Logger logger = Logger.getLogger(clazz); logger.removeAllAppenders(); logger.setLevel(Level.DEBUG); SimpleLayout layout = new SimpleLayout(); File newLogFile = File.createTempFile("log", ""); FileAppender appender = new FileAppender(layout, newLogFile.toString(), false, false, 0); logger.addAppender(appender); return newLogFile; }
Example 6
Source File: TestTmpFileCompression.java From spork with Apache License 2.0 | 5 votes |
private void resetLog(Class<?> clazz) throws Exception { if (logFile != null) logFile.delete(); Logger logger = Logger.getLogger(clazz); logger.removeAllAppenders(); logger.setLevel(Level.DEBUG); SimpleLayout layout = new SimpleLayout(); logFile = File.createTempFile("log", ""); FileAppender appender = new FileAppender(layout, logFile.toString(), false, false, 0); logger.addAppender(appender); }
Example 7
Source File: TestOrcStoragePushdown.java From spork with Apache License 2.0 | 5 votes |
@BeforeClass public static void oneTimeSetup() throws Exception{ cluster = MiniGenericCluster.buildCluster(); Util.copyFromLocalToCluster(cluster, basedir + "orc-file-11-format.orc", basedir + "orc-file-11-format.orc"); Util.copyFromLocalToCluster(cluster, basedir + "charvarchar.orc", basedir + "charvarchar.orc"); createInputData(); if(Util.WINDOWS){ OUTPUT1 = OUTPUT1.replace("\\", "/"); OUTPUT2 = OUTPUT2.replace("\\", "/"); OUTPUT3 = OUTPUT3.replace("\\", "/"); OUTPUT4 = OUTPUT4.replace("\\", "/"); } supportedOpTypes = new ArrayList<OpType>(); supportedOpTypes.add(OpType.OP_EQ); supportedOpTypes.add(OpType.OP_NE); supportedOpTypes.add(OpType.OP_GT); supportedOpTypes.add(OpType.OP_GE); supportedOpTypes.add(OpType.OP_LT); supportedOpTypes.add(OpType.OP_LE); supportedOpTypes.add(OpType.OP_IN); supportedOpTypes.add(OpType.OP_BETWEEN); supportedOpTypes.add(OpType.OP_NULL); supportedOpTypes.add(OpType.OP_NOT); supportedOpTypes.add(OpType.OP_AND); supportedOpTypes.add(OpType.OP_OR); Logger logger = Logger.getLogger(ColumnPruneVisitor.class); logger.removeAllAppenders(); logger.setLevel(Level.INFO); SimpleLayout layout = new SimpleLayout(); logFile = File.createTempFile("log", ""); FileAppender appender = new FileAppender(layout, logFile.toString(), false, false, 0); logger.addAppender(appender); }
Example 8
Source File: TestSimpleFlamdexDocWriter.java From imhotep with Apache License 2.0 | 5 votes |
@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 9
Source File: AbstractFTGSMergerCase.java From imhotep with Apache License 2.0 | 5 votes |
@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 10
Source File: TestLocalImhotepServiceCore.java From imhotep with Apache License 2.0 | 5 votes |
@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 11
Source File: TestUtils.java From desktop with GNU General Public License v3.0 | 5 votes |
private TestUtils(){ computerList = new LinkedList<Computer>(); BasicConfigurator.configure(); Logger logger = Logger.getRootLogger(); logger.setLevel(Level.WARN); logger.removeAllAppenders(); if(!logg.isAttached(log)){ logg.addAppender(log); } File folder = new File(testFolder); folder.mkdir(); try { String line; BufferedReader in = new BufferedReader(new FileReader("test/org/stacksync/test/distributed/Computers.txt")); stacksyncFolderPath = in.readLine(); while ((line = in.readLine()) != null) { StringTokenizer stk = new StringTokenizer(line, ","); computerList.add(new Computer(stk.nextToken(), stk.nextToken(), stk.nextToken())); } in.close(); } catch (IOException e) { logg.error("Failed to set up the tests"); System.exit(0); } }
Example 12
Source File: JobLoggerTest.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
private File initLoggers() throws IOException { Logger jobLogger = Logger.getLogger(JobLogger.class); FileAppender appender = ServerJobAndTaskLogs.createFileAppender(); File logFolder = folder.newFolder("logs"); appender.setFilesLocation(logFolder.getAbsolutePath()); jobLogger.removeAllAppenders(); jobLogger.addAppender(appender); return logFolder; }
Example 13
Source File: MavenLog4JConfigurator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void configureLog4j(Log log, String name) { Logger logger = Logger.getLogger(name); logger.setAdditivity(false); try { logger.setLevel(LOG4J_DEFAULT_LOG_LEVEL); } catch (NoSuchMethodError e) { // see http://bugzilla.slf4j.org/show_bug.cgi?id=279 } logger.removeAllAppenders(); logger.addAppender(createMojoLogAppender(log)); }
Example 14
Source File: SFTPFileSystemLoggingTest.java From sftp-fs with Apache License 2.0 | 5 votes |
@BeforeAll public static void setupLogging() { logger = LogManager.getLogger(SFTPLoggerTest.class.getPackage().getName()); originalLevel = logger.getLevel(); logger.setLevel(Level.TRACE); originalAppenders = getAllAppenders(logger); logger.removeAllAppenders(); Logger root = LogManager.getRootLogger(); originalRootAppenders = getAllAppenders(root); root.removeAllAppenders(); }
Example 15
Source File: TestLog4Json.java From big-c with Apache License 2.0 | 5 votes |
private String logOut(String message, Throwable throwable) { StringWriter writer = new StringWriter(); Logger logger = createLogger(writer); logger.info(message, throwable); //remove and close the appender logger.removeAllAppenders(); return writer.toString(); }
Example 16
Source File: TestLog4Json.java From hadoop with Apache License 2.0 | 5 votes |
private String logOut(String message, Throwable throwable) { StringWriter writer = new StringWriter(); Logger logger = createLogger(writer); logger.info(message, throwable); //remove and close the appender logger.removeAllAppenders(); return writer.toString(); }
Example 17
Source File: ProcessLoggerProvider.java From multiapps-controller with Apache License 2.0 | 5 votes |
private ProcessLogger createProcessLogger(String spaceId, String correlationId, String activityId, String loggerName, String logName, PatternLayout layout) { Logger logger = Logger.getLogger(loggerName); File logFile = getLocalFile(loggerName); logger.removeAllAppenders(); logger.addAppender(createAppender(logger.getLevel(), logFile, layout)); return new ProcessLogger(logger, logFile, logName, spaceId, correlationId, activityId); }
Example 18
Source File: PropertiesHelper.java From wings with Apache License 2.0 | 5 votes |
public static void removeLogger(String classname) { Logger logger = classLoggers.get(classname); if (logger != null) { classLoggers.remove(classname); logger.removeAllAppenders(); } }
Example 19
Source File: Log4jConfig.java From base-module with Apache License 2.0 | 4 votes |
public void configure(final Logger root) { root.removeAllAppenders(); configureFileAppender(root); root.setLevel(mLevel); }
Example 20
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** Used internally to parse the children of a category element. */ protected void parseChildrenOfLoggerElement(Element catElement, Logger cat, boolean isRoot) { PropertySetter propSetter = new PropertySetter(cat); // Remove all existing appenders from cat. They will be // reconstructed if need be. cat.removeAllAppenders(); NodeList children = catElement.getChildNodes(); final int length = children.getLength(); for (int loop = 0; loop < length; loop++) { Node currentNode = children.item(loop); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { Element currentElement = (Element) currentNode; String tagName = currentElement.getTagName(); if (tagName.equals(APPENDER_REF_TAG)) { Element appenderRef = (Element) currentNode; Appender appender = findAppenderByReference(appenderRef); String refName = subst(appenderRef.getAttribute(REF_ATTR)); if(appender != null) LogLog.debug("Adding appender named ["+ refName+ "] to category ["+cat.getName()+"]."); else LogLog.debug("Appender named ["+ refName + "] not found."); cat.addAppender(appender); } else if(tagName.equals(LEVEL_TAG)) { parseLevel(currentElement, cat, isRoot); } else if(tagName.equals(PRIORITY_TAG)) { parseLevel(currentElement, cat, isRoot); } else if(tagName.equals(PARAM_TAG)) { setParameter(currentElement, propSetter); } else { quietParseUnrecognizedElement(cat, currentElement, props); } } } propSetter.activate(); }