Java Code Examples for org.apache.logging.log4j.core.appender.ConsoleAppender#Target

The following examples show how to use org.apache.logging.log4j.core.appender.ConsoleAppender#Target . 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: ConsoleAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private <T extends Log4j1Configuration> Appender createAppender(String name, Layout layout, Filter filter,
        String level, String target, T configuration) {
    org.apache.logging.log4j.core.Layout<?> consoleLayout = null;

    if (layout instanceof LayoutWrapper) {
        consoleLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        consoleLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter consoleFilter = buildFilters(level, filter);
    ConsoleAppender.Target consoleTarget = SYSTEM_ERR.equals(target)
            ? ConsoleAppender.Target.SYSTEM_ERR : ConsoleAppender.Target.SYSTEM_OUT;
    return new AppenderWrapper(ConsoleAppender.newBuilder()
            .setName(name)
            .setTarget(consoleTarget)
            .setLayout(consoleLayout)
            .setFilter(consoleFilter)
            .setConfiguration(configuration)
            .build());
}
 
Example 2
Source File: Log4j1ConfigurationParser.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private void buildConsoleAppender(final String appenderName) {
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, ConsoleAppender.PLUGIN_NAME);
    final String targetValue = getLog4jAppenderValue(appenderName, "Target", "System.out");
    if (targetValue != null) {
        final ConsoleAppender.Target target;
        switch (targetValue) {
        case "System.out":
            target = ConsoleAppender.Target.SYSTEM_OUT;
            break;
        case "System.err":
            target = ConsoleAppender.Target.SYSTEM_ERR;
            break;
        default:
            reportWarning("Unknown value for console Target: " + targetValue);
            target = null;
        }
        if (target != null) {
            appenderBuilder.addAttribute("target", target);
        }
    }
    buildAttribute(appenderName, appenderBuilder, "Follow", "follow");
    if (FALSE.equalsIgnoreCase(getLog4jAppenderValue(appenderName, "ImmediateFlush"))) {
        reportWarning("ImmediateFlush=false is not supported on Console appender");
    }
    buildAppenderLayout(appenderName, appenderBuilder);
    builder.add(appenderBuilder);
}
 
Example 3
Source File: Log4j1ConfigurationParser.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private void buildConsoleAppender(final String appenderName) {
    final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, ConsoleAppender.PLUGIN_NAME);
    final String targetValue = getLog4jAppenderValue(appenderName, "Target", "System.out");
    if (targetValue != null) {
        final ConsoleAppender.Target target;
        switch (targetValue) {
        case "System.out":
            target = ConsoleAppender.Target.SYSTEM_OUT;
            break;
        case "System.err":
            target = ConsoleAppender.Target.SYSTEM_ERR;
            break;
        default:
            reportWarning("Unknown value for console Target: " + targetValue);
            target = null;
        }
        if (target != null) {
            appenderBuilder.addAttribute("target", target);
        }
    }
    buildAttribute(appenderName, appenderBuilder, "Follow", "follow");
    if (FALSE.equalsIgnoreCase(getLog4jAppenderValue(appenderName, "ImmediateFlush"))) {
        reportWarning("ImmediateFlush=false is not supported on Console appender");
    }
    buildAppenderLayout(appenderName, appenderBuilder);
    builder.add(appenderBuilder);
}
 
Example 4
Source File: ConsoleAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Override
public Appender parseAppender(Element appenderElement, XmlConfigurationFactory factory) {
    String name = appenderElement.getAttribute(XmlConfigurationFactory.NAME_ATTR);
    Holder<String> target = new Holder<>(SYSTEM_OUT);
    Holder<Layout> layout = new Holder<>();
    Holder<Filter> filter = new Holder<>();
    forEachElement(appenderElement.getChildNodes(), (currentElement) -> {
        switch (currentElement.getTagName()) {
            case LAYOUT_TAG:
                layout.set(factory.parseLayout(currentElement));
                break;
            case FILTER_TAG:
                filter.set(factory.parseFilters(currentElement));
                break;
            case PARAM_TAG: {
                if (currentElement.getAttribute(NAME_ATTR).equalsIgnoreCase(TARGET)) {
                    String value = currentElement.getAttribute(VALUE_ATTR);
                    if (value == null) {
                        LOGGER.warn("No value supplied for target parameter. Defaulting to System.out.");
                    } else {
                        switch (value) {
                            case SYSTEM_OUT:
                                target.set(SYSTEM_OUT);
                                break;
                            case SYSTEM_ERR:
                                target.set(SYSTEM_ERR);
                                break;
                            default:
                                LOGGER.warn("Invalid value \"{}\" for target parameter. Using default of System.out",
                                        value);
                        }
                    }
                }
                break;
            }
        }
    });
    org.apache.logging.log4j.core.Layout<?> consoleLayout = null;
    org.apache.logging.log4j.core.Filter consoleFilter = null;

    if (layout.get() instanceof LayoutWrapper) {
        consoleLayout = ((LayoutWrapper) layout.get()).getLayout();
    } else if (layout.get() != null) {
        consoleLayout = new LayoutAdapter(layout.get());
    }
    if (filter.get() != null) {
        if (filter.get() instanceof FilterWrapper) {
            consoleFilter = ((FilterWrapper) filter.get()).getFilter();
        } else {
            consoleFilter = new FilterAdapter(filter.get());
        }
    }
    ConsoleAppender.Target consoleTarget = SYSTEM_ERR.equals(target.get())
            ? ConsoleAppender.Target.SYSTEM_ERR : ConsoleAppender.Target.SYSTEM_OUT;
    return new AppenderWrapper(ConsoleAppender.newBuilder()
            .setName(name)
            .setTarget(consoleTarget)
            .setLayout(consoleLayout)
            .setFilter(consoleFilter)
            .setConfiguration(factory.getConfiguration())
            .build());
}