Logging
Logging is the cutting, skidding, on-site
processing, and loading of trees or logs onto
trucks or skeleton cars.
Slide 3
Slide 3 text
But why should I?
You want to know...
● What happened?
● When did it happen?
● Where did it happen? (and where didn't it?)
● Which steps were taken?
● And sometimes, actual input and output
Slide 4
Slide 4 text
Okay, but how do I do this then?
● Inspiration: log4j (java)
○ PHP: log4php
○ Python: logging (In standard library!)
○ Ruby: log4r, logging
include('Logger.php');
$logger = Logger::getLogger("main");
$logger->info("This is an informational message.");
$logger->warn("I'm not feeling so good...");
INFO - This is an informational message.
WARN - I'm not feeling so good...
Slide 5
Slide 5 text
Tips, tricks & pitfalls
● Use the various levels effectively
○ (WARN == INFO) == False
● Debugging should be OFF on production
● Be careful with big objects or method calls
○ $logger->debug("Doing something with object " .
$this->nastyLongObjectLookup()); // *yawn* App hangs
Slide 6
Slide 6 text
Tips, tricks & pitfalls (cont)
● Be clear and verbose
○ $logger->info("User logged in"); // Uhh.. who did?
$logger->info("User " . $user->id . " logged in");
○ $logger->warn("Got unexpected responsecode from
webservice"); // Which response code?
$logger->warn("Got unexpected responsecode " .
$response->code . " from websevice");
$logger->debug("Response data was: " . $response-
>data"); // Real programmers don't need debuggers ;)