I can guarantee you, I am not the only person who has been driven to madness at least once in a frustrating search for a log file. It seems like it should be the easiest thing to find in the whole system.
A definitive guide on where the PHP error log is stored would be a complicated bit of work. The official PHP manual does not even try to address the whole topic, because there are dependencies on systems outside PHP, such as the operating system (Linux vs. Windows, which distribution of Linux), including settings within Windows and Linux that affect the name and location of the PHP error log.
Until someone takes the time to write a complete, cross-system guide, the best you are going to get is general directions where you can inquire. Every PHP developer has had to endure agony in this pursuit, with one exception. If you work in one place and the information is provided when you first need it, then you have the information need forever, that is, until you find yourself in a new working environment. There are such fortunate people.
If the information is not given to you on a silver platter, so to speak, you have some hunting to do. The hunt is not the longest you will face in your career, but it is not the simplest either.
As is evident from the many answers already posted, a smart place to begin is the output of phpinfo(). To view it, create a PHP file containing this:
<?php
phpinfo();
Either browse to that file or run it from the command line. If you do both, you likely will find the error_log is in different places, depending on command line vs. web server use of PHP. That is because the PHP interpreter that runs on a web server is not the same PHP interpreter that runs from the command line, even when the command line is on the same machine as the web server. The answers already posted in here mostly are making an unstated assumption that PHP is running as part of a web server.

The default for error_log is no value

Whatever the value is, it comes from the php.ini files used to configure PHP. There can be many php.ini files. Finding your way among them is confusing at first, but you do not need to deal with this to find your PHP log.
If the output from phpinfo() shows a full path to a file, that is where the log is. You are lucky.
The trick is there usually is not a full path indicated in phpinfo(). When there is not a full path, the location depends on:
-
Whether error_log is no value. If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log.
-
If there is a file name without a path, the location depends on whether the file name has the value syslog. If it syslog, then the PHP error log is injected into the syslog for the server, which varies by Linux distribution. A common location is /var/log/syslog, but it can be anywhere. Even the name of the syslog varies by distribution.
-
If the name without a path is not syslog, a frequent home for the file is is the document root of the website (a.k.a., website home directory, not to be confused with the home directory for your account).
This cheat sheet has been helpful in some situations, but I regret to have to admit it is not nearly universal. You have my condolences.

(PHP 4, PHP 5, PHP 7, PHP 8)
error_log — Send an error message to the defined error handling routines
Description
error_log(
string $message,
int $message_type = 0,
?string $destination = null,
?string $additional_headers = null
): bool
Parameters
-
message -
The error message that should be logged.
-
message_type -
Says where the error should go. The possible message types are as
follows:error_log() log types
0 messageis sent to PHP’s system logger, using
the Operating System’s system logging mechanism or a file, depending
on what the error_log
configuration directive is set to. This is the default option.1 messageis sent by email to the address in
thedestinationparameter. This is the only
message type where the fourth parameter,
additional_headersis used.2 No longer an option. 3 messageis appended to the file
destination. A newline is not automatically
added to the end of themessagestring.4 messageis sent directly to the SAPI logging
handler. -
destination -
The destination. Its meaning depends on the
message_typeparameter as described above. -
additional_headers -
The extra headers. It’s used when the
message_type
parameter is set to1.
This message type uses the same internal function as
mail() does.
Return Values
Returns true on success or false on failure.
If message_type is zero, this function always returns true,
regardless of whether the error could be logged or not.
Changelog
| Version | Description |
|---|---|
| 8.0.0 |
destination andadditional_headers are now nullable.
|
Examples
Example #1 error_log() examples
<?php
// Send notification through the server log if we can not
// connect to the database.
if (!Ora_Logon($username, $password)) {
error_log("Oracle database not available!", 0);
}// Notify administrator by email if we run out of FOO
if (!($foo = allocate_new_foo())) {
error_log("Big trouble, we're all out of FOOs!", 1,
"operator@example.com");
}// another way to call error_log():
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
?>
Notes
Warning
error_log() is not binary safe. message will be truncated by null character.
Tip
message should not contain null character. Note that message may be sent to file, mail, syslog, etc. Use appropriate conversion/escape function, base64_encode(), rawurlencode() or addslashes() before calling error_log().
kevindougans at gmail dot com ¶
12 years ago
Advice to novices: This function works great along with "tail" which is a unix command to watch a log file live. There are versions of Tail for Windows too, like Tail for Win32 or Kiwi Log Viewer.
Using both error_log() and tail to view the php_error.log you can debug code without having to worry so much about printing debug messages to the screen and who they might be seen by.
Further Note: This works even better when you have two monitors setup. One for your browser and IDE and the other for viewing the log files update live as you go.
Sion ¶
4 years ago
DO NOT try to output TOO LARGE texts in the error_log();
if you try to output massive amounts of texts it will either cut of the text at about 8ooo characters (for reasonable massive strings, < 32 K characters) or (for insanely massive strings, about 1.6 million characters) totally crash without even throwing an error or anything (I even put it in a try/catch without getting any result from the catch).
I had this problem when I tried to debug a response from a wp_remote_get(); all of my error_log() worked as they should, except for ONE of them... (-_-)
After about a day of debugging I finally found out why & that's why I type this.
Apparently the response contained a body with over 1.6 million chars (or bytes? (whatever strlen() returns)).
If you have a string of unknown length, use this:
$start_index = 0;
$end_index = 8000;
error_log( substr( $output_text , $start_index , $end_index ) );
frank at booksku dot com ¶
16 years ago
Beware! If multiple scripts share the same log file, but run as different users, whichever script logs an error first owns the file, and calls to error_log() run as a different user will fail *silently*!
Nothing more frustrating than trying to figure out why all your error_log calls aren't actually writing, than to find it was due to a *silent* permission denied error!
i dot buttinoni at intandtel dot com ¶
14 years ago
Be carefull. Unexpected PHP dies when 2GByte of file log reached (on systems having upper file size limit).
A work aorund is rotate logs :)
php at kennel17 dot NOSPAM dot co dot uk ¶
17 years ago
It appears that the system log = stderr if you are running PHP from the command line, and that often stderr = stdout. This means that if you are using a custom error to both display the error and log it to syslog, then a command-line user will see the same error reported twice.
Anonymous ¶
19 years ago
when using error_log to send email, not all elements of an extra_headers string are handled the same way. "From: " and "Reply-To: " header values will replace the default header values. "Subject: " header values won't: they are *added* to the mail header but don't replace the default, leading to mail messages with two Subject fields.
<?php
error_log
("sometext", 1, "zigzag@my.domain",
"Subject: FoonFrom: Rizzlas@my.domainn");?>
---------------%<-----------------------
To: zigzag@my.domain
Envelope-to: zigzag@my.domain
Date: Fri, 28 Mar 2003 13:29:02 -0500
From: Rizzlas@my.domain
Subject: PHP error_log message
Subject: Foo
Delivery-date: Fri, 28 Mar 2003 13:29:03 -0500
sometext
---------------%<---------------------
quoth the docs: "This message type uses the same internal function as mail() does."
mail() will also fail to set a Subject field based on extra_header data - instead it takes a seperate argument to specify a "Subject: " string.
php v.4.2.3, SunOS 5.8
russ at russtanner dot com ¶
3 years ago
You can easily filter messages sent to error_log() using "tail" and "grep" on *nix systems. This makes monitoring debug messages easy to see during development.
Be sure to "tag" your error message with a unique string so you can filter it using "grep":
In your code:
error_log("DevSys1 - FirstName: $FirstName - LastName: $Lastname");
On your command line:
tail -f /var/log/httpd/error_log | grep DevSys1
In this example, we pipe apache log output to grep (STDIN) which filters it for you only showing messages that contain "DevSys1".
The "-f" option means "follow" which streams all new log entries to your terminal or to any piped command that follows, in this case "grep".
Matthew Swift ¶
3 years ago
Relative paths are accepted as the destination of message_type 3, but beware that the root directory is determined by the context of the call to error_log(), which can change, so that one instance of error_log () in your code can lead to the creation of multiple log files in different locations.
In a WordPress context, the root directory will be the site's root in many cases, but it will be /wp-admin/ for AJAX calls, and a plugin's directory in other cases. If you want all your output to go to one file, use an absolute path.
paul dot chubb at abs dot gov dot au ¶
14 years ago
When logging to apache on windows, both error_log and also trigger_error result in an apache status of error on the front of the message. This is bad if all you want to do is log information. However you can simply log to stderr however you will have to do all message assembly:
LogToApache($Message) {
$stderr = fopen('php://stderr', 'w');
fwrite($stderr,$Message);
fclose($stderr);
}
SJL ¶
15 years ago
"It appears that the system log = stderr if you are running PHP from the command line"
Actually, it seems that PHP logs to stderr if it can't write to the log file. Command line PHP falls back to stderr because the log file is (usually) only writable by the webserver.
stepheneliotdewey at GmailDotCom ¶
15 years ago
Note that since typical email is unencrypted, sending data about your errors over email using this function could be considered a security risk. How much of a risk it is depends on how much and what type of information you are sending, but the mere act of sending an email when something happens (even if it cannot be read) could itself imply to a sophisticated hacker observing your site over time that they have managed to cause an error.
Of course, security through obscurity is the weakest kind of security, as most open source supporters will agree. This is just something that you should keep in mind.
And of course, whatever you do, make sure that such emails don't contain sensitive user data.
p dot lhonorey at nospam-laposte dot net ¶
16 years ago
Hi !
Another trick to post "HTML" mail body. Just add "Content-Type: text/html; charset=ISO-8859-1" into extra_header string. Of course you can set charset according to your country or Env or content.
EG: Error_log("<html><h2>stuff</h2></html>",1,"eat@joe.com","subject :lunchnContent-Type: text/html; charset=ISO-8859-1");
Enjoy !
eguvenc at gmail dot com ¶
14 years ago
<?php
//Multiline error log class
// ersin güvenç 2008 eguvenc@gmail.com
//For break use "n" instead 'n'
Class log {
//
const USER_ERROR_DIR = '/home/site/error_log/Site_User_errors.log';
const GENERAL_ERROR_DIR = '/home/site/error_log/Site_General_errors.log';
/*
User Errors...
*/
public function user($msg,$username)
{
$date = date('d.m.Y h:i:s');
$log = $msg." | Date: ".$date." | User: ".$username."n";
error_log($log, 3, self::USER_ERROR_DIR);
}
/*
General Errors...
*/
public function general($msg)
{
$date = date('d.m.Y h:i:s');
$log = $msg." | Date: ".$date."n";
error_log($msg." | Tarih: ".$date, 3, self::GENERAL_ERROR_DIR);
}
}
$log = new log();
$log->user($msg,$username); //use for user errors
//$log->general($msg); //use for general errors
?>
franz at fholzinger dot com ¶
17 years ago
In the case of missing your entries in the error_log file:
When you use error_log in a script that does not produce any output, which means that you cannot see anything during the execution of the script, and when you wonder why there are no error_log entries produced in your error_log file, the reasons can be:
- you did not configure error_log output in php.ini
- the script has a syntax error and did therefore not execute
daniel dot fukuda at gmail dot com ¶
13 years ago
If you have a problem with log file permission *silently*
it's best to leave error_log directive unset so errors will be written in your Apache log file for current VirtualHost.
Anonymous ¶
2 years ago
Depending on the error, you may also want to add an error 500 header, and a message for the user:
$message = 'Description of the error.';
error_log($message);
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
exit($message);
Robert Chapin ¶
4 years ago
When error_log() unexpectedly uses stdout, you should check if the php.ini value for error_log is empty in your CLI environment. Something as simple as this might restore expected behavior:
<?php ini_set('error_log', 'error_log'); ?>
kazezb at nospam dot carleton dot edu ¶
17 years ago
It appears that error_log() only logs the first line of multi-line log messages. To log a multi-line message, either log each line individually or write the message to another file.
Anonymous ¶
13 years ago
After scouring the internet for getting event logging to
work in syslog on Windows 2003, I found the following
from this post and was able to successfully get Windows
Event Viewer to log PHP errors/notices:
http://forums.iis.net/p/1159662/1912015.aspx#1913338
1. Copy the PHP 5 binaries to "C:php".
2. Right-click My Computer and select Properties to bring
up the Computer Properties dialog. Switch to the Advanced
tab and click Environment Variables. Find the system
environment variable PATH, edit it and add ";C:php"
(without the quotes) to the end.
3. Make sure that the configuration file "php.ini" resides
in the directory "C:php" and contains the correct path
settings.
4. DELETE any old "php.ini" files from "C:WINDOWS"
and other directories.
5. Open REGEDIT, navigate to the key
"HKLMSOFTWAREPHP" and DELETE the string value
"IniFilePath" from there. It is outdated and no longer
necessary!
6. Modify NTFS security permissions of the directory
"C:php" to give Read and Execute permissions to (1) the
IIS Guest Account and (2) the group IIS_WPG.
7. Modify NTFS security permissions of the directories
"C:phpsession" and "C:phpupload" to give additional
Modify permissions to (1) the IIS Guest Account and (2)
the group IIS_WPG.
8. Navigate to the registry key
"HKLMSYSTEMCurrentControlSetServicesEventlog
Application" and edit the value "CustomSD" there. Find
the substring "(D;;0xf0007;;;BG)" which Denies access to
the application event log for Builtin Guest accounts (like
the IIS Web User account) and replace this substring with
"(A;;0x3;;;BG)" which allows read and write access. Please
pay attention to leave the rest of the security string intact.
Damaging this value can have dangerous effects!
9. Create or update the registry key
"HKLMSYSTEMCurrentControlSetServicesEventlogApplication
PHP-5.2.0" (adapt the last to your version part
if necessary) with the following values:
* "EventMessageFile" (REG_EXPAND_SZ) = "C:phpphp5ts.dll"
* "TypesSupported" (REG_DWORD) = 7
PHP logs are not just about errors. You can use logs to track the performance of API calls and function calls, or to count the occurrence of significant events in your applications (e.g., logins, signups, and downloads). Whether you’re operating a microservices architecture or a monolith, implementing a comprehensive PHP logging strategy will allow you to track critical changes in your applications and optimize their performance.
PHP and its available logging libraries give you many options for where to send and store your logs. As you’ll see in this post, storing your PHP logs in a central file is simple and gives you the greatest flexibility for processing and analyzing your logs later on. When you use a specialized tool to tail your log file and forward your logs to a central log management solution, your application code isn’t burdened with the overhead of buffering logs and handling network errors.
In this post, you’ll learn how to:
- configure the PHP system logger to automatically log errors
- use native PHP functions to log custom errors
- expand your logging capabilities with the Monolog logging library
- capture PHP exceptions and arbitrary events
How PHP creates logs
The PHP system logger creates logs automatically when the execution of your code produces an error. Additionally, you can create logs by calling PHP’s logging functions as you need to log custom errors and arbitrary events in your application. In this section, we’ll look at how logs are created and routed by each of these mechanisms.
The PHP system logger
You can configure the PHP system logger by using the error_reporting directive in PHP’s configuration file, php.ini, to designate the types of errors PHP will automatically log. This directive uses a set of predefined constants and bitwise operators to express what types of events to include and exclude from logs. For example, you would use this directive to log all errors:
PHP’s display_errors configuration directive gives you the option of displaying log messages in the browser. In a production environment, you should always set display_errors to Off for security reasons. However, in a development environment, you might want to display warnings and errors directly in the browser so developers can easily see information about the application’s status.
The PHP system logger routes logs in different ways depending on the value of the error_log configuration directive in php.ini:
- If
error_lognames a file, PHP writes its logs to that file. - If
error_logis set tosyslog, PHP sends logs to the OS logger. This is usuallysyslogor the newerrsyslog(which implements the syslog protocol) on Linux, orEvent Logon Windows. - If
error_logis unset, PHP creates logs using the Server API (SAPI). The SAPI used depends on your platform. As an example, a LAMP setup usesapacheas a SAPI, and logs are written to Apache’s error log.
To maximize the logging data available and to give yourself options for centralizing, processing, and analyzing your logs later, add the following configuration to your php.ini. (In PHP .ini files, a semicolon indicates the start of a comment.)
; Log all errors
error_reporting = E_ALL
; Don't display any errors in the browser
display_errors = Off
; Write all logs to this file:
error_log = my_file.log
Now your PHP logs are written to the my_file.log file we specified in the error_log directive above.
PHP’s logging functions
You can log any event you choose by explicitly calling PHP’s error_log() or syslog() function within your code. These functions create logs containing the message string you provide. The syslog() function will use the configuration in your rsyslog.conf file to write log messages. The error_log() function routes it to the file specified by the error_log configuration directive. The following example sends a message to the PHP system logger:
<?php
error_log("An error has occurred.");
The PHP system logger automatically adds a timestamp to each log, so each time this code runs, a line like the one below will be appended to our my_file.log file:
[15-Apr-2019 20:25:11 UTC] An error has occurred.
If no value is provided for the error_log configuration item in php.ini, logs are generated by the SAPI, and their format depends on the SAPI in use. For example, on a LAMP server with Apache’s default logging configuration, the example code shown above adds the following line to Apache’s error log (e.g., /var/log/apache2/error.log):
[Mon Apr 15 20:25:11.950260 2019] [php7:notice] [pid 26154] [client 123.123.123.123:57728] An error has occurred.
PHP’s error_log() and syslog() functions provide more options for configuring where your logs are sent. For example, when you call error_log(), you can provide a path to the file where the message should be logged that is different from the one defined by the error_log directive. For information about the advanced routing capabilities of PHP’s error_log() and syslog() functions, see the PHP documentation. In this article, we will focus on logging to a file, since this gives you the ability to forward and process your logs, as we described above.
Centralizing and storing your logs
So far, we’ve looked at PHP’s system logger and native logging functions. These mechanisms don’t provide much flexibility when you want to customize how your logs are formatted or routed, but they make it easy to get started writing logs to a local file. You can also process your logs with an external service. Consider a strategy that combines writing logs to a local file and forwarding them to an external service to aggregate, analyze, and monitor your logs. This way, you can offload log processing and long-term storage and aggregate logs from all your hosts in a single platform. You can troubleshoot an incident much more efficiently if you don’t have to manually log into each of your servers to view logs.
When you use a log management and analytics platform like Datadog, we recommend using JSON-formatted logs. This makes it easy to process, search, filter, and monitor your logs. To make it easy to create JSON logs and route them to a file, we recommend that you use the Monolog logging library. In the next section we will cover how to use the Monolog library to format your logs as JSON and automatically add metadata to all your logs.
The Monolog logging library
Monolog is one of the most widely used PHP logging libraries. It provides all the functionality of PHP’s native logging functions, and makes it easy to create PHP logs in different formats. You can easily differentiate logs within a single application by categorizing them in channels, and you can send your logs to databases, message queues, and external collaboration tools.
Monolog is available in the Packagist repository, and the examples in this section assume you’ve installed Monolog using Composer. If you already have Composer installed, all you need to do is issue this command to add Monolog to your project:
composer require monolog/monolog
In this section, we’ll look at some of the Monolog features that you can use to enhance your PHP logging. We’ll show you how to:
- create and organize logs using loggers and channels
- route logs using Monolog handlers
- use formatters to create JSON-formatted logs
- use processors to log uniform data
- assign appropriate log levels to events of different types
Loggers and channels
To start using Monolog, you need to create a logger—an instance of Monolog’s Logger class:
<?php
// Load dependencies required by Composer (including Monolog):
require_once "vendor/autoload.php";
// Use Monolog's `Logger` namespace:
use MonologLogger;
$logger = new Logger('transactions');
This code creates a logger object named $logger and gives it a channel name of transactions.
Monolog uses channels to differentiate logs that have been routed to the same destination but that contain data about different categories of events. Each time you create a logger, you need to provide a channel name. You can create multiple loggers within your application and use each one to log events related to a category of activity, such as purchases or user accounts. Because each logger’s channel value is associated with the logs it creates (as an object within a JSON-formatted log, for example), channels give you more latitude to use metadata to differentiate your logs.
Handlers
Monolog’s handlers determine how PHP will act on the log messages sent to each logger. The StreamHandler is Monolog’s basic means of writing logs to a file. Numerous other handlers are available so you can easily send logs to the service of your choice.
Once you’ve created a logger, you use it by defining one or more handlers and pushing them onto the Logger object. For each handler you create, you provide information about how it should route the log (e.g., a filename), and a minimum log level at which the handler should be triggered. By pushing multiple handlers onto a logger, you can use it to log different types of events to different destinations.
The following code illustrates pushing a handler on to the logger ($logger) we created above. It then calls Monolog’s info method to trigger the handler and log a message to the file /var/log/monolog/php.log:
<?php
require_once "vendor/autoload.php";
use MonologLogger;
use MonologHandlerStreamHandler;
$logger = new Logger('transactions');
// Declare a new handler and store it in the $logstream variable
// This handler will be triggered by events of log level INFO and above
$logstream = new StreamHandler('/var/log/monolog/php.log', Logger::INFO);
// Push the $logstream handler onto the Logger object
$logger->pushHandler($logstream);
$logger->info('A notable event has occurred.');
This logger creates logs in Monolog’s default format, but it’s easy to make Monolog structure your logs in a useful format. In the next sections of this post, we’ll look at the benefits you gain when you use the JsonFormatter to create your logs.
Formatters
Monolog allows you to define a custom log format, or you can choose an existing formatter to determine how your log messages appear. Monolog formatters are available to meet different logging requirements, and you can choose the one that best suits your needs.
Monolog’s JSONFormatter helps you structure your log data and lets you include any arbitrary data you require. This can make it easy to store multi-line errors in a single log line. You can also store information unique to each session by logging the PHP session array. JSON-formatted logs are easy for log management solutions to parse, so you can search, filter, and analyze your application’s data to track errors, usage, and performance trends.
The sample code below creates JSON logs with a channel value of transactions.
<?php
require_once "vendor/autoload.php";
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterJsonFormatter;
$logger = new Logger('transactions');
$logstream = new StreamHandler('/var/log/monolog/php.log', Logger::INFO);
// Apply Monolog's built-in JsonFormatter
$logstream->setFormatter(new JsonFormatter());
$logger->pushHandler($logstream);
$logger->info('Transaction complete');
When PHP executes this code, a log is added to the specified file—/var/log/monolog/php.log—that looks like this:
{
"message": "Transaction complete",
"context": [],
"level": 200,
"level_name": "INFO",
"channel": "transactions",
"datetime": {
"date": "2019-02-14 17:19:11.332526",
"timezone_type": 3,
"timezone": "UTC"
},
"extra": []
}
To isolate these logs from those created by other loggers in your application, you can use a log management solution to filter your data and view only logs from the transactions channel.
Notice that Monolog automatically adds two arrays to this log—context and extra. You can use these arrays to enrich your logs and provide more information about the activity you’re logging. In the next section, we’ll look at how to create and populate these arrays.
Processors
The context and extra arrays give you options for easily adding metadata to each log. You can use them to store any data that’s useful to you. We recommend using context to log the high-cardinality data that varies between sessions, and extra to log global metadata that’s common to all requests. In this section we’ll illustrate how you can use the two arrays to store different kinds of data.
You can use a Monolog processor to define metadata to be added to each log’s context and extra arrays. Processors make it easy to include the same information consistently across all the logs created by a single logger. The following example defines a Monolog processor to include context and extra data:
<?php
require_once "vendor/autoload.php";
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterJsonFormatter;
$logger = new Logger('transactions');
$logstream = new StreamHandler('/var/log/monolog/php.log', Logger::INFO);
$logstream->setFormatter(new JsonFormatter());
$logger->pushHandler($logstream);
$logger->pushProcessor(function ($record) {
$record['extra']['env'] = 'staging';
$record['extra']['version'] = '1.1';
$record['context'] = array('user' => $_SESSION["user"], 'customerID' => $_SESSION["customerID"], 'checkoutValue' => $_SESSION["checkoutValue"], 'sku_array' => $_SESSION["sku"]);
return $record;
});
$logger->info('Transaction complete');
In the resulting log, both the context and extra arrays are populated.
{
"message": "Transaction complete",
"context": {
"user": "user@example.com",
"customerID": 12102,
"checkoutValue": "17.39",
"sku_array": [468, 116]
},
"level": 200,
"level_name": "INFO",
"channel": "transactions",
"datetime": {
"date": "2019-04-16 15:46:16.531986",
"timezone_type": 3,
"timezone": "UTC"
},
"extra": {
"env": "staging",
"version": "1.1"
}
}
You can also pass context array data as an argument to the method you use to create the log. The example below illustrates passing the log message and context data in a single call:
$logger->info('Transaction complete', array('user' => $_SESSION["user"], 'customerID' => $_SESSION["customerID"], 'checkoutValue' => $_SESSION["checkoutValue"], 'sku_array' => $_SESSION["sku"]));
Log levels
PHP’s error_log() function assumes all messages describe errors within your application, but Monolog allows you to log other types of PHP events as well. Monolog supports eight different log levels—the same ones defined in the syslog protocol—so that each log carries metadata that conveys the severity of the event being logged.
When you call the Monolog function to create a log, you specify the log’s level. This way, you
can log the types of events (e.g., debug, error, or alert) you need to know about. For example, to log an event whose log level is error, you would call the logger’s error method as shown below:
$logger->error('Transaction failed');
Of course, you don’t want to have to revise your code during an outage to log debug messages. Instead you can configure your application to log events of all levels, and use a log management solution to filter logs downstream to isolate certain kinds of events.
Expanding your logging coverage
Because PHP logging is flexible, you have options in how much to log and how to handle your logs. In this section, we’ll look at how PHP exceptions work and how to capture them. We’ll also show you how to expand your logging to capture useful information about different types of events—not just errors.
Centralize and organize your PHP logging for easier analysis with Datadog.
Catch and log exceptions
Like many other languages, PHP uses exceptions to accommodate unintended behavior by your application. An exception is an object PHP creates (or throws) when the execution of your PHP script reaches an unintended state.
Exceptions should be caught when they occur—governed by code that addresses the exceptional case. The exception handler—the code that catches the exception—defines PHP’s behavior and output when faced with an exception. PHP does not automatically log exceptions when they are thrown, so you should create exception handlers that log useful information about the exception.
The code below shows an example of a basic exception handling strategy. The checkUsername function validates the length of the string passed to it, then throws exceptions under certain conditions. The function is called from within a try block, and a catch block handles any exceptions and logs the details.
<?php
require_once "vendor/autoload.php";
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterJsonFormatter;
$logger = new Logger('signups');
$logstream = new StreamHandler('/var/log/monolog/php.log', Logger::INFO);
$logstream->setFormatter(new JsonFormatter());
$logger->pushHandler($logstream);
function checkUsername($username) {
if (strlen($username) < 4) {
throw new Exception("Username $username is not long enough.");
} else if (strlen($username) > 12) {
throw new Exception("Username $username is too long.");
}
// $username is OK
}
try {
checkUsername('me');
} catch (exception $e) {
$message_string = "{$e->getMessage()} (file: {$e->getFile()}, line: {$e->getLine()})";
$logger->error($message_string);
}
When PHP throws an exception, it creates an exception object (named $e in the example above) that is available for the exception handler to use. The exception object contains properties, such as the file and lines of code that have caused the unintended state, that describe the state of the application. It also provides methods you can use to access those properties (such as getMessage() in the example above). You can use an exception handler to access the data contained in the exception object and log details of the exception.
The code above will append a line like this one to the file /var/log/monolog/php.log:
{
"message": "Username me is not long enough. (file: /var/www/html/checkUsername.php, line: 17)",
"context": [],
"level": 400,
"level_name": "ERROR",
"channel": "signups",
"datetime": {
"date": "2019-04-11 20:33:45.500634",
"timezone_type": 3,
"timezone": "UTC"
},
"extra": []
}
Better than logging only the message returned by the exception’s getMessage() method, you should log the exception object itself. The PHP logging standard that Monolog implements, PSR-3, states that a logged exception must be in the exception element of the context array. To log the whole exception object, change the $logger->error() call in the previous example to look like this instead:
$logger->error("checkUsername failed", array('exception' => $e));
When you log the exception object, all the information it contains is recorded in the log as JSON, as shown in this example log:
{
"message": "checkUsername failed",
"context": {
"exception": {
"class": "Exception",
"message": "Username me is not long enough.",
"code": 0,
"file": "/var/www/html/checkUsername.php:16"
}
},
"level": 400,
"level_name": "ERROR",
"channel": "signups",
"datetime": {
"date": "2019-04-24 15:01:17.656613",
"timezone_type": 3,
"timezone": "UTC"
},
"extra": []
}
If you use a log management service, you can use the exception object’s data to view, filter, and analyze your logs.
Catch unhandled exceptions
If your code doesn’t include a handler for a particular exception, PHP will generate a fatal error and halt execution. To prevent this, you can use PHP’s set_exception_handler() function to define your own default exception handler. This way you can avoid the fatal error caused by an unhandled exception, and you can capture the exception in your logs. The example below uses set_exception_handler() to catch and log any unhandled exceptions.
<?php
require_once "vendor/autoload.php";
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterJsonFormatter;
$logger = new Logger('signups');
$logstream = new StreamHandler('/var/log/monolog/php.log', Logger::INFO);
$logstream->setFormatter(new JsonFormatter());
$logger->pushHandler($logstream);
// Define default behavior if an exception isn't caught:
set_exception_handler( function($e) {
$uncaught_log = new Logger('uncaught');
$uncaught_logstream = new StreamHandler('/var/log/monolog/php.log', Logger::ERROR);
$uncaught_logstream->setFormatter(new JsonFormatter());
$uncaught_log->pushHandler($uncaught_logstream);
$uncaught_log->error("Uncaught exception", array('exception' => $e));
});
// Declare an empty class
class myClass {
// empty
}
// Try to call a non-existent function
try {
myClass::myFunction();
} catch (Exception $e) {
$logger->error("Call to myFunction failed", array('exception' => $e));
}
In this code, set_exception_handler() processes the exception thrown when the nonexistent myFunction() is called. It serves as the default exception handler, and will process any uncaught exceptions throughout the script (any of which would otherwise have caused a PHP fatal error).
When this code is executed, it logs an exception like the one below:
{
"message": "Uncaught exception",
"context": {
"exception": {
"class": "Error",
"message": "Call to undefined method myClass::myFunction()",
"Code": 0,
"file": "/var/www/html/test_exception_handler.php:30"
}
},
"level": 400,
"level_name": "ERROR",
"channel": "uncaught",
"datetime": {
"date": "2019-04-11 19:20:20.241717",
"timezone_type": 3,
"timezone": "UTC"
},
"extra": []
}
Note that it does not log the Call to myFunction failed error from the catch block. The code in the catch block would execute if myFunction() threw an exception, but in this case PHP throws an exception when we try to call the nonexistent myFunction(). Since that exception is uncaught, it gets processed by the function defined in set_exception_handler().
Log events (not just errors)
In addition to the errors the PHP system logger records automatically, you can log custom events such as API calls to and from your application. Logging these events allows you to monitor your application’s performance and usage trends. In an application made up of microservices, pretty much everything will be an API call, and you can add custom logging code around any calls worthy of attention. The example below calculates the response time of an API call, then uses Monolog to log the result.
<?php
require_once "vendor/autoload.php";
use MonologLogger;
use MonologHandlerStreamHandler;
use MonologFormatterJsonFormatter;
$logger = new Logger('APIperformance');
$logstream = new StreamHandler('/var/log/monolog/php.log', Logger::INFO);
$logstream->setFormatter(new JsonFormatter());
$logger->pushHandler($logstream);
function myAPIcall() {
$curl = curl_init();
$url = 'http://dummy.restapiexample.com/api/v1/employees';
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$logger->pushProcessor(function ($record) {
$record['extra']['env'] = 'staging';
$record['extra']['version'] = '1.1';
return $record;
});
$start = microtime(TRUE); // A timestamp before the call
$result = myAPIcall();
$end = microtime(TRUE); // Another timestamp after the call
// Log the call duration as a readable string
// and include the context array
$logger->info("myAPIcall took " . ($end - $start) . " seconds.", array('duration' => ($end - $start)), array('user' => $_SESSION["user"], 'customerID' => $_SESSION["customerID"], 'checkoutValue' => $_SESSION["checkoutValue"], 'sku_array' => $_SESSION["sku"]));
Each time this function runs, your logs collect data on the performance of the API call, which you can visualize in a service like Datadog:
In addition to logging API calls, you can expand your logging coverage to capture logins and logouts, as well as other user activity such as signups and transactions.
With all your logs aggregated in one place, Datadog’s Log Analytics makes it easy for you to visualize log data. For example, you can see your aggregated log volume, grouped by channel to understand the amount of activity across the different areas of your application.
From this view, you can export the graph to a dashboard or click to see individual logs. You can even create a monitor to alert on your log data, so you can automatically be notified of any unusual activity captured in your application logs.
For further information about using Monolog and Datadog, see our documentation.
Do more with your PHP logs
PHP logging offers a lot of flexibility that enables you to capture the right information and make it available for troubleshooting and monitoring. Once you’ve configured your applications to log all the information that might be useful to you, you can send your logs to a monitoring platform for in-depth analysis and collaborative troubleshooting. If you’re not already using Datadog to collect and analyze your logs, you can start with a free, full-featured 14-day trial.
All log paths on Windows and Linux:
/etc/httpd/logs/access.log
/etc/httpd/logs/access_log
/etc/httpd/logs/error.log
/etc/httpd/logs/error_log
/opt/lampp/logs/access_log
/opt/lampp/logs/error_log
/usr/local/apache/log
/usr/local/apache/logs
/usr/local/apache/logs/access.log
/usr/local/apache/logs/access_log
/usr/local/apache/logs/error.log
/usr/local/apache/logs/error_log
/usr/local/etc/httpd/logs/access_log
/usr/local/etc/httpd/logs/error_log
/usr/local/www/logs/thttpd_log
/var/apache/logs/access_log
/var/apache/logs/error_log
/var/log/apache/access.log
/var/log/apache/error.log
/var/log/apache-ssl/access.log
/var/log/apache-ssl/error.log
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/httpsd/ssl.access_log
/var/log/httpsd/ssl_log
/var/log/thttpd_log
/var/www/log/access_log
/var/www/log/error_log
/var/www/logs/access.log
/var/www/logs/access_log
/var/www/logs/error.log
/var/www/logs/error_log
C:apachelogsaccess.log
C:apachelogserror.log
C:Program FilesApache GroupApachelogsaccess.log
C:Program FilesApache GroupApachelogserror.log
C:program fileswampapache2logs
C:wampapache2logs
C:wamplogs
C:xamppapachelogsaccess.log
C:xamppapachelogserror.log
All log paths on Windows and Linux:
/etc/httpd/logs/access.log
/etc/httpd/logs/access_log
/etc/httpd/logs/error.log
/etc/httpd/logs/error_log
/opt/lampp/logs/access_log
/opt/lampp/logs/error_log
/usr/local/apache/log
/usr/local/apache/logs
/usr/local/apache/logs/access.log
/usr/local/apache/logs/access_log
/usr/local/apache/logs/error.log
/usr/local/apache/logs/error_log
/usr/local/etc/httpd/logs/access_log
/usr/local/etc/httpd/logs/error_log
/usr/local/www/logs/thttpd_log
/var/apache/logs/access_log
/var/apache/logs/error_log
/var/log/apache/access.log
/var/log/apache/error.log
/var/log/apache-ssl/access.log
/var/log/apache-ssl/error.log
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/httpsd/ssl.access_log
/var/log/httpsd/ssl_log
/var/log/thttpd_log
/var/www/log/access_log
/var/www/log/error_log
/var/www/logs/access.log
/var/www/logs/access_log
/var/www/logs/error.log
/var/www/logs/error_log
C:apachelogsaccess.log
C:apachelogserror.log
C:Program FilesApache GroupApachelogsaccess.log
C:Program FilesApache GroupApachelogserror.log
C:program fileswampapache2logs
C:wampapache2logs
C:wamplogs
C:xamppapachelogsaccess.log
C:xamppapachelogserror.log
В этом руководстве мы расскажем о различных способах того, как в PHP включить вывод ошибок. Мы также обсудим, как записывать ошибки в журнал (лог).
Как быстро показать все ошибки PHP
Самый быстрый способ отобразить все ошибки и предупреждения php — добавить эти строки в файл PHP:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Что именно делают эти строки?
Функция ini_set попытается переопределить конфигурацию, найденную в вашем ini-файле PHP.
Display_errors и display_startup_errors — это только две из доступных директив. Директива display_errors определяет, будут ли ошибки отображаться для пользователя. Обычно директива dispay_errors не должна использоваться для “боевого” режима работы сайта, а должна использоваться только для разработки.
display_startup_errors — это отдельная директива, потому что display_errors не обрабатывает ошибки, которые будут встречаться во время запуска PHP. Список директив, которые могут быть переопределены функцией ini_set, находится в официальной документации .
К сожалению, эти две директивы не смогут отображать синтаксические ошибки, такие как пропущенные точки с запятой или отсутствующие фигурные скобки.
Отображение ошибок PHP через настройки в php.ini
Если ошибки в браузере по-прежнему не отображаются, то добавьте директиву:
display_errors = on
Директиву display_errors следует добавить в ini-файл PHP. Она отобразит все ошибки, включая синтаксические ошибки, которые невозможно отобразить, просто вызвав функцию ini_set в коде PHP.
Актуальный INI-файл можно найти в выводе функции phpinfo (). Он помечен как “загруженный файл конфигурации” (“loaded configuration file”).
Отображать ошибки PHP через настройки в .htaccess
Включить или выключить отображение ошибок можно и с помощью файла .htaccess, расположенного в каталоге сайта.
php_flag display_startup_errors on
php_flag display_errors on
.htaccess также имеет директивы для display_startup_errors и display_errors.
Вы можете настроить display_errors в .htaccess или в вашем файле PHP.ini. Однако многие хостинг-провайдеры не разрешают вам изменять ваш файл PHP.ini для включения display_errors.
В файле .htaccess также можно включить настраиваемый журнал ошибок, если папка журнала или файл журнала доступны для записи. Файл журнала может быть относительным путем к месту расположения .htaccess или абсолютным путем, например /var/www/html/website/public/logs.
php_value error_log logs/all_errors.log
Включить подробные предупреждения и уведомления
Иногда предупреждения приводят к некоторым фатальным ошибкам в определенных условиях. Скрыть ошибки, но отображать только предупреждающие (warning) сообщения можно вот так:
error_reporting(E_WARNING);
Для отображения предупреждений и уведомлений укажите «E_WARNING | E_NOTICE».
Также можно указать E_ERROR, E_WARNING, E_PARSE и E_NOTICE в качестве аргументов. Чтобы сообщить обо всех ошибках, кроме уведомлений, укажите «E_ALL & ~ E_NOTICE», где E_ALL обозначает все возможные параметры функции error_reporting.
Более подробно о функции error_reporting ()
Функция сообщения об ошибках — это встроенная функция PHP, которая позволяет разработчикам контролировать, какие ошибки будут отображаться. Помните, что в PHP ini есть директива error_reporting, которая будет задана этой функцией во время выполнения.
error_reporting(0);
Для удаления всех ошибок, предупреждений, сообщений и уведомлений передайте в функцию error_reporting ноль. Можно сразу отключить сообщения отчетов в ini-файле PHP или в .htaccess:
error_reporting(E_NOTICE);
PHP позволяет использовать переменные, даже если они не объявлены. Это не стандартная практика, поскольку необъявленные переменные будут вызывать проблемы для приложения, если они используются в циклах и условиях.
Иногда это также происходит потому, что объявленная переменная имеет другое написание, чем переменная, используемая для условий или циклов. Когда E_NOTICE передается в функцию error_reporting, эти необъявленные переменные будут отображаться.
error_reporting(E_ALL & ~E_NOTICE);
Функция сообщения об ошибках позволяет вам фильтровать, какие ошибки могут отображаться. Символ «~» означает «нет», поэтому параметр ~ E_NOTICE означает не показывать уведомления. Обратите внимание на символы «&» и «|» между возможными параметрами. Символ «&» означает «верно для всех», в то время как символ «|» представляет любой из них, если он истинен. Эти два символа имеют одинаковое значение в условиях PHP OR и AND.
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
Эти три строки кода делают одно и то же, они будут отображать все ошибки PHP. Error_reporting(E_ALL) наиболее широко используется разработчиками для отображения ошибок, потому что он более читабелен и понятен.
Включить ошибки php в файл с помощью функции error_log ()
У сайта на хостинге сообщения об ошибках не должны показываться конечным пользователям, но эта информация все равно должна быть записана в журнал (лог).
Простой способ использовать файлы журналов — использовать функцию error_log, которая принимает четыре параметра. Единственный обязательный параметр — это первый параметр, который содержит подробную информацию об ошибке или о том, что нужно регистрировать. Тип, назначение и заголовок являются необязательными параметрами.
error_log("There is something wrong!", 0);
Параметр type, если он не определен, будет по умолчанию равен 0, что означает, что эта информация журнала будет добавлена к любому файлу журнала, определенному на веб-сервере.
error_log("Email this error to someone!", 1, "someone@mydomain.com");
Параметр 1 отправит журнал ошибок на почтовый ящик, указанный в третьем параметре. Чтобы эта функция работала, PHP ini должен иметь правильную конфигурацию SMTP, чтобы иметь возможность отправлять электронные письма. Эти SMTP-директивы ini включают хост, тип шифрования, имя пользователя, пароль и порт. Этот вид отчетов рекомендуется использовать для самых критичных ошибок.
error_log("Write this error down to a file!", 3, "logs/my-errors.log");
Для записи сообщений в отдельный файл необходимо использовать тип 3. Третий параметр будет служить местоположением файла журнала и должен быть доступен для записи веб-сервером. Расположение файла журнала может быть относительным путем к тому, где этот код вызывается, или абсолютным путем.
Журнал ошибок PHP через конфигурацию веб-сервера
Лучший способ регистрировать ошибки — это определить их в файле конфигурации веб-сервера.
Однако в этом случае вам нужно попросить администратора сервера добавить следующие строки в конфигурацию.
Пример для Apache:
ErrorLog "/var/log/apache2/my-website-error.log"
В nginx директива называется error_log.
error_log /var/log/nginx/my-website-error.log;
Теперь вы знаете, как в PHP включить отображение ошибок. Надеемся, что эта информация была вам полезна.
Как показать ошибки PHP
Если погуглить «ошибки PHP» или «PHP errors» , то одним из первых результатов в поиске будет ссылка на документацию по функции error_reporting. Эта функция позволяет как установить уровень отчетов об ошибках PHP, так и получить текущий уровень отчетов об ошибках PHP, как определено вашей конфигурацией PHP.
Функция error_reporting принимает единственный параметр, целое число, которое указывает, какой уровень отчетности установить. Если ничего не передавать в качестве параметра, функция error_reporting просто возвращается текущий установленный уровень.
Существует длинный список возможных значений, которые можно передать в качестве параметра. Мы рассмотрим их позже.
Сейчас важно знать, что для каждого значения, которое может быть передано в качестве параметра, в PHP уже существует предопределенная константа. Так, например, константа E_ERROR имеет значение 1. Это означает, что вы можете передать 1 или E_ERROR в функцию error_reporting и получить тот же результат.
Конфигурация отчетов об ошибках
Конфигурация отчетов об ошибках Использование функции error_reporting отлично подходит, когда необходимо просто увидеть любые ошибки, связанные с фрагментом кода, над которым вы сейчас работаете.
Но конечно было бы лучше контролировать, о каких ошибках сообщается в вашей локальной среде разработки, и регистрировать их где-нибудь, чтобы иметь возможность просматривать их позже. Это можно сделать внутри файла инициализации PHP (или php.ini).
Файл php.ini отвечает за настройку всех аспектов поведения PHP. В этом файле Вы можете установить такие вещи, как объем памяти, который следует выделить для сценариев PHP, разрешить загрузку файлов и какие уровни error_reporting вы хотите для своей среды.
Если вы не уверены или не знаете, где находится файл php.ini, один из способов узнать это - создать скрипт PHP, который использует функцию phpinfo. Эта функция выведет всю информацию, относящуюся к вашему PHP.
Как вы можете видеть из моего phpinfo, мой текущий файл php.ini находится в /etc/php/7.3/apache2/php.ini. Ваш файл может иметь другое расположение.

Найдя файл php.ini, откройте его в любом редакторе и найдите раздел «Error handling and logging». Вот тут и начинается самое интересное!
Директивы сообщения об ошибках
Директивы сообщения об ошибкахПервое, что вы увидите в этом разделе, - это раздел комментариев, который включает подробное описание всех констант уровня ошибки. Далее мы будем использовать эти константы, чтобы установить уровни отчетов об ошибках.
Также эти константы задокументированы в документации по PHP.
Под этим списком находится второй список значений. Здесь показано, как установить некоторые часто используемые наборы комбинаций значений отчетов об ошибках, включая значения по умолчанию, предлагаемое значение для среды разработки и предлагаемые значения для "боевого" окружения.
; Common Values:
; E_ALL (Show all errors, warnings and notices including coding standards.)
; E_ALL & ~E_NOTICE (Show all errors, except for notices)
; E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
После всех комментариев указано текущее значение вашего уровня error_reporting. Для локальной разработки я бы предложил установить его на E_ALL, что позволит видеть все ошибки.
error_reporting = E_ALL
Обычно это одна из первых вещей, которую следует сделать при настройке новой среды разработки. Таким образом, можно увидеть все сообщения об ошибках.
После директивы error_reporting вы можете установить некоторые дополнительные директивы. Как и раньше, файл php.ini включает описания каждой директивы. Ниже приведено краткое описание самых важных из них.
Директива display_errors позволяет вам устанавливать, выводить ли PHP ошибки или нет. Обычно у меня установлено значение «On»,что позволяет видеть ошибки по мере их возникновения.Директива display_startup_errors позволяет включить / выключить отображение ошибок, которые могут возникнуть во время запуска PHP. Обычно это ошибки в конфигурации PHP или веб-сервера, а не конкретно в вашем коде. Рекомендуется оставить это значение выключенным, если вы не можете устранить проблему и не уверены, что ее вызывает.Директива log_errors сообщает PHP, нужно ли записывать ошибки в файл журнала ошибок. По умолчанию он всегда включен и рекомендуется.
Остальные директивы можно оставить по умолчанию, за исключением, может быть, директивы error_log, которая позволяет указать, где регистрировать ошибки, если log_errors включен. По умолчанию он регистрирует ошибки там, где где указал ваш веб-сервер.
Настройка логирования ошибок
Настройка логирования ошибокЕсли Вы используете в качестве веб-сервера Apache, в конфигурации виртуального хоста добавьте следующее, чтобы определить местоположение журнала ошибок.
ErrorLog ${APACHE_LOG_DIR}/project-error.log
Если же Вы используете в качестве веб-сервера nginx, тогда в конфигурационный файл вашего проекта необходимо добавить следующее:
error_log /var/www/sites/logs/error.log error;
Итак, в зависимости от вашей локальной среды разработки вам может потребоваться настроить логирование в соответствии с вашими потребностями. В качестве альтернативы, если вы не можете указать журнал логирования на уровне веб-сервера, вы можете установить его на уровне php.ini.
error_log = /path/to/php.log
Стоит отметить, что в этом файле будут регистрироваться все ошибки PHP, и если вы работаете над несколькими проектами, это может быть не совсем удобно.
Поиск и исправление ошибок
Поиск и исправление ошибокЕсли вы недавно начали программировать на PHP и решили включить отчет об ошибках, будьте готовы к тому, что ваш код будет отображать множество сообщений. Вы можете увидеть некоторые вещи, которых не ожидали, и которые необходимо исправить.
Преимущество, однако, в том, что теперь, когда вы знаете, как включить все это на уровне сервера, вы можете быть уверены, что видите эти ошибки, видите когда они случаются, и исправляете их до того, как их увидят другие!
Как искать и исправлять ошибки? Да очень просто. В журнале ошибок как правило указан файл и строка кода, где произошла ошибка. Также в файле журнала ошибок может храниться вся цепочка вызовов, которая привела к возникновению ошибки.
За последние 24 часа нас посетили 8870 программистов и 832 робота. Сейчас ищут 375 программистов …
-

bio_hazard
Активный пользователь- С нами с:
- 14 мар 2007
- Сообщения:
- 31
- Симпатии:
- 0
Здравствуйте, поддскажите пожалуйста куда php выводит ошибки в какой файл? Просто выполняю примеры из учебника -ошибки точно есть, но где их посмотреть не знаю.
-
а почему бы не выводить их прямо в браузер, вместо того, чтобы постоянно лазить в логи?
в php.ini:если все же хотите пользоваться логами, то почитайте тут.
-

bio_hazard
Активный пользователь- С нами с:
- 14 мар 2007
- Сообщения:
- 31
- Симпатии:
- 0
Спасибо, ваш метод очень удобный спсибо.
-

Команда форума
Модератор- С нами с:
- 15 мар 2007
- Сообщения:
- 9.901
- Симпатии:
- 968
simpson, патентуй метод пока не поздно
Продолжая тему спрошу.
Может кто знает как настроить php так чтобы он ошибки складывал в файл error.log в папке рядом со скриптом выполнившим ошибку? -

Вопрос по теме, куда копать, как лучше всего и как былобы логичнее всего сделать, что бы:
При любых ошибках, фаталь, синтаксических, mysql ошибки, заголовки, в общем все видимые в браузере ошибки записывались в файл.
По поводу mysql я примерно знаю как лучше сделать:mysql_query() or die(err_write(«_FILE_, _ERROR_»));
и функция err_write() которая все пихает в файл, но как записать не предсказуемые ошибки синтаксические к примеру.
-

- С нами с:
- 2 фев 2007
- Сообщения:
- 4.680
- Симпатии:
- 1
- Адрес:
- Минск
xak2, ты про log_errors = on в php.ini ?
-

Команда форума
Модератор- С нами с:
- 15 мар 2007
- Сообщения:
- 9.901
- Симпатии:
- 968