Solved

How to rotate php error logs

Posted on 2007-03-23
9
2,705 Views
Last Modified: 2008-03-04
Hi,

I am using Apache & PHP on Solaris.
The question is regarding PHP error logs.

In my php.ini file, the following flags are set as below.

log_error = On
log_errors_max_len = 1024.

If I set as above, am I going to get mutilple php_error.logs each of 1024 size or always I get only one php_error.log of 1024 size.

But for the above setting, my log size is grwoing beyond 1024 also.

My requirement here is that I should have similar functionality of  "rotatelogs" of httpd for php_error.logs.
That is, once php_error log exceeds 1024, the new php_error log should be created and should also have the old php_error.log

Similar functionality of Piped logging using rotatelogs of httpd.

Thanks  
0
Comment
Question by:srini_kandimalla
  • 5
  • 4
9 Comments
 
LVL 61

Expert Comment

by:gheist
ID: 18784544
php uses webserver logging facilities, so rotatelogs is to be used
0
 

Author Comment

by:srini_kandimalla
ID: 18793888
In my php.ini file

I replaced the  error_log = /opt/xxx/zzz/apache/logs/php_error.log

with this below statement for rotating logs purpose, but it did not work.

ErrorLog "|/opt/xxx/zzz/apache/bin/rotatelogs /opt/xxx/zzz/apache/logs/php_error.log 5M"

My assumption is that TransferLog and ErrorLog work only in httpd.conf file, not using php.ini file.
When I revert back the changes, the php_error.logs are created.

Thanks
0
 
LVL 61

Expert Comment

by:gheist
ID: 18795931
Not sure what you mean by 5M
This value should be expressed in seconds.
0
 

Author Comment

by:srini_kandimalla
ID: 18795989
5M tells the size of log. The ErrorLog and TransferLog macros accepts it instead of seconds. Once log size exceed 5M size it will rotate to new log.
My basic questions here is that whether we can ise TranLog and ErrorLog macros of httpd.conf in php.ini or not?

Thanks
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 61

Expert Comment

by:gheist
ID: 18799266
rotatelogs parameter #2 is syntactically wrong. It will not work.
You will not find documentation to back your missassumptions.
0
 

Author Comment

by:srini_kandimalla
ID: 18801353
You can use both options, such as, Seconds as well as Size ( 5M).
This I am working on Solaris.
If you go to apache bin direcotry and give the rotate logs command, you can see both options.
But this documentation I too could not find on the net, I found it thru the command on Solaris.
It is as below. I tired this command for size and worked for me.

My basic question is that the TransferLog and ErrorLog directives whether they work by using php.ini or not instead of http.conf file. That is the php.ini supports these two commands or not. Answer to this is suffient for me, if it works any syntax changes for php.ini


The below is output of on Solaris

dev-sun-xyz#
dev-sun-xyz# pwd
/opt/xxx/zzz/apache/bin
dev-sun-xyz# ./rotatelogs
Usage: ./rotatelogs [-l] <logfile> <rotation time in seconds> [offset minutes from UTC] or <rotation size in megabytes>

Add this:

TransferLog "|./rotatelogs /some/where 86400"

or

TransferLog "|./rotatelogs /some/where 5M"

to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the
system time at which the log nominally starts (N.B. if using a rotation time,
the time will always be a multiple of the rotation time, so you can synchronize
cron scripts with it). At the end of each rotation time or when the file size
is reached a new log is started.
dev-sun-xyz#

Thanks
0
 
LVL 61

Accepted Solution

by:
gheist earned 500 total points
ID: 18802744
I've got apache 1.3 and assumed its features.

So - is your apache logs rotating?

error_log has multiple values:

    Name of the file where script errors should be logged. The file should be writable by the web server's user. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3) and on Windows NT it means the event log. The system logger is not supported on Windows 95. See also: syslog(). If this directive is not set, errors are sent to the SAPI error logger. For example, it is an error log in Apache or stderr in CLI.

basically comment out error_log line and read apache error log instead. php does no log rotations.
0
 

Author Comment

by:srini_kandimalla
ID: 18803455
Yes, my apache logs are rotating with Size (5M) option.

If you look at my orginal question at the top, I metnioned that
log_error = On
log_errors_max_len = 1024

what does it mean of "log_errors_max_len = 1024" in while logging PHP errors.
Is it size of error log file or length of error string line length in error file of php ??

Thanks

0
 
LVL 61

Assisted Solution

by:gheist
gheist earned 500 total points
ID: 18813907
http://ee.php.net/manual/en/ini.php
http://ee.php.net/manual/en/ref.errorfunc.php#ini.log-errors-max-len

log_error prevents server from presenting errors in webpages.
_max_len is size of logged error /think of long SQL statement/
error_log is used to avoid default logging to apache error log

I am not english, so please consult reference manual firsthand.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now