Types of logs Application ● Error / Exception ● Access logs Infrastructure ● Server logs ● Database logs ● Mail logs Issue No. URLs The tag does not have an ALT attribute defined 107,669 The page contains unnecessary redirects 55,195 The page contains broken hyperlinks 9,283 The title is too long 6,444 The page contains invalid markup 5,779 The page was excluded by a noindex attribute 4,531 The page contains multiple canonical formats 4,508 The page contains a large amount of script code 785 The description is too long 700 The page contains a large number of Cascading Style Sheet definitions 104 The page contains multiple tags 85 The tag is missing 38 Logging and Monitoring Example of logging
Log levels (RFC 5424) DEBUG INFO NOTICE WARNING - (0): System is unusable - (5): Normal but significant events ERROR CRITICAL ALERT - (6): Events such as logging in, SQL logs - (4): Exceptional occurrences not errors - (3): Runtime errors no immediate action - (2): Critical. Unexpected exceptions EMERGENCY - (1): Action must be taken immediately - (7): Detailed debug information
API Example namespace WP; class FooBarAPI { public function __contruct($username, $password) { $this->username = $username; $this->password = $password; } public function login($username, $password) { // We would login to a real API here // Return an exception for demonstration throw new \Exception("We have an error"); } }
API Example - Logger namespace WP; use Monolog\Logger; class API extends FooBarAPI { private $logger; public function __construct(Logger $logger) { $this->logger = $logger; } public function test($something) { try { parent::login('admin', 'password'); } catch(\Exception $e) { $this->logger->alert("We have an error, oops!"); $this->logger->warning("This is a warning message"); $this->logger->debug("This is a debug message"); } } }
API Example - Test File require __DIR__ . '/vendor/autoload.php'; use Monolog\Logger; use Monolog\Handler\StreamHandler; // Instantiate logger $log = new Logger('API'); $log->pushHandler(new StreamHandler('app_error.log', Logger::DEBUG)); // create the api and do something $api = new WP\API($log); $api->test("something");
API Example - Log File [2016-11-14T17:57:48.271290+00:00] API.ALERT: We have an error, oops! [] [] [2016-11-14T17:57:48.272004+00:00] API.WARNING: This is a warning message [] []