Java Code Examples for org.apache.logging.log4j.Level#toLevel()
The following examples show how to use
org.apache.logging.log4j.Level#toLevel() .
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: Settings.java From BHBot with GNU General Public License v3.0 | 6 votes |
private void setLogLevelFromString(String level) { switch (level.toUpperCase()) { case "TRACE": case "DEBUG": case "INFO": case "WARN": case "ERROR": case "FATAL": case "OFF": case "ALL": logLevel = Level.toLevel(level); break; default: logLevel = Level.toLevel("INFO"); break; } }
Example 2
Source File: Config.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
private Config() { this.c = ConfigFactory.load(); final String logLevel = c.getString("log-level"); Level level = Level.toLevel(logLevel); final String lowerLevel = logLevel.toLowerCase(); if (lowerLevel.equals("debug") || lowerLevel.equals("telemetry")) { this.debug = true; } // force change Object ctx = LogManager.getContext(false); if (ctx instanceof LoggerContext) { LoggerContext context = (LoggerContext) ctx; Configuration configuration = context.getConfiguration(); LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); loggerConfig.setLevel(level); context.updateLoggers(); } }
Example 3
Source File: Log4j2Watcher.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void registerListener(ListenerConfig cfg) { if (history != null) throw new IllegalStateException("History already registered"); history = new CircularList<LogEvent>(cfg.size); Level threshold = (cfg.threshold != null) ? Level.toLevel(cfg.threshold) : Level.WARN; ThresholdFilter filter = ThresholdFilter.createFilter(threshold, Filter.Result.ACCEPT, Filter.Result.DENY); // If there's already an appender like this, remove it LoggerContext ctx = (LoggerContext) LogManager.getContext(false); LoggerConfig config = getLoggerConfig(ctx, LoggerInfo.ROOT_NAME); appender = new Log4j2Appender(this, filter, threshold); // "Log4j2WatcherAppender" config.removeAppender(appender.getName()); if (!appender.isStarted()) appender.start(); config.addAppender(appender, threshold, filter); ctx.updateLoggers(); }
Example 4
Source File: Adapter.java From iaf with Apache License 2.0 | 5 votes |
public void setRequestReplyLogging(boolean requestReplyLogging) { if (requestReplyLogging) { ConfigurationWarnings.add(this, log, "implementing setting of requestReplyLogging=true as msgLogLevel=Terse"); msgLogLevel = MSGLOG_LEVEL_TERSE; } else { ConfigurationWarnings.add(this, log, "implementing setting of requestReplyLogging=false as msgLogLevel=None"); msgLogLevel = Level.toLevel("OFF"); } }
Example 5
Source File: HighlightConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Creates a level style map where values are ANSI escape sequences given configuration options in {@code option[1]} * . * <p> * The format of the option string in {@code option[1]} is: * </p> * * <pre> * Level1=Value, Level2=Value, ... * </pre> * * <p> * For example: * </p> * * <pre> * ERROR=red bold, WARN=yellow bold, INFO=green, ... * </pre> * * <p> * You can use whitespace around the comma and equal sign. The names in values MUST come from the * {@linkplain AnsiEscape} enum, case is normalized to upper-case internally. * </p> * * @param options * The second slot can optionally contain the style map. * @return a new map */ private static Map<String, String> createLevelStyleMap(final String[] options) { if (options.length < 2) { return DEFAULT_STYLES; } // Feels like a hack. Should String[] options change to a Map<String,String>? final String string = options[1] .replaceAll(PatternParser.DISABLE_ANSI + "=(true|false)", Strings.EMPTY) .replaceAll(PatternParser.NO_CONSOLE_NO_ANSI + "=(true|false)", Strings.EMPTY); // final Map<String, String> styles = AnsiEscape.createMap(string, new String[] {STYLE_KEY}); final Map<String, String> levelStyles = new HashMap<>(DEFAULT_STYLES); for (final Map.Entry<String, String> entry : styles.entrySet()) { final String key = entry.getKey().toUpperCase(Locale.ENGLISH); final String value = entry.getValue(); if (STYLE_KEY.equalsIgnoreCase(key)) { final Map<String, String> enumMap = STYLES.get(value.toUpperCase(Locale.ENGLISH)); if (enumMap == null) { LOGGER.error("Unknown level style: " + value + ". Use one of " + Arrays.toString(STYLES.keySet().toArray())); } else { levelStyles.putAll(enumMap); } } else { final Level level = Level.toLevel(key, null); if (level == null) { LOGGER.warn("Setting style for yet unknown level name {}", key); levelStyles.put(key, value); } else { levelStyles.put(level.name(), value); } } } return levelStyles; }
Example 6
Source File: LevelAttributeConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public Level convertToEntityAttribute(final String s) { if (Strings.isEmpty(s)) { return null; } return Level.toLevel(s, null); }
Example 7
Source File: TagUtils.java From logging-log4j2 with Apache License 2.0 | 5 votes |
static Level resolveLevel(final Object level) { if (level instanceof Level) { return (Level) level; } if (level instanceof String) { return Level.toLevel((String) level); } return null; }
Example 8
Source File: LevelMatchFilterBuilder.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public Filter parseFilter(Element filterElement, XmlConfigurationFactory factory) { final Holder<String> level = new Holder<>(); final Holder<Boolean> acceptOnMatch = new BooleanHolder(); forEachElement(filterElement.getElementsByTagName("param"), (currentElement) -> { if (currentElement.getTagName().equals("param")) { switch (currentElement.getAttribute(NAME_ATTR).toLowerCase()) { case LEVEL: level.set(currentElement.getAttribute(VALUE_ATTR)); break; case ACCEPT_ON_MATCH: acceptOnMatch.set(Boolean.parseBoolean(currentElement.getAttribute(VALUE_ATTR))); break; } } }); Level lvl = Level.ERROR; if (level.get() != null) { lvl = Level.toLevel(level.get(), Level.ERROR); } org.apache.logging.log4j.core.Filter.Result onMatch = acceptOnMatch.get() != null && acceptOnMatch.get() ? org.apache.logging.log4j.core.Filter.Result.ACCEPT : org.apache.logging.log4j.core.Filter.Result.DENY; return new FilterWrapper(LevelMatchFilter.newBuilder() .setLevel(lvl) .setOnMatch(onMatch) .setOnMismatch(org.apache.logging.log4j.core.Filter.Result.NEUTRAL) .build()); }
Example 9
Source File: LevelRangeFilterBuilder.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public Filter parseFilter(Element filterElement, XmlConfigurationFactory factory) { final Holder<String> levelMax = new Holder<>(); final Holder<String> levelMin = new Holder<>(); final Holder<Boolean> acceptOnMatch = new BooleanHolder(); forEachElement(filterElement.getElementsByTagName("param"), (currentElement) -> { if (currentElement.getTagName().equals("param")) { switch (currentElement.getAttribute(NAME_ATTR).toLowerCase()) { case LEVEL_MAX: levelMax.set(currentElement.getAttribute(VALUE_ATTR)); break; case LEVEL_MIN: levelMax.set(currentElement.getAttribute(VALUE_ATTR)); break; case ACCEPT_ON_MATCH: acceptOnMatch.set(Boolean.parseBoolean(currentElement.getAttribute(VALUE_ATTR))); break; } } }); Level max = Level.FATAL; Level min = Level.TRACE; if (levelMax.get() != null) { max = Level.toLevel(levelMax.get(), Level.FATAL); } if (levelMin.get() != null) { min = Level.toLevel(levelMin.get(), Level.DEBUG); } org.apache.logging.log4j.core.Filter.Result onMatch = acceptOnMatch.get() != null && acceptOnMatch.get() ? org.apache.logging.log4j.core.Filter.Result.ACCEPT : org.apache.logging.log4j.core.Filter.Result.NEUTRAL; return new FilterWrapper(LevelRangeFilter.createFilter(min, max, onMatch, org.apache.logging.log4j.core.Filter.Result.DENY)); }
Example 10
Source File: LevelMatchFilterBuilder.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private Filter createFilter(String level, boolean acceptOnMatch) { Level lvl = Level.ERROR; if (level != null) { lvl = Level.toLevel(level, Level.ERROR); } org.apache.logging.log4j.core.Filter.Result onMatch = acceptOnMatch ? org.apache.logging.log4j.core.Filter.Result.ACCEPT : org.apache.logging.log4j.core.Filter.Result.DENY; return new FilterWrapper(LevelMatchFilter.newBuilder() .setLevel(lvl) .setOnMatch(onMatch) .setOnMismatch(org.apache.logging.log4j.core.Filter.Result.NEUTRAL) .build()); }
Example 11
Source File: AbstractConfiguration.java From logging-log4j2 with Apache License 2.0 | 5 votes |
protected Level getDefaultStatus() { final String statusLevel = PropertiesUtil.getProperties().getStringProperty( Constants.LOG4J_DEFAULT_STATUS_LEVEL, Level.ERROR.name()); try { return Level.toLevel(statusLevel); } catch (final Exception ex) { return Level.ERROR; } }
Example 12
Source File: Adapter.java From iaf with Apache License 2.0 | 5 votes |
@IbisDoc({"defines behaviour for logging messages. Configuration is done in the MSG appender in log4j4ibis.properties. " + "Possible values are: <table border='1'><tr><th>msgLogLevel</th><th>messages which are logged</th></tr>" + "<tr><td colspan='1'>Off</td> <td>No logging</td></tr>" + "<tr><td colspan='1'>Basic</td><td>Logs information from adapter level messages </td></tr>" + "<tr><td colspan='1'>Terse</td><td>Logs information from pipe messages.</td></tr>" + "<tr><td colspan='1'>All</td> <td>Logs all messages.</td></tr></table>", "BASIC"}) public void setMsgLogLevel(String level) throws ConfigurationException { Level toSet = Level.toLevel(level); if (toSet.name().equalsIgnoreCase(level)) //toLevel falls back to DEBUG, so to make sure the level has been changed this explicity check is used. msgLogLevel = toSet; else throw new ConfigurationException("illegal value for msgLogLevel ["+level+"]"); }
Example 13
Source File: Log4JSink.java From deprecated-security-advanced-modules with Apache License 2.0 | 5 votes |
public Log4JSink(final String name, final Settings settings, final String settingsPrefix, AuditLogSink fallbackSink) { super(name, settings, settingsPrefix, fallbackSink); loggerName = settings.get( settingsPrefix + ".log4j.logger_name","sgaudit"); auditLogger = LogManager.getLogger(loggerName); logLevel = Level.toLevel(settings.get(settingsPrefix + ".log4j.level","INFO").toUpperCase()); enabled = auditLogger.isEnabled(logLevel); }
Example 14
Source File: AsyncQueueFullPolicyFactory.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private static AsyncQueueFullPolicy createDiscardingAsyncQueueFullPolicy() { final PropertiesUtil util = PropertiesUtil.getProperties(); final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.INFO.name()); final Level thresholdLevel = Level.toLevel(level, Level.INFO); LOGGER.debug("Creating custom DiscardingAsyncQueueFullPolicy(discardThreshold:{})", thresholdLevel); return new DiscardingAsyncQueueFullPolicy(thresholdLevel); }
Example 15
Source File: Config.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
private void setLogLevel(final String logLevel) { Object ctx = LogManager.getContext(false); if (ctx instanceof LoggerContext) { LoggerContext context = (LoggerContext) ctx; Level level = Level.toLevel(logLevel); Configuration configuration = context.getConfiguration(); LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); loggerConfig.setLevel(level); context.updateLoggers(); this.debug = !logLevel.toLowerCase().equals("info"); } }
Example 16
Source File: LogUtil.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static void configureLogLevel(String logLevel) { Level level = Level.toLevel(logLevel); try { final Logger logger = (Logger) LogManager.getRootLogger(); logger.setLevel(level); } catch (Throwable t) { //We catch throwable as there is a case where logger level setting fails when old SLF4j library interferes. log.error("Could not set the log level to : " + level + ". Probably inconsistent Log4J class is loaded.", t); } }
Example 17
Source File: StatusConfiguration.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Specifies the logging level by name to use for filtering StatusLogger messages. * * @param status name of logger level to filter below. * @return {@code this} * @see Level */ public StatusConfiguration setStatus(final String status) { this.status = Level.toLevel(status, null); if (this.status == null) { this.error("Invalid status level specified: " + status + ". Defaulting to ERROR."); this.status = Level.ERROR; } return this; }
Example 18
Source File: StatusLoggerAdmin.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public void setLevel(final String level) { this.level = Level.toLevel(level, Level.ERROR); }
Example 19
Source File: LogSender.java From iaf with Apache License 2.0 | 4 votes |
@Override public void configure() throws ConfigurationException { super.configure(); log=LogUtil.getLogger(getLogCategory()); level=Level.toLevel(getLogLevel()); }
Example 20
Source File: LogHelper.java From okapi with Apache License 2.0 | 4 votes |
public static void setRootLogLevel(String name) { Level l = Level.toLevel(name); setRootLogLevel(l); }