title: Using log4j on centos 7 to log to rsyslog
body: <p>Currently I am trying to write a wrapper class (Log.java) to abstract away the logging to syslog. I am running on Ubuntu 18 and have tested my Log class by running it through Intellij. I installed log4j from (<a href="https://logging.apache.org/log4j/2.0/download.html" rel="nofollow noreferrer">https://logging.apache.org/log4j/2.0/download.html</a>: apache-log4j-2.11.1-bin.tar.gz )<br>
  Here are the classes and the log4j.xml file that I have:</p>
  
  <p>log4j.xml:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration status="info" name="Main" packages=""&gt;
      &lt;Appenders&gt;
          &lt;Syslog name="test"  host="localhost" port="514"
                  protocol="TCP" appName="Main"
                  facility="LOCAL3" newLine="true"
                  /&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Logger name="Log" level="info"&gt;
              &lt;AppenderRef ref="test"/&gt;
          &lt;/Logger&gt;
          &lt;Root level="info"&gt;
              &lt;AppenderRef ref="test"/&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>Log.java:</p>
  
  <pre><code>import org.apache.log4j.*;
  
  public class Log {
  
      private String _ident;
      private static final Logger logger = Logger.getLogger("Log");
  
      public Log(String ident) {
          _ident = ident;
      }
  
      public void info(String message) {
          logger.info("[INFO]" + "["+ _ident+ "] " +message);
      }
  
      public void debug(String message) {
          logger.debug("[DEBUG]" + "["+ _ident+ "] " +message);
      }
  
      public void warn(String message) {
          logger.warn("[WARNING]" + "["+ _ident+ "] " +message);
      }
  
      public void error(String message) {
          logger.error("[ERROR]" + "["+ _ident+ "] " +message);
      }
  
  }
  </code></pre>
  
  <p>Main.java:</p>
  
  <pre><code>public class Main {
  
      public static void main(String args[]) {
          Log log = new Log("Test");
          log.info("this is info");
          log.error("This is error");
          log.warn("This is warn");
          log.debug("This is debug");
      }
  
  
  }
  </code></pre>
  
  <p>However, I need to be able to use these classes on my centos 7 virtual machine without the use of an IDE. On Centos 7 I have installed the yum package: log4j and thus the jar file is located at /usr/share/java/log4j.jar</p>
  
  <p>I have attempted to link Log.java, Main.java and log4j.jar together using javac, however, each time I try to run java Main, I get an error stating that org.apache.log4j.logger can't be found. </p>
  
  <p>I also have attempted creating a jar from these files, yet I get the same error.</p>
  
  <p>How can I create a bash script to link these files together, resolve all dependencies, and produce an executable that I can run on my virtual machine? Keep in mind, that the logger needs to know the location of the xml file which I've only been able to achieve by placing the path in the vm options in Intellij.</p>
  
  <p>@Ice: So I created a bash script that:</p>
  
  <pre><code>#!/bin/bash
  LOG4j2_DIR="/usr/share/java/"
  javac -cp $LOG4J2_DIR/log4j.jar Log.java
  javac Main.java
  java -Dlog4j.configurationFile="log4j.xml" -cp .:$LOG4J2_DIR/log4j.jar 
  Main
  </code></pre>
  
  <p>And I got the following error:</p>
  
  <pre><code>log4j:WARN Continuable parsing error 2 and column 54
  log4j:WARN Document root element "Configuration", must match DOCTYPE root "null".
  log4j:WARN Continuable parsing error 2 and column 54
  log4j:WARN Document is invalid: no grammar found.
  log4j:ERROR DOM element is - not a &lt;log4j:configuration&gt; element.
  log4j:WARN No appenders could be found for logger (Log).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  </code></pre>