Logs.ws - PHP API Library
This library can be used in your PHP script to send your application error logs to the Logs.ws server.
(c) 2013-2014 Logs.ws
Download the PHP API Library “Logs.php” from
https://github.com/Logs-ws/PHP-API
Open php.ini and add the path of the Logs.php class file in the auto_prepend_file directive. Learn more about auto_prepend_file
auto_prepend_file = "path/to/Logs.php"Alternatively, if you do not have access to php.ini, you can create .htaccess file on your project root and add the following line in it.
php_value auto_prepend_file "path/to/Logs.php"Open Logs.php class file and change the following setting with your Logs.ws API key. Your API key can be found at the Account Settings page.
<?php const API_KEY = 'YOUR-API-KEY'; ?>You can also set the value for DEBUG to true if you want to display errors on your site.
<?php const DEBUG = true; ?>With the completion of the above 3 steps, you are done setting up the library and its ready to use. You do not have to include the Logs.php class file anywhere as it will be included automatically as per the settings done in Step 2 above. To see it in action, open any php page inside your project and write a code that would generate an error.
For example, let us see an example of generating a fatal error. Lets call a function that has not yet defined.
<?php TestFunction(); ?>Once you execute the above script, it will silently (assuming DEBUG is set to false) send the error log to your Logs.ws account. You can see the log from your account dashboard.
You can also manually send your logs using the Send() method. You do not have to create an instance of the Logs class since its already created inside the Logs.php file.
<?php
try{
// Try code here..
} catch(Exception \$e){
\$type = 'INFO'; //Optional. Possible values INFO, WARNING, ERROR.
\$Log->Send(\$e->getMessage(), \$type);
}
?>