Java Code Examples for org.apache.logging.log4j.Level#getLevel()
The following examples show how to use
org.apache.logging.log4j.Level#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: MCRLoggingCommands.java From mycore with GNU General Public License v3.0 | 6 votes |
/** * @param name * the name of the java class or java package to set the log * level for * @param logLevelToSet * the log level to set e.g. TRACE, DEBUG, INFO, WARN, ERROR and * FATAL, providing any other value will lead to DEBUG as new log * level */ @MCRCommand(syntax = "change log level of {0} to {1}", help = "{0} the package or class name for which to change the log level, {1} the log level to set.", order = 10) public static synchronized void changeLogLevel(String name, String logLevelToSet) { LOGGER.info("Setting log level for \"{}\" to \"{}\"", name, logLevelToSet); Level newLevel = Level.getLevel(logLevelToSet); if (newLevel == null) { LOGGER.error("Unknown log level \"{}\"", logLevelToSet); return; } Logger log = "ROOT".equals(name) ? LogManager.getRootLogger() : LogManager.getLogger(name); if (log == null) { LOGGER.error("Could not get logger for \"{}\"", name); return; } LOGGER.info("Change log level from {} to {}", log.getLevel(), newLevel); Configurator.setLevel(log.getName(), newLevel); }
Example 2
Source File: LevelTagTest.java From spectator with Apache License 2.0 | 5 votes |
@Test public void levels() { for (StandardLevel std : StandardLevel.values()) { Level level = Level.getLevel(std.name()); Assertions.assertEquals(std, LevelTag.get(level).standardLevel()); } }
Example 3
Source File: BasicConfigurationFactory.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public BasicConfiguration(final LoggerContext loggerContext) { super(loggerContext, ConfigurationSource.NULL_SOURCE); final LoggerConfig root = getRootLogger(); setName("BasicConfiguration"); final String levelName = System.getProperty(DEFAULT_LEVEL); final Level level = (levelName != null && Level.getLevel(levelName) != null) ? Level.getLevel(levelName) : Level.DEBUG; root.setLevel(level); }
Example 4
Source File: BasicConfigurationFactory.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public BasicConfiguration(final LoggerContext loggerContext) { super(loggerContext, ConfigurationSource.NULL_SOURCE); final LoggerConfig root = getRootLogger(); setName("BasicConfiguration"); final String levelName = System.getProperty(DEFAULT_LEVEL); final Level level = (levelName != null && Level.getLevel(levelName) != null) ? Level.getLevel(levelName) : Level.DEBUG; root.setLevel(level); }
Example 5
Source File: LevelMixInTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Test public void testNameOnly() throws IOException { final Level expected = Level.getLevel("DEBUG"); final String str = writer.writeValueAsString(expected); Assert.assertTrue(str.contains("DEBUG")); final Level actual = reader.readValue(str); Assert.assertEquals(expected, actual); }
Example 6
Source File: DefaultMergeStrategy.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Merge the root properties. * @param rootNode The composite root node. * @param configuration The configuration to merge. */ @Override public void mergeRootProperties(final Node rootNode, final AbstractConfiguration configuration) { for (final Map.Entry<String, String> attribute : configuration.getRootNode().getAttributes().entrySet()) { boolean isFound = false; for (final Map.Entry<String, String> targetAttribute : rootNode.getAttributes().entrySet()) { if (targetAttribute.getKey().equalsIgnoreCase(attribute.getKey())) { if (attribute.getKey().equalsIgnoreCase(STATUS)) { final Level targetLevel = Level.getLevel(targetAttribute.getValue().toUpperCase()); final Level sourceLevel = Level.getLevel(attribute.getValue().toUpperCase()); if (targetLevel != null && sourceLevel != null) { if (sourceLevel.isLessSpecificThan(targetLevel)) { targetAttribute.setValue(attribute.getValue()); } } else if (sourceLevel != null) { targetAttribute.setValue(attribute.getValue()); } } else { if (attribute.getKey().equalsIgnoreCase("monitorInterval")) { final int sourceInterval = Integer.parseInt(attribute.getValue()); final int targetInterval = Integer.parseInt(targetAttribute.getValue()); if (targetInterval == 0 || sourceInterval < targetInterval) { targetAttribute.setValue(attribute.getValue()); } } else { targetAttribute.setValue(attribute.getValue()); } } isFound = true; } } if (!isFound) { rootNode.getAttributes().put(attribute.getKey(), attribute.getValue()); } } }
Example 7
Source File: CustomLevelsTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Before public void before() { diagLevel = Level.getLevel("DIAG"); noticeLevel = Level.getLevel("NOTICE"); verboseLevel = Level.getLevel("VERBOSE"); listAppender = context.getListAppender("List1").clear(); }
Example 8
Source File: CustomLevelsOverrideTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Before public void before() { warnLevel = Level.getLevel("WARN"); infoLevel = Level.getLevel("INFO"); debugLevel = Level.getLevel("DEBUG"); listAppender = context.getListAppender("List1").clear(); }
Example 9
Source File: BasicConfigurationFactory.java From logging-log4j2 with Apache License 2.0 | 5 votes |
public BasicConfiguration() { super(null, ConfigurationSource.NULL_SOURCE); final LoggerConfig root = getRootLogger(); final String name = System.getProperty(DEFAULT_LEVEL); final Level level = (name != null && Level.getLevel(name) != null) ? Level.getLevel(name) : Level.ERROR; root.setLevel(level); }
Example 10
Source File: LoggingSettings.java From luna with MIT License | 4 votes |
/** * Returns the logging level for this file output entry. */ public Level getLevel() { return Level.getLevel(name()); }
Example 11
Source File: MongoDb4LevelCodec.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public Level decode(final BsonReader reader, final DecoderContext decoderContext) { return Level.getLevel(reader.readString()); }
Example 12
Source File: LoggerNameLevelRewritePolicy.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private static Level getLevel(final String name) { return Level.getLevel(name.toUpperCase(Locale.ROOT)); }
Example 13
Source File: CustomLevelsWithFiltersTest.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Before public void before() { infom1Level = Level.getLevel("INFOM1"); infop1Level = Level.getLevel("INFOP1"); }
Example 14
Source File: MongoDb3LevelCodec.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public Level decode(final BsonReader reader, final DecoderContext decoderContext) { return Level.getLevel(reader.readString()); }