The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Logger in slim framework

Fizer's Avatar


24 May, 2012 05:38 PM

I Want to have a logger to log the request URL and sender data for further analysis.
How can I do it in slim framework?

I am a noob to PHP and Slim framework.

  1. Support Staff 1 Posted by Brian Nesbitt on 19 Jun, 2012 02:54 AM

    Brian Nesbitt's Avatar

    First I'd say this sounds like a job for a fronting reverse proxy like nginx. It does a nice job of logging, rotating logs and very fast as well.

    Second if you are running PHP via phpfpm then I think it does logging as well.

    If you insist on doing it in Slim (for debugging / testing) then this should get you started.

    $app->hook('slim.after.router', function () use ($app) {
        $req = $app->request();
        $s = sprintf("[%s] [%s] [%s %s] [%s]", 

    This won't hijack 404's or errors so you'd have to overwrite those specifically but for general pages this should work. The log by default writes out to stderr. If you want it written to a file you can check out the Slim Extras repo:

  2. Brian Nesbitt closed this discussion on 29 Jun, 2012 01:10 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac