Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

\n not putting text on a new line in php error_log function

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.
like image 393
Brady Latsha Avatar asked Sep 28 '13 05:09

Brady Latsha


People also ask

Where does Error_log write to?

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.

Where do PHP errors go?

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.

How do I log messages in PHP?

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 .

How do I create a PHP 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.


1 Answers

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);

?>
like image 121
Md. Sahadat Hossain Avatar answered Sep 29 '22 07:09

Md. Sahadat Hossain