The PHP podcast where everyone chimes in.

Originally aired on

March 28th, 2017

060: Logging & Crash Reporting in PHP

No matter how experienced you are as a programmer, at some point your app will generate errors and crash. Fixing problems with your app quickly is paramount in order to affect as little of your user base as possible. We discuss what is involved with implementing effective logging and crash reporting techniques in PHP to help you keep your apps up and running like a well-oiled machine.

with


Logging & Crash Reporting in PHP Show Summary


What are logs and why do we care about logging?

  • Logs are streams of time-ordered events collected from a running process
  • Logging can generate huge amounts of output
  • Logs allow us to reason about our systems by telling us:
    • What is happening
    • When it is happening
    • Why it is happening
  • We can use tools to help us to
    • Isolate relevant events based on queries
    • Notify us about important events (e.g: by email, slack, etc)

What should we log?

  • In general, log more rather than less
  • There are some things we should not log:
    • Passwords
    • Personal data
    • Software with filtering can help with this
  • Logging too much can impact performance

The de-facto standard for logging in PHP is PSR-3 and the most common logging library is monolog.

PSR-3 Defines a lot of log levels. How many should we use?

  • DEBUG, INFO, WARNING and ERROR is probably enough for most apps
  • The levels we use are based on the syslog RFC
  • It depends on the scale of your application

How can we visualize logs?

  • tail -f
  • The ELK Stack is popular, fast and (relatively) easy to set up
    • Elasticsearch indexes logs and makes them searchable
    • Logstash collates the data from different log sources
    • Kibana is the visualization layer for analyzing the data

Where should we write logs?

  • Flat files and logrotate
  • A buffering system like Redis or Kafka
  • Send logs to an aggregation service

John-Daniel Trask


Daniel Berman


Developer Shout-Out

The Developer Shout-Out recognizes developers in the community for their contributions.

For this episode the panel guests, John-Daniel and Daniel nominated Zeev Suraski for the Developer Shout-Out segment.

Thank you, Zeev Suraski for all your contributions to the PHP community. A $50 Amazon gift card is on its way to you.

$50 Amazon gift card sponsored by Gordon Wilson

Gordon Wilson

Gordon Wilson

"I'm not affiliated to any company, but just want to show my appreciation for the excellent work you and your guests do for all us listeners."

Show Notes Credit

Chris Shaw

Thank you Chris Shaw for authoring the show notes for this episode!

If you'd like to contribute show notes and totally get credit for it, check out the show-notes repo!