How do I log errors and warnings into a file

0 votes
How do I turn on all error and warnings and log them to a file, but to set up all of that within the script (not changing anything in php.ini)?

I want to define a file name and so that all errors and warnings get logged into it.
Sep 14, 2020 in PHP by kartik
• 37,520 points
493 views

1 answer to this question.

0 votes

Hello @kartik,

Use the following code:

ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log( "Hello, errors!" );

Then watch the file:

tail -f /tmp/php-error.log

Hope it helps!!
Thank you!!

answered Sep 14, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How do I get a file extension in PHP?

Hello @kartik, pathinfo() $path_info = pathinfo('/foo/bar/baz.bill'); echo $path_info['extension']; // "bill" Hope ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,840 points
974 views
0 votes
1 answer

How do I capture PHP output into a variable?

Hello, Try this: <?php ob_start(); ?> <xml/> <?php $xml = ob_get_clean(); ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,840 points
1,148 views
0 votes
1 answer

How do I receive email and process it in a web application?

Use procmail if it is installed on ...READ MORE

answered Nov 4, 2020 in PHP by Niroj
• 82,840 points
627 views
0 votes
1 answer

How can I include a php file and also send query parameters in php?

Hello, You could do something like this to ...READ MORE

answered Nov 10, 2020 in PHP by Niroj
• 82,840 points
6,199 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,995 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,696 views
0 votes
1 answer

How do I restore a dump file from mysqldump?

Hello @kartik, It should be as simple as ...READ MORE

answered Aug 18, 2020 in PHP by Niroj
• 82,840 points
1,138 views
0 votes
1 answer

How do I recursively delete a directory and its entire contents files as well as sub dirs in PHP?

Hello @kartik, The user-contributed section in the manual ...READ MORE

answered Aug 24, 2020 in PHP by Niroj
• 82,840 points
1,104 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP