Appender.appender is null based on MDCSiftingAppender in log4j.properties (log4j 1)
<p>I was given a working java project. It logs with log4j (not log4j 2).</p>

<p>I want to add a sift appender without adding log4j 2 or any other dependency that will ruin existing log4 dependency.</p>

<p>I have this <code>log4j.properties</code> file</p>

<pre><code># Root logger
log4j.rootLogger=INFO, sift
log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
log4j.configDebug = true

# Sift appender
log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
log4j.appender.sift.key=session_id
log4j.appender.sift.default=no_session_id
log4j.appender.sift.appender=org.apache.log4j.FileAppender
log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.sift.appender.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %m%n
log4j.appender.sift.appender.file=/var/log/rr/$\\{session_id\\}.log
log4j.appender.sift.appender.append=true
</code></pre>

<p>and this is my main:</p>

<pre><code>public class SiftExampleLog4j {

    static org.apache.log4j.Logger logger = Logger.getLogger(SiftExampleLog4j.class);

    public void log() {
        BasicConfigurator.configure();
        org.apache.log4j.MDC.put("session_id","MyGooApp");

        logger.error("example1");

        org.apache.log4j.MDC.put("session_id","MyFooApp");

        logger.error("example2");
    }

    public static void main (String[] args){
    new SiftExampleLog4j().log();
    }
}
</code></pre>

<p>But I get NPE when i try to log</p>

<p><code>logger.error("example1");</code></p>

<p>What am i missing how to make the "apender" member not null?</p>

<p>here is the stack trace for the short <code>main</code>:</p>

<pre><code>Exception in thread "main" java.lang.NullPointerException
    at org.apache.log4j.sift.MDCSiftingAppender.getAppender(MDCSiftingAppender.java:109)
    at org.apache.log4j.sift.MDCSiftingAppender.append(MDCSiftingAppender.java:79)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.error(Category.java:305)
    at com.waze.rr_logger.SiftExampleLog4j.log(SiftExampleLog4j.java:14)
    at com.waze.rr_logger.SiftExampleLog4j.main(SiftExampleLog4j.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
</code></pre>

<p>But I get NPE when i try to log</p>

<p>What am i missing?</p>

<p><a href="https://i.stack.imgur.com/TedXq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TedXq.png" alt="enter image description here"></a></p>