Why I Created a PHP Logging Tool

Hristiyan Dodov
Jul 8 · 3 min read

A couple of months ago, I was developing a plugin for Kirby. Everything was going well until I hit a bump in one JSON response. I tried to dig up some information regarding the bug via echo and var_dump() but the problem with those is that they break the JSON formatting, which ruins the response.

I wanted to get a proper debugging tool and installed Xdebug. Although it had very promising features, it had the following issues:

  • It took some time to set up
  • The Sublime Text plugin didn’t work properly
  • Each request was seconds slower, and most importantly:
  • I still couldn’t log data without ruining the response

This tool has pretty fancy features like breakpoints, but in terms of logging — it only changes the original var_dump() with a more visually appealing version. It doesn’t fix the problem of providing data without messing with the output.

The Solution

While there are tools like Monolog that let you log to a file, they are wrapped up as a dependency for your project, not as a developer tool that you use on demand for debugging. I wanted something that can be used anytime without messing with the codebase of my current project.

At first, I had a simple script that provided a logging function. That function simply saved whatever was passed to it in a file. It was more than enough to help me with my situation regarding the plugin bug.

Then, I realized I can use fs.watch() of Node.js to read data and log it in real time. This was pretty handy because I was able to have a terminal window open while testing and see the logs as they came:

Finally, my browser extension mania kicked in and I couldn’t resist the urge to create an extension that received logs through a WebSocket server and output them in DevTools:

Now, you can log data from the back-end and see it in the console where your front-end logs appear. Very handy!

The tool is called relog:

  • GitHub documentation here
  • CLI tool on npm here
  • Chrome Extension here

Check me out or follow me for similar stuff. Also check out Oblik where we post other cool stuff that you wouldn’t want to miss out:

Dribbble · Behance · Instagram · Twitter · GitHub

Oblik Studio

a cross-disciplinary design studio and the people behind it

Hristiyan Dodov

Written by

Full-Stack Developer at Oblik Studio

Oblik Studio

a cross-disciplinary design studio and the people behind it

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade