Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set up error_log by folder?

My company has a large hosting, but it’s not managed by us, we don't see configuration files, but I want to reply this feature on our local test server.

I’m new in my company and want to start some debug of applications to fix some minors and majors issues to clients, but the amount of files is so big that single error_file is huge.. and there are many people working on this so each time I check log (like 30 secs to 1 min) has hundreds of added lines.

I don’t know if this is set up on Apache, through .htaccess files or in php.ini.

I am talking about PHP errors, but I don't know if this is set in PHP, Apache, or maybe using a third-party library.

I'm not talking about setting a specific folder error_log. I'm talking about if errors are logged in the scripts folder.

Example: I create a folder named test1. Inside it I make some buggy PHP script that throws some errors. When I run the script I can see an error_log file created in the folder. So it works on the fly.

I have tried to ask the hosting company support how they do this, but they haven’t answered me.


I don't know if maybe could be some kind of cPanel setting (BTW, the hosting support stuff doesn't understand this question either, but well.. usually level 1 of support can’t handle technical stuff).

like image 988
Camilo Lizarazo Avatar asked May 08 '12 13:05

Camilo Lizarazo


People also ask

Where does error_log go?

There are two possible values for error_log: a custom log file and the syslog. If the syslog is used, then all PHP errors will be sent directly to the default system log file—in Linux, this is typically /var/log/syslog.

How do I create an error log?

The ini_set(“log_errors”, TRUE) command can be added to the php script to enable error logging in php. The ini_set('error_log', $log_file) command can be added to the php script to set the error logging file. Further error_log($error_message) function call can be used to log error message to the given file.

What is error_log file?

The error_log() function sends an error message to a log, to a file, or to a mail account.


1 Answers

I found it.

You have to set a directive in the php.ini file as follows, string "error_log". On the right side is the file name you want for the log,

error_log = error_log

This will generate a PHP error log in the folder where script executed are,

I'll try to explain.

Script test.php in folder /www/site/lib:

include "./db_conn.php";

If file db_conn.php is not located in the same directory, this will fire a warning and error. Usually this will be lead to the servers/vhost log, but using this directive you will get an error_log file under the /www/site/lib directory.

Why was I looking or this? Well, as I wrote, I'm working on a huge application, with thousands of files many fires warnings, notices, etc. I'm not the only one in the project and the site error_log file was so huge it was hard to keep tracking debug evolution for one or just some files. Now I just have to track the log from directories where I'm working.

like image 184
Camilo Lizarazo Avatar answered Sep 22 '22 01:09

Camilo Lizarazo