Just combing through the logs with hundreds or thousands of the same entry is a showstopper. When a bug causes an error, it can fill up the logs pretty quickly. It’s also a way to track performance, which is often a sign or a cause of a bug. What’s a trace? It’s not just a stack dump that lets you see what was going on when an error happened. It should be configurable and you should have control over the configuration. This can be a server issue or errors hitting your logs. Alerting is a way to send alerts automatically to a group email (better than an individual for continuity) when there’s a problem. If you’re a programmer, you know what I mean! You’ll want to automate almost anything if you can. If you can centralize your logs and metrics across instances, that’s even better! You’d be able to spot trouble wherever it happens. You want to see all your logs in one place. The best thing you can do is send your PHP logs to a service that will handle a few key things for you: Unless you have all day and night to hover over the logs, you will not know when something bad is happening! First, you have to know about the errors. It’s one thing to log errors-that’s almost a given. It’s a whole other thing to take action when errors are logged. But even with the best logging settings, you still need to monitor for errors. The PHP manual spells out these settings in more detail and provides more information I could ever fit in this section. Do this in production rather than displaying them to end users. log_errors and error_log work together to send errors to a log file.display_startup_errors should only be used when debugging.display_errors tells PHP if and where to display error messages.E_NOTICE is useful during development since it will tell you about defects such as unassigned variables. error_reporting sets the level of logging.You’ll want to consider the following settings: This is possible, but think about how you would change modes after deploying your application.Ī combination of settings will get you the right levels of error logging. If you can’t use configuration files, you have the option of changing the values via a script. Otherwise, you might use the htaccess configuration. You can use the php.ini file, if you have access to it. PHP has a few ways to configure error reporting. Each function has a purpose and can be useful for debugging. You can see them in action in this Paiza. These functions are a quick way to debug your PHP code. Here’s sample code that exercises each of these useful debugging functions: You can print_r, log it to a file, or send it to a logging endpoint asynchronously. debug_print_backtrace() prints a backtrace that shows the current function call-chain.This is useful when there are multiple paths to update a single reference. debug_zval_dump ($var) dumps the variable with its reference counts.get_defined_vars() gets all the defined variables including built-ins and custom variables (print_r to view them).print_r ($var) prints the variable value in human-readable form to stdout.var_dump ($var) dumps the variable type and value to stdout. There are other functions you can use for debugging through outputs. The var_dump function is one way to see what’s happening in your PHP program. Let me backup to some simple ways to output values. The logs will fill up pretty quickly in “debug mode,” so you only want to turn it on temporarily. When the program is run in debug mode or the log level is set to debug, these messages will end up in your stdout, stderr, or log files. In PHP, you can use various loggers to log debug messages. It’s useful to have debug logging in your program. Sometimes this means doing a var_dump or logging a whole series of events. When you need a simple way to debug programs and you have no other options, you can usually output values.
0 Comments
Leave a Reply. |