首頁  >  文章  >  後端開發  >  linux - log4php在使用過程中提示:設定檔無法載入

linux - log4php在使用過程中提示:設定檔無法載入

WBOY
WBOY原創
2016-08-18 09:16:021246瀏覽

下面是一行nginx錯誤日誌,為了方便查看,我給大家做了分隔:

<code>016/08/14 14:34:49 [error] 2819#0: *59 FastCGI sent in stderr: 
"PHP message: PHP Warning:  log4php: Configuration failed. 
Error loading configuration file: failed to load external entity 
"/alidata1/****/logger_conf.xml" Using default configuration. 
in /alidata1/****/configurators/LoggerConfiguratorDefault.php on line 475" 
while reading response header from upstream, client: 101.226.103.72, server: ****, 
request: "POST /share/notify HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", 
host: "*****"
</code>

情況介紹

1.使用Logger::getRootLogger調用,在入口處,引用Log4php,同時Logger.configure('*')載入。

2.之前沒有出現這個問題,我懷疑是因為我調整過一次nginx的權限出現的問題,之前nginx的用戶是apache,現在我修改成了nobody。 (但這種懷疑沒有依據,我已經重啟無數次nginx了)

3.這種情況時好時壞,有的時候我可以正常使用Logger來列印輸出,但大多數的時候會報上面的錯誤。 (這從側面也說明設定檔權限沒有問題)。我重啟php-fpm有時候會好,但這裡面有多少關係,感覺沒有任何關聯。 php-fpm的work流程也是nobody權限

我已經確認可以排除的情況

<code>1. 文件确实存在,文件的权限已经是777.(甚至文件路径中权限我都修改成了777)
</code>

有誰遇到了同樣的問題,我現在在入口處調用了Logger.configure()來指定調用文件,為啥會出現上面的錯誤,大家幫忙看一看

linux - log4php在使用過程中提示:設定檔無法載入

回覆內容:

下面是一行nginx錯誤日誌,為了方便查看,我給大家做了分隔:

<code>016/08/14 14:34:49 [error] 2819#0: *59 FastCGI sent in stderr: 
"PHP message: PHP Warning:  log4php: Configuration failed. 
Error loading configuration file: failed to load external entity 
"/alidata1/****/logger_conf.xml" Using default configuration. 
in /alidata1/****/configurators/LoggerConfiguratorDefault.php on line 475" 
while reading response header from upstream, client: 101.226.103.72, server: ****, 
request: "POST /share/notify HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", 
host: "*****"
</code>

情況介紹

1.使用Logger::getRootLogger調用,在入口處,引用Log4php,同時Logger.configure('*')載入。

2.之前沒有出現這個問題,我懷疑是因為我調整過一次nginx的權限出現的問題,之前nginx的用戶是apache,現在我修改成了nobody。 (但這種懷疑沒有依據,我已經重啟無數次nginx了)

3.這種情況時好時壞,有的時候我可以正常使用Logger來列印輸出,但大多數的時候會報上面的錯誤。 (這從側面也說明設定檔權限沒有問題)。我重啟php-fpm有時候會好,但這裡面有多少關係,感覺沒有任何關聯。 php-fpm的work流程也是nobody權限

我已經確認可以排除的情況

<code>1. 文件确实存在,文件的权限已经是777.(甚至文件路径中权限我都修改成了777)
</code>

有誰遇到了同樣的問題,我現在在入口處調用了Logger.configure()來指定調用文件,為啥會出現上面的錯誤,大家幫忙看一看

linux - log4php在使用過程中提示:設定檔無法載入

問題的解決方法
感謝這篇文章,請點擊查看

簡短介紹一下問題的原因:引入的類別中包含了這個函數:libxml_disable_entity_loader

我的log4php.properties

<code>log4php.rootLogger=INFO, stderr, stdout, file
log4php.appender.stdout=LoggerAppenderConsole
log4php.appender.stdout.layout=LoggerLayoutPattern
log4php.appender.stdout.layout.ConversionPattern=%date{ISO8601} [%p] %m%n
log4php.appender.stdout.threshold=INFO

log4php.appender.stderr=LoggerAppenderConsole
log4php.appender.stderr.layout=LoggerLayoutPattern
log4php.appender.stderr.target=stderr
log4php.appender.stderr.threshold=ERROR
log4php.appender.stderr.layout.ConversionPattern=%date{ISO8601} [%p] [%l] %m%n

log4php.appender.file=LoggerAppenderDailyFile
log4php.appender.file.layout=LoggerLayoutPattern
log4php.appender.file.threshold=ERROR
log4php.appender.file.file=commands/logs/%s-error.log
log4php.appender.file.layout.ConversionPattern=%date{ISO8601} [%p] [%l] %m%n</code>

PHP初始化

<code>\Logger::configure(__DIR__ . '/log4php.properties');
$logger = \Logger::getLogger('default');
$logger->info('xxx');</code>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn