DOCUMENTATION

PHP Client

Install Manually

To add the Logify Alert client to the application's code, follow the steps below.

  1. Copy the Logify folder to your PHP project.

  2. Use the code below to include the LoadHelper.php file to the PHP script you use to call the Logify API.

    require_once('/Logify/LoadHelper.php');

  3. Register the library autoloader by executing the following code:

    spl_autoload_register(array("DevExpress\LoadHelper", "LoadModule"));

All classes in the library are wrapped in the DevExpress\Logify namespace. Apply the use operator as demonstrated below to get rid of long names in your code:

use DevExpress\Logify\LogifyAlertClient; use DevExpress\Logify\Core\Attachment;

Install with Composer

To add the Logify Alert client to the application's code with Composer, follow the steps below.

  1. Create a composer.json file in your project's root folder or use an existing one.

  2. Add the section below to the composer.json file.
    "require": {
        "devexpress/logify.alert.php": "dev-master"
    }

  3. Execute the following command:

    php composer.phar install

  4. Add require __DIR__ . '/vendor/autoload.php'; to your PHP project.

All classes in the library are wrapped in the DevExpress\Logify namespace. Apply the use operator as demonstrated below to get rid of long names in your code:

use DevExpress\Logify\LogifyAlertClient; use DevExpress\Logify\Core\Attachment;

Logify Alert supports PHP starting from ver. 5.4.

Properties

apiKey

Type: String

Specifies the API Key used to register an application within the Logify service.

$client->apiKey = 'SPECIFY_YOUR_API_KEY_HERE';

appName

Type: String
Default value: null

Specifies the application name.

$client->appName = 'My Application';

appVersion

Type: String
Default value: null

Specifies the application version.

$client->appVersion = '1.0.2';

attachments

Type: array(Attachment)
Default value: null

Specifies a collection of files attached to a report. The total attachments size must not exceed 3 Mb per crash report. The attachment name must be unique within a crash report.

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\Attachment;
$client = LogifyAlertClient::get_instance();
$client->apiKey = 'SPECIFY_YOUR_API_KEY_HERE';
$attachment = new Attachment();
$attachment->name = "MyAttachedImage.jpg";
$attachment->content = file_get_contents('C:\Work\Image_to_attach.jpg');
// We strongly recommend that you specify the attachment type.
$attachment->mimeType = 'image/jpeg';

$attachments = array($attachment);
$client->attachments = $attachments;

collectExtensions

Type: Boolean
Default value: false

Specifies whether loaded PHP extensions are collected and sent to the server.

$client->collectExtensions = true;

customData

Type: Array
Default value: null

Gets the collection of custom data sent with generated reports. Use the customData property to attach additional information to the generated report. For instance, you can use this property to track additional metrics that are important regarding your application: CPU usage, environment parameters, etc.

$customData = array('CustomerName' => 'Mary'); $client->customData = $customData;

Ignore Variables

Specifies configuration values used to enable the $GLOBALS system values collection.

Note: Before collecting $GLOBALS system values, make sure none of them stores personal or private data (passwords, logins, and etc.). If so, use the ignoreKeyPattern property to exclude the required key's value from collecting.

ignoreKeyPattern

Type: String
Default value: null

A regular expression to exclude personal or private data (passwords, logins, and etc.) from collecting the $GLOBALS system values. By default, all system values are collected.

$client->ignoreKeyPattern = '([pP][aA][sS][sS][wW][oO][rR][dD])';

ignoreGetBody

Type: Boolean
Default value: false

Specifies whether the $_GET array's data is collected and sent to the server.

$client->ignoreGetBody = true;

ignorePostBody

Type: Boolean
Default value: false

Specifies whether the $_POST array's data is collected and sent to the server.

$client->ignorePostBody = true;

ignoreCookies

Type: Boolean
Default value: false

Specifies whether the $_COOKIE array's data is collected and sent to the server.

$client->ignoreCookies = true;

ignoreFilesBody

Type: Boolean
Default value: false

Specifies whether the $_FILES array's data is collected and sent to the server.

$client->ignoreFilesBody = true;

ignoreEnvironmentBody

Type: Boolean
Default value: false

Specifies whether the $_ENVIROMENT array's data is collected and sent to the server.

$client->ignoreEnvironmentBody = true;

ignoreRequestBody

Type: Boolean
Default value: false

Specifies whether the $_REQUEST array's data is collected and sent to the server.

$client->ignoreRequestBody = true;

ignoreServerVariables

Type: Boolean
Default value: false

Specifies whether the $_SERVER array's data is collected and sent to the server.

$client->ignoreServerVariables = true;

offlineReportsCount

Type: Integer
Default value: 0

Specifies how many previous reports are kept once an Internet connection is lost. Reports are only saved when the offlineReportsEnabled property is set to true.

$client->offlineReportsEnabled = true; $client->offlineReportsCount = 20;

offlineReportsDirectory

Type: String

Specifies a directory path for storing reports once an Internet connection is lost. Reports are only saved when the offlineReportsEnabled property is set to true.

$client->offlineReportsEnabled = true; $client->offlineReportsDirectory = '';

offlineReportsEnabled

Type: Boolean
Default value: false

Specifies if Logify should store the last offlineReportsCount reports once an Internet connection is lost. Call the send_offline_reports method to send the kept reports once an Internet connection is available.

$client->offlineReportsEnabled = true; $client->offlineReportsCount = 20; // Keeps the last 20 reports $client->offlineReportsDirectory = "";

pathToConfigFile

Type: String

Specifies the configuration file path.

$client->pathToConfigFile = '/config.php';

tags

Type: Array

Gets the collection of tags specifying additional report fields, which will be used in auto ignoring, filtering or detecting duplicates.

A key is a tag name (a string that consists of a-z, A-Z, 0-9, and _ characters), and a value is a tag value that is saved to a report. A new tag is added with Allow search enabled.

$tags = array('tag_name' => 'tag_value'); $client->tags = $tags;

userId

Type: String

Specifies a unique user identifier that corresponds to the sent report.

$client->userId = "user@myapp.com";

Methods

get_instance

Returns a single instance of the LogifyAlert class.

$client = LogifyAlertClient::get_instance();

send

Generates a crash report based on the caught exception and sends this report to the Logify Alert service.

  • send(Exception $ex)

    Generates a crash report based on the caught exception and sends this report to the Logify Alert service.

    try {
        RunCode();
    }
        catch (Exception $ex) {
        $client->send($ex);
    }

  • send(Exception $ex, $customData, $attachments)

    Sends the caught exception with the specified custom data and attachments to the Logify Alert service.

    use DevExpress\Logify\Core\Attachment;
    try {
      RunCode();
    }
    catch (Exception $ex) {
      $customdata = array('FailedOperation' => 'RunCode');
      $attachment = new Attachment();
      $attachment->name = "MyAttachedImage.jpg";
      $attachment->content = file_get_contents('C:\Work\Image_to_attach.jpg');
      // We strongly recommend that you specify the attachment type.
      $attachment->mimeType = 'image/jpeg';
      $attachments = array($attachment);
      $client->send($ex, $customdata, $attachments);
    }

send_offline_reports

Sends all reports saved in the offlineReportsDirectory folder to the Logify Alert service.

start_exceptions_handling

Commands Logify Alert to start listening to uncaught exceptions and sends reports for all processed exceptions.

$client->start_exceptions_handling();

stop_exceptions_handling

Commands Logify Alert to stop listening to uncaught exceptions.

$client->stop_exceptions_handling();

Callbacks

set_after_report_exception_callback(callable $afterReportExceptionHandler)

Occurs after Logify Alert sends a new crash report to the service.

The $afterReportExceptionHandler's $response parameter is true if the report has been sent successfully. Otherwise, the $response parameter contains the error message that occurred during sending.

use DevExpress\Logify\LogifyAlertClient;
$client = LogifyAlertClient::get_instance();
$client->start_exceptions_handling();
$client->set_after_report_exception_callback('after_report_exception');
function after_report_exception($response){
	if($response !== true){
    	echo $response.'<br />';
	}
}

set_before_report_exception_callback(callable $beforeReportExceptionHandler)

Occurs before Logify Alert sends a new crash report to the service.

The set_before_report_exception_callback event occurs between the set_can_report_exception_callback callback and sending a new report to the Logify Alert service. If sending the report is canceled in the set_can_report_exception_callback event's handler, the report is not sent and the set_before_report_exception_callback event is not raised.

Use the set_can_report_exception_callback event's handler to add custom data or an attachment to the sent report by assigning the required data to the customData or attachments property.

$client->set_before_report_exception_callback('before_report_exception');
function before_report_exception(){
    $client = LogifyAlertClient::get_instance();
    $attachment = new Attachment();
    $attachment->name = 'My attachment's unique name per one report';
	$attachment->mimeType = 'image/jpeg';
	$attachment->content = file_get_contents(''C:\Work\Image_to_attach.jpg'');;
	$client->attachments = array($attachment);
	$client->customData = array('CustomerName' => 'Mary');
}

set_can_report_exception_callback(callable $canReportExceptionHandler)

Occurs between generating a new crash report and calling the $beforeReportExceptionHandler.

The set_can_report_exception_callback event occurs right after a new report is generated and ready to be sent to the Logify Alert service. Handle this event by returning false from your function to cancel sending the report. Thus, the generated report is not sent to the service and the set_before_report_exception_callback is not raised.

use DevExpress\Logify\LogifyAlertClient;
$client = LogifyAlertClient::get_instance();
$client->start_exceptions_handling();
$client->set_can_report_exception_callback('can_report_exception');
function can_report_exception($exception){
	if($exception instanceof Error){
    	return false;
	}
	return true;
}

Terms of use Copyright © 2016-2019 Developer Express Inc.