title: why can't I log method name and code line in log4j when I extend log4j
body: <p>I've extended log42 logger. </p>
  
  <p><strong>The idea:</strong>
  I should pass enum to log method, in order to choose appender in runtime.</p>
  
  <p><strong>My interface:</strong></p>
  
  <pre><code>public interface MyLoggerInterface {
      void info(String logMessage, MyLoggerAppenderEnum... appender);
      public static MyLoggerInterface getLogger(Class aClass, MyLoggerAppenderEnum... appender) {
          return MyLoggerInterfaceImpl.getLogger(aClass, appender);
      }
  }
  </code></pre>
  
  <p><strong>implementation:</strong></p>
  
  <pre><code>    public class MyLoggerInterfaceImpl extends Logger implements MyLoggerInterface {
      private static final String FQCN = MyLoggerInterfaceImpl.class.getName();
  
      protected MyLoggerInterfaceImpl(LoggerContext context, String name, MessageFactory messageFactory) {
          super(context, name, messageFactory);
      }
  
      public static MyLoggerInterface getLogger(Class aClass, MyLoggerAppenderEnum... appenders) {
          return getLogger(aClass.getName(), appenders);
      }
  
      private static MyLoggerInterface getLogger(String name, MyLoggerAppenderEnum... appenders) {
          return (MyLoggerInterfaceImpl) org.apache.logging.log4j.LogManager.getLogger(name);
      }
  
      @Override
      public void info(String logMessage, MyLoggerAppenderEnum... appenders) {
          this.log(FQCN, Level.INFO, null, new SimpleMessage(logMessage), null, appenders);
      }
  
      private void log(String fqcn, Level level, Marker marker, Message message, Throwable throwable, MyLoggerAppenderEnum... appenders) {
          Arrays.stream(appenders)
                  .map(appender -&gt; findAppenderByName(appender))
                  .collect(Collectors.toList())
                  .forEach(appender -&gt;
                          appender.append(
                                  new Log4jLogEvent(this.getName(), marker, fqcn, level, message, new ArrayList&lt;Property&gt;(), throwable)
                          )
                  );
      }
  
      private Appender findAppenderByName(MyLoggerAppenderEnum appenders) {
          return this.getAppenders().get(appenders.name());
      }
  }
  </code></pre>
  
  <p>But <strong>Note</strong> that  in log4j <strong>2.X</strong>  LoggerFactory is <strong>removed</strong> from 1.X version. So I implement additional classes, in order to avoid <strong>ClassCastException</strong> (Logger to MyLoggerInterfaceImpl) .   </p>
  
  <p>So. MyContext:</p>
  
  <pre><code>    public class MyLoggerContext extends LoggerContext {
      public MyLoggerContext(String name) {
          super(name);
      }
      @Override
      protected Logger newInstance(final LoggerContext ctx, final String name, final MessageFactory messageFactory) {
          return new MyLoggerInterfaceImpl(ctx, name, messageFactory);
      }
  }
  </code></pre>
  
  <p>Context Selector:</p>
  
  <pre><code>public class MyLoggerContextSelector implements ContextSelector {
  
      private final LoggerContext CONTEXT = new MyLoggerContext("MyLoggerContext");
      public LoggerContext getContext(String fqcn, ClassLoader loader, boolean currentContext) {
          return CONTEXT;
      }
      public LoggerContext getContext(String fqcn, ClassLoader loader, boolean currentContext, URI configLocation) {
          return CONTEXT;
      }
      public List&lt;LoggerContext&gt; getLoggerContexts() {
          return Arrays.asList(CONTEXT);
      }
      public void removeContext(LoggerContext context) {
      }
  }
  </code></pre>
  
  <p>Context Factory:</p>
  
  <pre><code>public class MyLoggerLog4jContextFactory extends Log4jContextFactory {
      public MyLoggerLog4jContextFactory() {
          super(new MyLoggerContextSelector(), new DefaultShutdownCallbackRegistry());
      }
  }
  </code></pre>
  
  <p>and manager:</p>
  
  <pre><code>public class MyLoggerManager {
      public static void initialize(String configURL) {
          try {
              System.setProperty("log4j2.loggerContextFactory", "ge.test.core.logging.MyLoggerLog4jContextFactory");
              System.setProperty("Log4jLogEventFactory", "org.apache.logging.log4j.core.impl.DefaultLogEventFactory");
              Configurator.initialize(null, configURL);
          } catch (Exception ex ) {
              System.err.println("Cannot initialize Log4J using configuration url:" + configURL);
          }
      }
  }
  </code></pre>
  
  <p><strong>Cool! Everything works fine!!!</strong> and usage:</p>
  
  <pre><code> MyLoggerManager.initialize("Log4j2.xml");
   MyLoggerInterface logger = MyLoggerInterface.getLogger(AppLauncher.class);
   logger.info("test", MyLoggerAppenderEnum.Console);
  </code></pre>
  
  <p><strong>BUT</strong> problem is that If I use extend custom logger, I can't log method name and line. Layout is correct! <strong>If I dont use</strong> extended custom logger, mehtod name and line is logged too! </p>
  
  
  
  <pre><code>&lt;Configuration status="WARN"&gt;
  &lt;Appenders&gt;
      &lt;Console name="Console" target="SYSTEM_OUT"&gt;
          &lt;PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} %method:%line - %msg%n"/&gt;
      &lt;/Console&gt;
      ...
  &lt;/Appenders&gt;
  &lt;Loggers&gt;
      ...
      &lt;Logger name="Console" level="trace" additivity="false"&gt;
          &lt;appender-ref ref="Console" level="trace"/&gt;
      &lt;/Logger&gt;
      ...
      &lt;Root level="error"&gt;
          ...
          &lt;AppenderRef ref="Console"/&gt;
      &lt;/Root&gt;
  &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p><strong>Question:</strong> 
  I want to log <strong>method name and line</strong> too. but it does not work <strong>after</strong> I extend my logger class (layout syntaxt is correct!) </p>
  
  <p>I found the extended logger example <a href="http://sureshgarrepalli.blogspot.com/2016/03/building-logging-wrapper-on-top-of.html" rel="nofollow noreferrer">here</a> </p>
  
  <p>and my code in here in <a href="https://gitlab.com/vakhoq/logger-testing" rel="nofollow noreferrer">gitlab</a></p>
  
  <p>I use <strong>log4j 2.9.1</strong>   </p>