Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: syslog - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Newt" width="11" height="7"/> <ネットワーク
Last updated: Sun, 25 Nov 2007

view this page in

syslog

(PHP 4, PHP 5)

syslog — システムログのメッセージを生成する

説明

bool syslog ( int $priority , string $message )

syslog() はシステムログが出力するログメッセージを生成します。

ユーザ定義のログハンドラの設定に関する情報については、Unix マニュアルの syslog.conf (5) を参照ください。 syslog の facility と option に関するより詳細な情報は、 Unix マシンの syslog (3) にあります。

パラメータ

priority

priority は、容易さ (facility) とレベル (level) の組み合わせです。以下の値が使用できます。
syslog() の優先順位 (降順)
定数 説明
LOG_EMERG システムは使用不可
LOG_ALERT アクションを直ちにおこす必要がある
LOG_CRIT 致命的な条件
LOG_ERR エラーを発生する条件
LOG_WARNING 警告を発生する条件
LOG_NOTICE 通常の動作だが、特徴的な条件
LOG_INFO 情報を与えるメッセージ
LOG_DEBUG デバッグ用のメッセージ

message

残りの引数は送信するメッセージです。ただし、文字 %m は、errno の値に対応するエラーメッセージ文字列 (strerror) に置換されます。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

Example#1 syslog() の使用例

<?php
define_syslog_variables
();
// syslogをオープンし、プロセスIDをインクルードし、標準エラー出力にも
// ログを出力します。そして、ユーザ定義のログ記録機構を使用します。
openlog("myScriptLog"LOG_PID LOG_PERRORLOG_LOCAL0);

// 何らかのコード

if (authorized_client()) {
    
// 何かをする
} else {
    
// クライアントは未認証!
    // ログを記録する
    
$access date("Y/m/d H:i:s");
    
syslog(LOG_WARNING"Unauthorized client: $access {$_SERVER['REMOTE_ADDR']} ({$_SERVER['HTTP_USER_AGENT']})");
}

closelog();
?>

注意

Windows NT では、syslog サービスはイベントログを使用してエミュレートされます。

注意: Windows 環境では、openlog()facility パラメータに LOG_LOCAL0 から LOG_LOCAL7 までを使用することはできません。



Newt" width="11" height="7"/> <ネットワーク
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
syslog
james dot ellis at gmail dot com
03-Dec-2007 01:26
If anyone is wondering why their log messages are appearing in multiple log files, here is one answer applying to *nix systems:

If your syslog.conf looks like this (assuming you use LOG_LOCAL0 for web app logging) :

local0.info    /var/log/web/info.log

This will collect *all* messages of LOG_INFO level and higher, i.e everything except debug messages

Try this instead to ensure that only messages of the named log level go into the relevant log file:

local0.=info    /var/log/web/info.log

Additionally, you may like to add this to ensure your messages don't end up in generic log files like "messages"  "all" "syslog" and "debug":

local0.none    /var/log/messages
local0.none    /var/log/debug
etc

saves disk space among other things - more at "man syslog.conf"
helly at php dot net
13-Apr-2007 09:49
If you are using syslog-ng and want errors send to syslog then use ini setting "error_log = syslog" and add something like the following to your syslog-ng.conf:

destination php { file("/var/log/php.log" owner(root) group(devel) perm(0620)); };
log { source(src); filter(f_php); destination(php); };
adam _at_ lockdownnetworks _dot_ com
11-Apr-2007 10:32
Be aware when using syslog() that if you set the timezone of environment to be something other than the standard, syslog() may log the time to the log(s) with the wrong time zone information. For example:

<?php

openlog
('mylog', LOG_PID | LOG_ODELAY,LOG_LOCAL4);

putenv('TZ=UTC');
syslog(LOG_INFO, 'UTC Log line');

putenv('TZ=US/Pacific');
syslog(LOG_INFO, 'US/Pacific Log line');

closelog();

?>

Viewing the /usr/log/messages log will display these two lines:

Apr 11 01:25:39 hostname mylog[1400]: UTC Log line
Apr 10 18:25:39 hostname mylog[1400]: US/Pacific Log line

Adam.
Torsten
23-Apr-2004 10:27
I had a problem trying to issue a syslog message with IIS 5.1 under Windows XP. The function call seemed to succeed, but the event viewer showed that no entry was made.
Finally I found out that the user account used for the webserver (IUSR_<Computername>) did not have enough permissions to issue syslog alerts. I changed this by adding this user to the Users group instead of only Guest.
daniele dot patoner at biblio dot unitn dot it
07-Nov-2003 04:00
This work for me, to redirect  logs to a separate syslog file

put this line in your /etc/syslog.conf :

local0.debug   /var/log/php.log

Then restart syslogd:

/etc/init.d/syslog restart

php example:

<?php
define_syslog_variables
();
openlog("TextLog", LOG_PID, LOG_LOCAL0);

$data = date("Y/m/d H:i:s");
syslog(LOG_DEBUG,"Messagge: $data");

closelog();
?>
gregj at pdxperts dot com
29-Jul-2003 09:05
The message string sent to the log file is limited to 500 characters.
monte at ispi dot net
04-Jul-2003 03:05
If you have php.ini setup to send PHP errors to syslog, they will all get dumped into /var/log/messages (at least it does with RedHat 9 by default). I wanted to figure out how to get PHP errors to go to their own syslog file.

After some trial and error, I figured out what facility and priority PHP uses, which is "user.notice". So, to get your PHP errors going to a separate syslog file, put this line in your /etc/syslog.conf :

user.notice   /var/log/php.log

Then restart syslogd:

/etc/init.d/syslog restart

Why PHP uses "user" as the facility I'm not sure, probably because it's the only one that works under Windows?

Monte
nospam \100 jraxis com (that's right!)
01-Apr-2002 01:32
This *does* actually goto the system log as configured in /etc/syslog.conf (such as /var/log/messages), it doesn't goto Apache's ErrorLog (such as /var/log/httpd/error_log). At least under my Debian Potato with Apache 1.3.23.

Use error_log() to be sure it gets into Apache's ErrorLog.
dpreece at paradise dot net dot nz
30-Jan-2002 09:08
To set up a custom log file via the syslog daemon (FreeBSD in this case)...

Add to /etc/syslog.conf a line that says all errors from the httpd process are to go to a file called (for example) /var/log/httpd-php.log

!httpd
*.*   {tab}   /var/log/httpd-php.log

Note the tab, being a tab character! Next create a blank file to be written to. I'm sure there are 1e+6 ways to do this, but I choose

# cat > httpd-php.log << EOF
? EOF

Finally find your syslog daemon and send it a sighup to inform it of the change:

# ps ax | grep syslogd
  133  ??  Ss     0:07.23 syslogd -s
# kill -1 133

Et voila! Php syslog calls will now arrive in /var/log/httpd-php.log
mavetju at chello dot nl
22-Jan-2001 11:11
With FreeBSD I can use: syslog(LOG_INFO,"test");

BSD/OS does not support this, I had to use the literal values for the priority (158: local3.info):
syslog(158,"test");
gherson at snet dot net
21-Dec-2000 06:09
Example of where to look for syslog's output:   /var/log/httpd/access_log
(on Red Hat Linux Secure Server v6.2).
rcgraves+php at brandeis dot edu
17-Feb-2000 05:51
For the-header-file-enabled:

man 3 syslog defines the priorities, but not the integer values. For that you'll need to read your system header file.

Let's suppose I want to log an informational message in the mail log (which happens to be true). The man page tells me I want LOG_MAIL|LOG_INFO. So I look in /usr/include/sys/syslog.h and find (this happens to be Linux, your system could be different):

#define LOG_INFO        6       /* informational */
#define LOG_MAIL        (2<<3)  /* mail system */

2<<3 means shift 3 bits left, which means multiply by 8. So I want 2*8 + 6 = 22. syslog(22,"this message will appear in the mail log"); And indeed it does.
bb at lb-data dot co dot at
08-Sep-1999 07:54
In Windows NT, use the following values of priority:
1 = error,
6 = info

Newt" width="11" height="7"/> <ネットワーク
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites