New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix function log from Slim/Log.php #851

merged 3 commits into from Feb 25, 2015


None yet
5 participants
Copy link

alexandrubagu commented Jun 25, 2014

Now you can print mixed variables: $app->log->debug(mixed )

$response = array( "data" => "value" );

and also:

$my_obj = new stdClass;
$my_obj->fix = 1;
$my_obj->email = "";


This comment has been minimized.

Copy link

danielgsims commented Jun 27, 2014

I see one problem with this. If you have an object, it will always return the print_r of that object. If the object can be cast a string using the __toString magic method, it won't be triggered by the print_r function.

Of course you could always go with something like this:

if (is_array($object) || (is_object($object) && !method_exists($object, "__toString"))) {
    $message = print_r($object,1);
} else {
    $message = (string) $object;

There are a lot of other ways to cast an object to a string out there. This kind of code is an antipattern because you can't cover all of your cases. For example, what if I implement the Json Serializable interface and want to log all of my classes as JSON? I think it's preferable to go one of two paths: handle all objects the same way, or create a user definable way to handle these logging methods.


This comment has been minimized.

Copy link

alexandrubagu commented Jun 30, 2014

I think your solution is the best. I modified the Log.php file to reflect your sulution.

For other behavior I think a solution is to define a CustomLogWriter

new CustomLogWriter() ));

This comment has been minimized.

Copy link

maldoinc commented Jul 5, 2014

I'd also recommend passing true to the print_r function as per it's signature, rather than relying on php's implicit type conversion


This comment has been minimized.

Copy link

alexandrubagu commented Jul 7, 2014

I modified the print_r statement to use true instead of 1(int)


This comment has been minimized.

Copy link

bensquire commented Aug 5, 2014

Is there any chance this fix can make it into a tagged release? That would be really useful :)

codeguy added a commit that referenced this pull request Feb 25, 2015

Merge pull request #851 from alexandrubagu/fix_log_method
fix function log from Slim/Log.php

@codeguy codeguy merged commit 9f1ee51 into slimphp:master Feb 25, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment