Apache Error Log Newline
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers
Php Error Log Newline
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x apache velocity new line Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it error_log new line only takes a minute: Sign up newline in error_log in php up vote 13 down vote favorite 1 How to insert a newline while using error_log() in php I tried to use
and \n but those didn't work. php
Php Error Log Line Break
share|improve this question asked Jun 7 '10 at 6:26 Satish 4402719 4 I wouldn’t do that. I would expect that every line in the error log is one single entry. Spreading a message over two or more lines would break this. –Gumbo Jun 7 '10 at 6:40 add a comment| 5 Answers 5 active oldest votes up vote 25 down vote accepted Use double quotes when putting the error message: error_log("This is a two lined message. \nThis is line two.");
Php Syslog
should work. error_log('This is a one lined message. \nThis is the same line still.'); will not work: notice the single quotes. share|improve this answer answered Jun 7 '10 at 6:33 Konerak 27.1k66197 You haven't given the 2nd and 3rd parameter(the name of the error log file ) –Satish Jun 7 '10 at 6:40 4 So? The other parameters are optional. Maybe you should specify what you want to achieve, because AFAICT you've just been given the solution to your problem. –wimvds Jun 7 '10 at 9:26 @Satish, sorry for the late comment, but, if we do not put any second and third parameter, the log gets written to php's default error log file: 'php_errors.log' which is welcome. –Pupil Mar 13 '15 at 8:56 this not work in windows –Koks_rs Jan 5 at 14:12 @Koks_rs: try \r\n in MS Windows? –Konerak Jan 6 at 7:47 | show 1 more comment up vote 13 down vote PHP_EOL manage newlines on multiple platforms: error_log("Error message".PHP_EOL, 3, 'error.log'); share|improve this answer answered Apr 11 '14 at 13:28 Mladen Janjetovic 2,1602034 1 Nice one, works fine with PHP running on IIS. \10 didn't work but this one does. –Jordi May 25 at 9:03 add a comment| up vote 4 down vote As mentioned before, you can use either PHP_EOL or use double quotes in order to output a newline to your log file.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies php error_log of this site About Us Learn more about Stack Overflow the company
Php_eol
Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges php date Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a http://stackoverflow.com/questions/2987465/newline-in-error-log-in-php minute: Sign up PHP/Apache error.log doesn't execute new_line characters, why? up vote 2 down vote favorite 1 For example instead of getting the following post:Array ( "a" => "b", "c" => "d" ) I just get this: post:Array (\n "a" => "b",\n "c" => "d"\n) It's really uncomfortable to read this while debugging my code. So if you have any suggestion on http://stackoverflow.com/questions/8503958/php-apache-error-log-doesnt-execute-new-line-characters-why why this couldn't work alright, tell me. I am running it in a Windows7 Putty connected to an Ubuntu virtual server, which runs supposedly it's default Apache/PHP configuration. (well probably not, but as always nobody in the team remembers to have changed anything) edit: Someone requested the code that writes to the error.log: "b","c"=>"d"),1)); ?> The commands to view the error log are: sudo tail -f /var/log/apache2/error.log sudo vim /var/log/apache2/error.log sudo cat /var/log/apache2/error.log In all instances the problem occurs that \n is not executed as expected. php apache ubuntu error-handling share|improve this question edited Dec 14 '11 at 12:37 asked Dec 14 '11 at 11:47 erikb85 3,96184382 1 Handling newlines is done by the editor/viewer. Try using a different one. –Oldskool Dec 14 '11 at 11:50 1 Show us the code which is writing to the error log. –symcbean Dec 14 '11 at 12:02 both tried and information added. –erikb85 Dec 14 '11 at 12:38 add a comment| 3 Answers 3 active oldest votes up vote 7 down vote accepted I also faced the same problem, but after sp
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business http://stackoverflow.com/questions/34581507/php-error-log-ignoring-newline Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just http://www.drcoen.com/2012/05/php-error_log-and-newlines-a-solution/ like you, helping each other. Join them; it only takes a minute: Sign up PHP error_log ignoring newline [duplicate] up vote -2 down vote favorite This question already has an answer here: PHP error log and newline error log chars 3 answers Running PHP 7.0.1 I have come across a problem, I use error_log('....'.PHP_EOL.'...'); but when I look at the log file, I get verbatim \n in the output. error_log is set up to use syslog, and ends up in apaches error_log. This is a CentOS 7 system. Bypassing syslog is not an option as that removes the ability to use syslog forwarding to a central log server. php apache syslog share|improve this question error log newline edited Jan 6 at 3:59 Andrea 8,29921744 asked Jan 3 at 20:56 Morten Nilsen 18912 marked as duplicate by Michael Berkowski, Community♦ Jan 3 at 22:07 This question was marked as an exact duplicate of an existing question. Do you insist upon using syslog? If you define a file in php.ini, you can avoid this. stackoverflow.com/questions/1203664/… –Michael Berkowski Jan 3 at 21:17 syslog forwarding is a facility I care about, so, yes. –Morten Nilsen Jan 3 at 21:45 The single comma ' lacks variable interpolation. You should use double quotes. Please see: stackoverflow.com/questions/1402566/… also see: docs.php.net/manual/en/language.types.string.php –Ryan Rentfro Jan 3 at 21:54 1 variable interpolation is not relevant to this question. –Morten Nilsen Jan 3 at 21:56 1 Oh, CentOS7 should be using rsyslog instead of plain old syslog.. Perhaps you can configure it: stackoverflow.com/questions/5463992/… –Michael Berkowski Jan 3 at 22:00 | show 5 more comments 1 Answer 1 active oldest votes up vote -1 down vote if you're worried about cross-os compatibility, just use "\r\n". Seems to be the better choice just about every time... Also remember that \n in single-quotes ( '\n' ) will, indeed, print out the \n verbatim. double-quotes ( "\n" ) will get you what you want. share|improve this answer edited Jan 3 at 22:27 answered Jan 3 at
a basic text editor (Sublime Text 2 with Vim key-bindings being my current choice) and simple debug output statements when trying to track down a bug. With my current job, I deal with an API over AJAX so it's not easy to send debug statements to the browser, hence had been using a combination of PHP's error_log and print_r($var, 1) to get the value of a variable on the server. When debugging this way, I'd usually be doing a tail -f on my error log file, monitoring changes to that as I go. This was all fine, but got very frustrating when dealing with arrays, objects and even strings with newline characters. The reason for this frustration was that newline characters were being displayed in the error log as \n and no new line, so something like $var = array('zero' => 0, 'one' => 1); error_log(print_r($var, 1)); would produce: Array\n(\n [zero] => 0\n [one] => 1\n) instead of the nicer: Array ( [zero] => 0 [one] => 1 ) Not too bad for small arrays but for large objects it's a nightmare! Googling around didn't have an easy answer. I'm sure it's some setting deep in php.ini or my Apache config, but I managed to come up with a pretty neat solution, which I'm going to document here. I started by creating my own error log in /tmp/derror (David's Error = derror!) and letting any one write to it (I realise this could be slightly cleaner/more secure): touch /tmp/derror chmod 766 /tmp/derror Next I needed a nice debug function to write to this file. I wrote one that'll take any number of parameters and for each one, output the current time along side a dump of their value. If it's an object or class, use print_r, otherwise just display the value: function derror() { $f = fopen('/tmp/derror', 'a'); foreach (func_get_args() as $obj) { fwrite($f, date('Y-m-d G:i:s')."\n"); if (is_array($obj) || is_object($obj)) { fwrite($f, print_r($obj,1)."\n\n"); } else { fwrite($f, $obj."\n\n"); } } fclose($f); } // called like derror($var1, $var2); So, that function works fine but after a while I realised by doing my tail -f on my new error file, I was missing out on the real server errors. So, I had 2 different terminal tabs open, flipping between them both, which got annoying after about 2 errors! Luckily, I quickly thought of a way around this: route PHP's error logging to my new file. The way Apache and virtual ho