Java Code Examples for org.apache.log4j.Logger#getLevel()
The following examples show how to use
org.apache.log4j.Logger#getLevel() .
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: AkxLog4jManager.java From wind-im with Apache License 2.0 | 6 votes |
public static void setLogLevel(Level level) { try { Logger rootLogger = Logger.getRootLogger(); if (rootLogger.getLevel() == level) { return; } rootLogger.setLevel(level); Enumeration<Logger> logEnum = getAllLogger(); while (logEnum.hasMoreElements()) { Logger logger = logEnum.nextElement(); logger.setLevel(level); } logger.info("set site server log_level=" + level); } catch (Exception e) { logger.error("update log4j level=" + level + " error", e); } logger.info("update log4j level=" + level + " finish"); }
Example 2
Source File: GraphSONMessageSerializerV3d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldFailOnMessageSerializerWithMapperIfNoGremlinServerModule() { Logger logger = Logger.getLogger(AbstractGraphSONMessageSerializerV2d0.class); Level previousLevel = logger.getLevel(); // Disable temporarily logging for this test logger.setLevel(Level.OFF); GraphSONMapper.Builder builder = GraphSONMapper.build().addCustomModule(GraphSONXModuleV3d0.build().create(false)); GraphSONMessageSerializerV3d0 graphSONMessageSerializerV3d0 = new GraphSONMessageSerializerV3d0(builder.create()); try { convert("hello", graphSONMessageSerializerV3d0); fail("Serialization should have failed since no GremlinServerModule registered."); } catch (SerializationException e) { assertTrue(e.getMessage().contains("Could not find a type identifier for the class")); assertTrue(e.getCause() instanceof JsonMappingException); assertTrue(e.getCause().getCause() instanceof IllegalArgumentException); } // Put logger level back to its original value logger.setLevel(previousLevel); }
Example 3
Source File: CBMutationOutputFormatterTest.java From datawave with Apache License 2.0 | 6 votes |
@Before public void setup() { testDriverLevel = CBMutationOutputFormatterTest.logger.getLevel(); CBMutationOutputFormatterTest.logger.setLevel(Level.ALL); uutAppender = new CommonTestAppender(); Logger uutLogger = Logger.getLogger(CBMutationOutputFormatter.class); uutLevel = uutLogger.getLevel(); uutLogger.setLevel(Level.ALL); uutLogger.addAppender(uutAppender); Logger.getLogger(AccumuloOutputFormat.class).addAppender(uutAppender); TypeRegistry.reset(); }
Example 4
Source File: UrlRewriteRulesDescriptorFactoryTest.java From knox with Apache License 2.0 | 6 votes |
@Test public void testLoadEmptyFile() { Logger logger = org.apache.log4j.LogManager.getLogger( "org.apache.commons.digester3.Digester" ); Level level = logger.getLevel(); try { logger.setLevel( org.apache.log4j.Level.OFF ); UrlRewriteRulesDescriptorFactory.load( "xml", getTestResourceReader( "empty.xml" ) ); fail( "Should have thrown an IOException." ); } catch ( IOException e ) { // Expected. assertEquals("org.xml.sax.SAXParseException; lineNumber: 16; " + "columnNumber: 4; Premature end of file.", e.getMessage()); } catch ( Throwable t ) { fail( "Should have thrown an IOException." ); } finally { logger.setLevel( level ); } }
Example 5
Source File: XmlGatewayDescriptorImporterTest.java From knox with Apache License 2.0 | 6 votes |
@Test public void testXmlGatewayDescriptorLoadInvalid() throws IOException { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<gateway>\n" + " <resource>\n" + " <filter>\n" + " <param>"; Reader reader = new StringReader( xml ); // Keep the tests quiet. Ignore the stack trace that ends up being written to System.out. Logger logger = Logger.getLogger( "org.apache.commons.digester3.Digester" ); Level level = logger.getLevel(); logger.setLevel( Level.OFF ); PrintStream out = System.out; System.setOut( null ); try { GatewayDescriptorFactory.load( "xml", reader ); fail( "Should have thrown IOException" ); } catch( IOException e ) { assertThat( e.getMessage(), containsString( "org.xml.sax.SAXParseException" ) ); } finally { System.setOut( out ); logger.setLevel( level ); } }
Example 6
Source File: AkxLog4jManager.java From openzaly with Apache License 2.0 | 6 votes |
public static void setLogLevel(Level level) { try { Logger rootLogger = Logger.getRootLogger(); if (rootLogger.getLevel() == level) { return; } rootLogger.setLevel(level); Enumeration<Logger> logEnum = getAllLogger(); while (logEnum.hasMoreElements()) { Logger logger = logEnum.nextElement(); logger.setLevel(level); } logger.info("set site server log_level=" + level); } catch (Exception e) { logger.error("update log4j level=" + level + " error", e); } logger.info("update log4j level=" + level + " finish"); }
Example 7
Source File: Log4jHelper.java From arthas with Apache License 2.0 | 6 votes |
private static Map<String, Object> doGetLoggerInfo(Logger logger) { Map<String, Object> info = new HashMap<String, Object>(); info.put(LoggerHelper.name, logger.getName()); info.put(LoggerHelper.clazz, logger.getClass()); CodeSource codeSource = logger.getClass().getProtectionDomain().getCodeSource(); if (codeSource != null) { info.put(LoggerHelper.codeSource, codeSource.getLocation()); } info.put(LoggerHelper.additivity, logger.getAdditivity()); Level level = logger.getLevel(), effectiveLevel = logger.getEffectiveLevel(); if (level != null) { info.put(LoggerHelper.level, level.toString()); } if (effectiveLevel != null) { info.put(LoggerHelper.effectiveLevel, effectiveLevel.toString()); } @SuppressWarnings("unchecked") List<Map<String, Object>> result = doGetLoggerAppenders(logger.getAllAppenders()); info.put(LoggerHelper.appenders, result); return info; }
Example 8
Source File: PropertySourceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("serial") public void toString_verbosityVariesOnLogLevel() { String name = "props"; Map<String, Object> map = new HashMap<String, Object>() {{ put("k1", "v1"); }}; MapPropertySource ps = new MapPropertySource(name, map); Logger logger = Logger.getLogger(ps.getClass()); Level original = logger.getLevel(); try { logger.setLevel(Level.DEBUG); assertThat("PropertySource.toString() should render verbose output for log levels <= DEBUG", ps.toString(), equalTo(String.format("%s@%s [name='%s', properties=%s]", ps.getClass().getSimpleName(), System.identityHashCode(ps), name, map))); logger.setLevel(Level.INFO); assertThat("PropertySource.toString() should render concise output for log levels >= INFO", ps.toString(), equalTo(String.format("%s [name='%s']", ps.getClass().getSimpleName(), name, map.size()))); } finally { logger.setLevel(original); } }
Example 9
Source File: BulkIngestMapFileLoaderTest.java From datawave with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { systemProperties = new ArrayList<>(); testDriverLevel = BulkIngestMapFileLoaderTest.logger.getLevel(); BulkIngestMapFileLoaderTest.logger.setLevel(Level.ALL); Logger uutLogger = Logger.getLogger(BulkIngestMapFileLoader.class); uutAppender = new CommonTestAppender(); uutLevel = uutLogger.getLevel(); uutLogger.setLevel(Level.ALL); uutLogger.addAppender(uutAppender); }
Example 10
Source File: ReservedKeysVerificationStrategyTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Before public void setupForEachTest() { final Logger strategyLogger = Logger.getLogger(AbstractWarningVerificationStrategy.class); previousLogLevel = strategyLogger.getLevel(); strategyLogger.setLevel(Level.WARN); Logger.getRootLogger().addAppender(logAppender = new TestLogAppender()); }
Example 11
Source File: MetadataTableSplitsTest.java From datawave with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { mockConfiguration.clear(); mockConfiguration.put(MetadataTableSplits.REFRESH_SPLITS, "false"); testDriverLevel = logger.getLevel(); logger.setLevel(Level.ALL); Logger uutLog = Logger.getLogger(MetadataTableSplits.class); uutLevel = uutLog.getLevel(); uutLog.setLevel(Level.ALL); Logger zcLog = Logger.getLogger(ZooCache.class); zooCacheLevel = zcLog.getLevel(); zcLog.setLevel(Level.ALL); Logger zkLog = Logger.getLogger(ZooKeeper.class); zooKeeperLevel = zkLog.getLevel(); zkLog.setLevel(Level.ALL); createMockFileSystem(); MetadataTableSplitsTest.FILE_STATUS_MODIFICATION_TIME = MetadataTableSplitsTest.FILE_STATUS_ACCESS_TIME = 0l; MetadataTableSplitsTest.FILE_STATUS_USER = MetadataTableSplitsTest.USER_NAME; MetadataTableSplitsTest.FILE_STATUS_GROUP = MetadataTableSplitsTest.USER_NAME; }
Example 12
Source File: LoggerUtil.java From attic-apex-core with Apache License 2.0 | 5 votes |
public static synchronized ImmutableMap<String, String> getClassesMatching(@Nonnull String searchKey) { Pattern searchPattern = Pattern.compile(searchKey); Map<String, String> matchedClasses = Maps.newHashMap(); @SuppressWarnings("unchecked") Enumeration<Logger> loggerEnumeration = LogManager.getCurrentLoggers(); while (loggerEnumeration.hasMoreElements()) { Logger logger = loggerEnumeration.nextElement(); if (searchPattern.matcher(logger.getName()).matches()) { Level level = logger.getLevel(); matchedClasses.put(logger.getName(), level == null ? "" : level.toString()); } } return ImmutableMap.copyOf(matchedClasses); }
Example 13
Source File: LambdaLogger.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
/** * Run the supplied code, quieting the supplied log with the specified Level */ public static final void quiet(Class<?> cls, Level set, Code code) throws Exception { final Logger log = Logger.getLogger(cls); final Level curr = log.getLevel(); log.setLevel(set); try { code.run(); } finally { log.setLevel(curr); } }
Example 14
Source File: MetadataTableConfigHelperTest.java From datawave with Apache License 2.0 | 5 votes |
@Before public void setup() { Level desiredLevel = Level.ALL; Logger log = Logger.getLogger(MetadataTableConfigHelperTest.class); MetadataTableConfigHelperTest.testDriverLevel = log.getLevel(); log.setLevel(desiredLevel); }
Example 15
Source File: LoggerConfigurator.java From maven-framework-project with MIT License | 5 votes |
@ManagedOperation(description = "Returns the Logger LEVEL for the given logger name") @ManagedOperationParameters({ @ManagedOperationParameter(description = "The Logger Name", name = "loggerName"), }) public String getLoggerLevel(String loggerName) { Logger logger = Logger.getLogger(loggerName); Level loggerLevel = logger.getLevel(); return loggerLevel == null ? "The logger " + loggerName + " has not level" : loggerLevel.toString(); }
Example 16
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testGetMethods() { Column c1 = new Column("f1", "q1"); Column c2 = new Column("f1", "q2"); try (Transaction tx = client.newTransaction()) { tx.set("r1", c1, "v1"); tx.set("r1", c2, "v2"); tx.set("r2", c1, "v3"); tx.set("r2", c2, "v4"); tx.commit(); } Logger logger = Logger.getLogger("fluo.tx"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} [%-8c{2}] %-5p: %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (Snapshot snap = client.newSnapshot()) { Map<RowColumn, String> ret1 = snap.gets(Arrays.asList(new RowColumn("r1", c1), new RowColumn("r2", c2))); Assert.assertEquals( ImmutableMap.of(new RowColumn("r1", c1), "v1", new RowColumn("r2", c2), "v4"), ret1); Map<String, Map<Column, String>> ret2 = snap.gets(Arrays.asList("r1", "r2"), ImmutableSet.of(c1)); Assert.assertEquals( ImmutableMap.of("r1", ImmutableMap.of(c1, "v1"), "r2", ImmutableMap.of(c1, "v3")), ret2); Map<Column, String> ret3 = snap.gets("r1", ImmutableSet.of(c1, c2)); Assert.assertEquals(ImmutableMap.of(c1, "v1", c2, "v2"), ret3); Assert.assertEquals("v1", snap.gets("r1", c1)); } miniFluo.waitForObservers(); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } String pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 \\Qget([r1 f1 q1 , r2 f1 q2 ]) -> [r2 f1 q2 =v4, r1 f1 q1 =v1]\\E"; pattern += ".*txid: \\1 \\Qget([r1, r2], [f1 q1 ]) -> [r1=[f1 q1 =v1], r2=[f1 q1 =v3]]\\E"; pattern += ".*txid: \\1 \\Qget(r1, [f1 q1 , f1 q2 ]) -> [f1 q1 =v1, f1 q2 =v2]\\E"; pattern += ".*txid: \\1 \\Qget(r1, f1 q1 ) -> v1\\E"; pattern += ".*txid: \\1 close\\(\\).*"; String origLogMsgs = writer.toString(); String logMsgs = origLogMsgs.replace('\n', ' '); Assert.assertTrue(logMsgs.matches(pattern)); }
Example 17
Source File: AkxLog4jManager.java From openzaly with Apache License 2.0 | 4 votes |
public static Level getLogLevel() { Logger rootLogger = Logger.getRootLogger(); return rootLogger.getLevel(); }
Example 18
Source File: LogIT.java From fluo with Apache License 2.0 | 4 votes |
@Test public void testBinaryLogging() throws Exception { Logger logger = Logger.getLogger("fluo.tx"); StringWriter writer = new StringWriter(); WriterAppender appender = new WriterAppender(new PatternLayout("%d{ISO8601} [%-8c{2}] %-5p: %m%n"), writer); Level level = logger.getLevel(); boolean additivity = logger.getAdditivity(); try { logger.setLevel(Level.TRACE); logger.setAdditivity(false); logger.addAppender(appender); try (LoaderExecutor le = client.newLoaderExecutor()) { le.execute(new BinaryLoader1()); } miniFluo.waitForObservers(); String pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 class: org.apache.fluo.integration.log.LogIT\\$BinaryLoader1"; pattern += ".*txid: \\1 \\Qdelete(r\\x051, c\\x021 c\\xf51 )\\E"; pattern += ".*txid: \\1 \\Qget(r\\x062, c\\x021 c\\xf51 ) -> null\\E"; pattern += ".*txid: \\1 \\Qget(r\\x062, [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> []\\E"; pattern += ".*txid: \\1 \\Qget([r\\x051, r\\x062], [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> []\\E"; pattern += ".*txid: \\1 \\Qset(r\\x051, c\\x092 c\\xe52 , v\\x992)\\E"; pattern += ".*txid: \\1 \\Qset(r\\x062, c\\x092 c\\xe52 , v\\xd91)\\E"; pattern += ".*txid: \\1 \\QsetWeakNotification(r\\x062, c\\x092 c\\xe52 )\\E"; pattern += ".*txid: \\1 \\Qcommit()\\E -> SUCCESSFUL commitTs: \\d+"; pattern += ".*"; String origLogMsgs = writer.toString(); String logMsgs = origLogMsgs.replace('\n', ' '); Assert.assertTrue(origLogMsgs, logMsgs.matches(pattern)); waitForClose(writer, pattern); final String v1 = "\\Qr\\x051=[c\\x092 c\\xe52 =v\\x992]\\E"; final String v2 = "\\Qr\\x062=[c\\x092 c\\xe52 =v\\xd91]\\E"; pattern = ".*txid: (\\d+) begin\\(\\) thread: \\d+"; pattern += ".*txid: \\1 \\Qtrigger: r\\x062 c\\x092 c\\xe52 4\\E"; pattern += ".*txid: \\1 \\Qclass: org.apache.fluo.integration.log.LogIT$BinaryObserver\\E"; pattern += ".*txid: \\1 \\Qget(r\\x051, c\\x092 c\\xe52 ) -> v\\x992\\E"; pattern += ".*txid: \\1 \\Qget(r\\x062, [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> " + "[c\\x092 c\\xe52 =v\\xd91]\\E"; pattern += ".*txid: \\1 \\Qget([r\\x051, r\\x062], [c\\x021 c\\xf51 , c\\x092 c\\xe52 ]) -> " + "[\\E(" + v1 + "|" + v2 + ")\\, (" + v1 + "|" + v2 + ")\\]"; pattern += ".*txid: \\1 \\Qcommit() -> SUCCESSFUL commitTs: -1\\E"; pattern += ".*"; Assert.assertTrue(origLogMsgs, logMsgs.matches(pattern)); waitForClose(writer, pattern); } finally { logger.removeAppender(appender); logger.setAdditivity(additivity); logger.setLevel(level); } }
Example 19
Source File: LoggerUtil.java From attic-apex-core with Apache License 2.0 | 4 votes |
public static synchronized void changeLoggersLevel(@Nonnull Map<String, String> targetChanges) { /* remove existing patterns which are subsets of new patterns. for eg. if x.y.z.* will be removed if * there is x.y.* in the target changes. */ for (Map.Entry<String, String> changeEntry : targetChanges.entrySet()) { Iterator<Map.Entry<String, Pattern>> patternsIterator = patterns.entrySet().iterator(); while ((patternsIterator.hasNext())) { Map.Entry<String, Pattern> entry = patternsIterator.next(); String finer = entry.getKey(); String wider = changeEntry.getKey(); if (finer.length() < wider.length()) { continue; } boolean remove = false; for (int i = 0; i < wider.length(); i++) { if (wider.charAt(i) == '*') { remove = true; break; } if (wider.charAt(i) != finer.charAt(i)) { break; } else if (i == wider.length() - 1) { remove = true; } } if (remove) { patternsIterator.remove(); patternLevel.remove(finer); } } } for (Map.Entry<String, String> loggerEntry : targetChanges.entrySet()) { String target = loggerEntry.getKey(); patternLevel.put(target, Level.toLevel(loggerEntry.getValue())); patterns.put(target, Pattern.compile(target)); } if (!patternLevel.isEmpty()) { @SuppressWarnings("unchecked") Enumeration<Logger> loggerEnumeration = LogManager.getCurrentLoggers(); while (loggerEnumeration.hasMoreElements()) { Logger classLogger = loggerEnumeration.nextElement(); Level oldLevel = classLogger.getLevel(); Level newLevel = getLevelFor(classLogger.getName()); if (newLevel != null && (oldLevel == null || !newLevel.equals(oldLevel))) { logger.info("changing level of {} to {}", classLogger.getName(), newLevel); classLogger.setLevel(newLevel); } } } }
Example 20
Source File: UnitTestHelper.java From metron with Apache License 2.0 | 4 votes |
public static Level getLog4jLevel(Class clazz) { Logger logger = Logger.getLogger(clazz); return logger.getLevel(); }