Java Code Examples for org.apache.logging.log4j.core.config.LoggerConfig#getName()

The following examples show how to use org.apache.logging.log4j.core.config.LoggerConfig#getName() . 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: Log4j2Helper.java    From arthas with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> doGetLoggerInfo(LoggerConfig loggerConfig) {
    Map<String, Object> info = new HashMap<String, Object>();

    String name = loggerConfig.getName();
    if (name == null || name.trim().isEmpty()) {
        name = LoggerConfig.ROOT;
    }

    info.put(LoggerHelper.name, name);
    info.put(LoggerHelper.clazz, loggerConfig.getClass());
    CodeSource codeSource = loggerConfig.getClass().getProtectionDomain().getCodeSource();
    if (codeSource != null) {
        info.put(LoggerHelper.codeSource, codeSource.getLocation());
    }
    Object config = getConfigField(loggerConfig);
    if (config != null) {
        info.put(LoggerHelper.config, config);
    }

    info.put(LoggerHelper.additivity, loggerConfig.isAdditive());

    Level level = loggerConfig.getLevel();
    if (level != null) {
        info.put(LoggerHelper.level, level.toString());
    }

    List<Map<String, Object>> result = doGetLoggerAppenders(loggerConfig);
    info.put(LoggerHelper.appenders, result);
    return info;
}
 
Example 2
Source File: XmlConfiguration.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Used internally to parse a level  element.
 */
private void parseLevel(Element element, LoggerConfig logger, boolean isRoot) {
    String catName = logger.getName();
    if (isRoot) {
        catName = "root";
    }

    String priStr = subst(element.getAttribute(VALUE_ATTR));
    LOGGER.debug("Level value for {} is [{}}].", catName, priStr);

    if (INHERITED.equalsIgnoreCase(priStr) || NULL.equalsIgnoreCase(priStr)) {
        if (isRoot) {
            LOGGER.error("Root level cannot be inherited. Ignoring directive.");
        } else {
            logger.setLevel(null);
        }
    } else {
        String className = subst(element.getAttribute(CLASS_ATTR));
        if (EMPTY_STR.equals(className)) {
            logger.setLevel(OptionConverter.convertLevel(priStr, org.apache.logging.log4j.Level.DEBUG));
        } else {
            LOGGER.debug("Desired Level sub-class: [{}]", className);
            try {
                Class<?> clazz = LoaderUtil.loadClass(className);
                Method toLevelMethod = clazz.getMethod("toLevel", ONE_STRING_PARAM);
                Level pri = (Level) toLevelMethod.invoke(null, new Object[]{priStr});
                logger.setLevel(OptionConverter.convertLevel(pri));
            } catch (Exception oops) {
                if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
                    Thread.currentThread().interrupt();
                }
                LOGGER.error("Could not create level [" + priStr +
                        "]. Reported error follows.", oops);
                return;
            }
        }
    }
    LOGGER.debug("{} level set to {}", catName,  logger.getLevel());
}
 
Example 3
Source File: XmlConfigurationFactory.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Used internally to parse a level  element.
 */
private void parseLevel(Element element, LoggerConfig logger, boolean isRoot) {
    String catName = logger.getName();
    if (isRoot) {
        catName = "root";
    }

    String priStr = subst(element.getAttribute(VALUE_ATTR));
    LOGGER.debug("Level value for {} is [{}}].", catName, priStr);

    if (INHERITED.equalsIgnoreCase(priStr) || NULL.equalsIgnoreCase(priStr)) {
        if (isRoot) {
            LOGGER.error("Root level cannot be inherited. Ignoring directive.");
        } else {
            logger.setLevel(null);
        }
    } else {
        String className = subst(element.getAttribute(CLASS_ATTR));
        if (EMPTY_STR.equals(className)) {
            logger.setLevel(convertLevel(OptionConverter.toLevel(priStr, Level.DEBUG)));
        } else {
            LOGGER.debug("Desired Level sub-class: [{}]", className);
            try {
                Class<?> clazz = LoaderUtil.loadClass(className);
                Method toLevelMethod = clazz.getMethod("toLevel", ONE_STRING_PARAM);
                Level pri = (Level) toLevelMethod.invoke(null, new Object[]{priStr});
                logger.setLevel(convertLevel(pri));
            } catch (Exception oops) {
                if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
                    Thread.currentThread().interrupt();
                }
                LOGGER.error("Could not create level [" + priStr +
                        "]. Reported error follows.", oops);
                return;
            }
        }
    }
    LOGGER.debug("{} level set to {}", catName,  logger.getLevel());
}
 
Example 4
Source File: Logger.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * This method is only used for 1.x compatibility. Returns the parent of this Logger. If it doesn't already exist
 * return a temporary Logger.
 *
 * @return The parent Logger.
 */
public Logger getParent() {
    final LoggerConfig lc = privateConfig.loggerConfig.getName().equals(getName()) ? privateConfig.loggerConfig
            .getParent() : privateConfig.loggerConfig;
    if (lc == null) {
        return null;
    }
    final String lcName = lc.getName();
    final MessageFactory messageFactory = getMessageFactory();
    if (context.hasLogger(lcName, messageFactory)) {
        return context.getLogger(lcName, messageFactory);
    }
    return new Logger(context, lcName, messageFactory);
}