I'm trying to get my errors in my error.log file to be on separate lines, but \n does not seem to be doing that. I feel like i'm missing something easy, but it's all on the same line so if i have a bunch of errors in there it will be almost impossible to find them.
<?php
$msg_one = "Error message 1.\n ";
$msg_two = "Error message 2.\n ";
$log_file = "C:\\inetpub\\wwwroot\\logging\\errors.log";
error_log($msg_one, 3, $log_file);
error_log($msg_two, 3, $log_file);
?>
and the output in the log file looks like this:
Error message 1. Error message 2.
The location of the error log file itself can be set manually in the php. ini file. On a Windows server, in IIS, it may be something like "'error_log = C:\log_files\php_errors. log'" in Linux it may be a value of "'/var/log/php_errors.
By default, whenever an error or exception is thrown, PHP sends the error message directly to the user via STDOUT. In a command-line environment, this means that errors are rendered in the terminal. In a web environment, errors and exceptions get displayed directly in the browser.
Log messages can be generated manually by calling error_log() or automatically when notices, warnings, or errors come up during execution. By default, the error log in PHP is disabled. You can enable the error log in one of two ways: by editing php. ini or by using ini_set .
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.
Use "\r\n"
instead of "\n"
<?php
$msg_one = "Error message 1.\r\n ";
$msg_two = "Error message 2.\r\n ";
$log_file = "C:\\inetpub\\wwwroot\\logging\\errors.log";
error_log($msg_one, 3, $log_file);
error_log($msg_two, 3, $log_file);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With