你好,游客 登录 注册 搜索
背景:
阅读新闻

nginx+fpm记录php的error log

[日期:2013-01-10] 来源:Linux社区  作者:zinss [字体:大 中 小]

pool.d目录下配置文件(例如:www.conf)

(1)保证配置文件中一个参数的开启,参数定义看英文注释很清楚:

; Redirect worker stdout and stderr into main error log. If not set, stdout and
; stderr will be redirected to /dev/null according to FastCGI specs.
; Note: on highloaded environement, this can cause some delay in the page
; process time (several ms).
; Default Value: no
catch_workers_output = yes

(2)同时可以开启access_log和slow_log

<SPAN style="COLOR: #ff0000">access.log = /var/log/fpm/php5-fpm.access.log</SPAN>

; The access log format.
; The following syntax is allowed
;  %%: the '%' character
;  %C: %CPU used by the request
;      it can accept the following format:
;      - %{user}C for user CPU only
;      - %{system}C for system CPU only
;      - %{total}C  for user + system CPU (default)
;  %d: time taken to serve the request
;      it can accept the following format:
;      - %{seconds}d (default)
;      - %{miliseconds}d
;      - %{mili}d
;      - %{microseconds}d
;      - %{micro}d
;  %e: an environment variable (same as $_ENV or $_SERVER)
;      it must be associated with embraces to specify the name of the env
;      variable. Some exemples:
;      - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
;      - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
;  %f: script filename
;  %l: content-length of the request (for POST request only)
;  %m: request method
;  %M: peak of memory allocated by PHP
;      it can accept the following format:
;      - %{bytes}M (default)
;      - %{kilobytes}M
;      - %{kilo}M
;      - %{megabytes}M
;      - %{mega}M
;  %n: pool name
;  %o: ouput header
;      it must be associated with embraces to specify the name of the header:
;      - %{Content-Type}o
;      - %{X-Powered-By}o
;      - %{Transfert-Encoding}o
;      - ....
;  %p: PID of the child that serviced the request
;  %P: PID of the parent of the child that serviced the request
;  %q: the query string
;  %Q: the '?' character if query string exists
;  %r: the request URI (without the query string, see %q and %Q)
;  %R: remote IP address
;  %s: status (response code)
;  %t: server time the request was received
;      it can accept a strftime(3) format:
;      %d/%b/%Y:%H:%M:%S %z (default)
;  %T: time the log has been written (the request has finished)
;      it can accept a strftime(3) format:
;      %d/%b/%Y:%H:%M:%S %z (default)
;  %u: remote user
;
; Default: "%R - %u %t \"%m %r\" %s"
;access.format = %R - %u %t "%m %r%Q%q" %s %f %{mili}d %{kilo}M %C%%
 
; The log file for slow requests
; Default Value: not set
; Note: slowlog is mandatory if request_slowlog_timeout is set
slowlog = /var/log/fpm/php5-fpm.log.slow
 
; The timeout for serving a single request after which a PHP backtrace will be
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
request_slowlog_timeout = 3

fpm日志按天分割脚本

#!/bin/bash -

#1.fpm日志存放路径
php5_fpm_path="/var/log/php5-fpm"

path_array=($php5_fpm_path)


#2.日志标识前缀数组
icontact_fpm_sign="test"
test_fpm_sign="php5-fpm"

prefix_array=($icontact_fpm_sign $test_fpm_sign)


#3.日志success or slow 标识后缀数组
bool_array=("access" "slow" "error")


#4.nginx日志切割备份后缀
postfix=`date +%Y%m%d`".log"


#5.备份当前的日志文件,重命名改为日期后缀
for path in ${path_array[*]}
do
 for prefix in ${prefix_array[*]}
 do
  for bool in ${bool_array[*]}
  do
   file=$path/$prefix.$bool.log
   backfile=$path/$prefix.$bool.$postfix
   if [ -e $file ]
   then
    mv $file  $backfile
   fi
  done
 done
done


#6.查找nginx进程号,让其产生新的日志文件
fpm_pid=`ps -aux |grep -E 'php-fpm: master process'|grep -v 'grep'|awk '{print $2}'`
#USR1:Reopen log files,刷新nginx日志文件
kill -USR1 $fpm_pid

后记

大家有改进的意见欢迎跟贴留言!

linux
相关资讯       nginx+fpm 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款