Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lightning talk - Logging

Lightning talk - Logging

A 5 minute lightning talk I gave to my colleagues at a&m impact internetdiensten.

Nick Groenen

February 26, 2013

More Decks by Nick Groenen

Other Decks in Programming


  1. View Slide

  2. Logging
    Logging is the cutting, skidding, on-site
    processing, and loading of trees or logs onto
    trucks or skeleton cars.

    View Slide

  3. 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

    View Slide

  4. Okay, but how do I do this then?
    ● Inspiration: log4j (java)
    ○ PHP: log4php
    ○ Python: logging (In standard library!)
    ○ Ruby: log4r, logging
    $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...

    View Slide

  5. 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

    View Slide

  6. 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 ;)

    View Slide

  7. Tips, tricks & pitfalls (cont)
    ● grep, sed, awk, sort, uniq
    ● Critical/Exception?
    ○ Yes, log it, but
    more importantly....

    View Slide

  8. Now, go forth
    and log!
    Image credits
    Logging truck and bush taxi accident: Wikipedia uploader Amcaja
    The Sentry: Marvel Comics

    View Slide