为什么log4jxml配置有错误?

时间:2017-12-27 12:49:34

标签: java bash debugging logging log4j

我有启动脚本的问题,我有自己的log4j.xml文件。我脚本的片段如下:

export JAVA_HOME=/home/iso/JDK1.6u45/jdk1.6.0_45
MNCHECKER_HOME=/home/MNChecker
JAR="$MNCHECKER_HOME/MNChecker.jar"
LOG="/var/log/MNChecker.log"
LOCK="/var/lock/subsys/MNChecker"
CHECK_SERVER=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
CHECK_PORT=3000
LISTEN_PORT=1410
LOG4j_FILE="/home/MNChecker/log4j.xml"

cd "$MNCHECKER_HOME"
nohup $JAVA_HOME/bin/java -Dlog4j.debug -Dlog4j.configuration="file:"$LOG4J_FILE"" -jar "$JAR" -server $CHECK_SERVER -port $CHECK_PORT -listen -listen-port $LISTEN_PORT >> "$LOG" 2>&1 &

我的log4j.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'>
    <appender name="ConsoleOutput"  class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c %m%n"/>
        </layout>
    </appender>

    <!--Set the default log level and where the default goes-->
    <!--Possible levels are DEBUG, INFO, WARN, ERROR, FATAL-->
    <root>
        <level value="info"/>
        <appender-ref ref="ConsoleOutput"/>
    </root>

</log4j:configuration>

当我尝试运行我的脚本时,我的/var/logNChecker.log中有错误日志:

log4j: Using URL [file:] for automatic log4j configuration.
log4j: Reading configuration from URL file:
log4j:ERROR Could not read configuration file from URL [file:].
java.io.FileNotFoundException:  (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:120)
        at java.io.FileInputStream.<init>(FileInputStream.java:79)
        at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
        at java.net.URL.openStream(URL.java:1010)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:424)
        at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:460)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:113)
        at org.apache.log4j.Logger.getLogger(Logger.java:85)
        at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229)
        at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
        at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
        at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
        at com.lppsa.MNodeChecker.App.<init>(App.java:13)
        at com.lppsa.MNodeChecker.App.main(App.java:71)
log4j:ERROR Ignoring configuration file [file:].
log4j:WARN No appenders could be found for logger (com.lppsa.MNodeChecker.App).
log4j:WARN Please initialize the log4j system properly.

一切都很好,我用“nohup”行更改脚本到下面:

nohup $JAVA_HOME/bin/java -jar "$JAR" -server $CHECK_SERVER -port $CHECK_PORT -listen -listen-port $LISTEN_PORT >> "$LOG" 2>&1 &

我几乎可以肯定,我错过了什么或写错了什么,但是什么?

0 个答案:

没有答案