title: How to instantiate loggers inside static methods in Log4j (For a large project)?
body: <p>I know the question title is a bit raw, the more I tried to make it clear in a single statement the less I was successful.
  Anyways, in a web application project I need to log every action (and the errors which occur inside them) with Log4j, there are hundreds of classes in the project and I want to avoid having a Logger object for each class. The level needed for logging is ERROR.
  So, I've thought of a custom class containing a static method which handles the Logger object's "error()" method. As shown below:</p>
  
  <pre><code>public class LoggerUtil {
  
      public static void error(String message, Object classObject) {
          String className = classObject.getClass().getName();
          Logger logger = LogManager.getLogger(className);
          logger.error(message);
      }
  }
  </code></pre>
  
  <p>So that whenever "LoggerUtil.error(message, this.getClass().getName())" is called anywhere in the project, we are able to log something by current class' related logger.
  Problem is that this doesn't seem to work, I guess it is not possible to instantiate a logger related to a specific class in another class.
  When our LoggerUtil.error() is called in one class the ERROR log that is given shows an unrelated class as it's source (java.lang.String). I wonder if there's a way to make this idea work?</p>
  
  <p>[UPDATE]: Problem solved. There was a problem in design, which was fixed in this way:</p>
  
  <pre><code>public class LoggerUtil {
  
      public static void error(String message, String className) {
          Logger logger = LogManager.getLogger(className);
          logger.error(message);
      }
  }
  </code></pre>
  
  <p>The second argument was changed into String so the class name is passed to the method directly. The logger works fine now. </p>