Java Code Examples for org.apache.logging.log4j.core.appender.rewrite.RewriteAppender#createAppender()

The following examples show how to use org.apache.logging.log4j.core.appender.rewrite.RewriteAppender#createAppender() . 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: DeobfuscatingRewritePolicy.java    From VanillaFix with MIT License 6 votes vote down vote up
/** Modifies the log4j config to add the policy **/
public static void install() {
    Logger rootLogger = (Logger) LogManager.getRootLogger();
    LoggerConfig loggerConfig = rootLogger.get();

    // Remove appender refs from config
    List<AppenderRef> appenderRefs = new ArrayList<>(loggerConfig.getAppenderRefs());
    for (AppenderRef appenderRef : appenderRefs) {
        loggerConfig.removeAppender(appenderRef.getRef());
    }

    // Create the RewriteAppender, which wraps the appenders
    RewriteAppender rewriteAppender = RewriteAppender.createAppender(
            "VanillaFixDeobfuscatingAppender",
            "true",
            appenderRefs.toArray(new AppenderRef[0]),
            rootLogger.getContext().getConfiguration(),
            new DeobfuscatingRewritePolicy(),
            null
    );
    rewriteAppender.start();

    // Add the new appender
    loggerConfig.addAppender(rewriteAppender, null, null);
}
 
Example 2
Source File: RewriteAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private <T extends Log4j1Configuration> Appender createAppender(String name, String level,
        String[] appenderRefs, RewritePolicy policy, Filter filter, T configuration) {
    org.apache.logging.log4j.Level logLevel = OptionConverter.convertLevel(level,
            org.apache.logging.log4j.Level.TRACE);
    AppenderRef[] refs = new AppenderRef[appenderRefs.length];
    int index = 0;
    for (String appenderRef : appenderRefs) {
        refs[index++] = AppenderRef.createAppenderRef(appenderRef, logLevel, null);
    }
    org.apache.logging.log4j.core.Filter rewriteFilter = buildFilters(level, filter);
    org.apache.logging.log4j.core.appender.rewrite.RewritePolicy rewritePolicy;
    if (policy instanceof RewritePolicyWrapper) {
        rewritePolicy = ((RewritePolicyWrapper) policy).getPolicy();
    } else {
        rewritePolicy = new RewritePolicyAdapter(policy);
    }
    return new AppenderWrapper(RewriteAppender.createAppender(name, true, refs, configuration,
            rewritePolicy, rewriteFilter));
}
 
Example 3
Source File: DefaultRewriteAuditAppender.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final String domain) {
    super.init(domain);

    rewriteAppender = RewriteAppender.createAppender(
            getTargetAppenderName() + "_rewrite",
            "true",
            new AppenderRef[] { AppenderRef.createAppenderRef(getTargetAppenderName(), Level.DEBUG, null) },
            ((LoggerContext) LogManager.getContext(false)).getConfiguration(), getRewritePolicy(), null);
}