PHP code example of devexpress / logify.alert.php

1. Go to this page and download the library: Download devexpress/logify.alert.php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devexpress / logify.alert.php example snippets


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

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\Attachment;
 composer.phar install

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

use DevExpress\Logify\LogifyAlertClient;
    
    $client = LogifyAlertClient::get_instance();
    $client->apiKey = 'SPECIFY_YOUR_API_KEY_HERE';
    $client->start_exceptions_handling();

use DevExpress\Logify\LogifyAlertClient;
    
    try {
        $client = LogifyAlertClient::get_instance();
        $client->apiKey = 'SPECIFY_YOUR_API_KEY_HERE';
    }
    catch (Exception $e) {
        $client->send($e);
    }


class LogifyAlert{
    public $settings = array(
        'apiKey' => 'SPECIFY_YOUR_API_KEY_HERE',
        'userId' => 'php user',
        'appName' => 'Test PHP Application',
        'appVersion' => '0.0.0.1',
    );
    public $collectExtensions = true;
    public $offlineReportsCount = 10;
    public $offlineReportsDirectory = '<directory-for-offline-reports>';
    public $offlineReportsEnabled = true;
    public $breadcrumbsMaxCount = 1100;

    public $ignoreKeyPattern = '([pP][aA][sS][sS][wW][oO][rR][dD])';
    public $ignoreGetBody = true;
    public $ignorePostBody = true;
    public $ignoreCookies = true;
    public $ignoreFilesBody = true;
    public $ignoreEnvironmentBody = true;
    public $ignoreRequestBody = true;
    public $ignoreServerVariables = true;

}

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

    $client->apiKey = 'SPECIFY_YOUR_API_KEY_HERE';

    $client->appName = 'My Application';

    $client->appVersion = '0.0.0.1';

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 = "My attachment's unique name per one report";
    $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;

    $client->breadcrumbs;

    $client->breadcrumbsMaxCount = 1100;

    $client->collectExtensions = true;

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

    $tags = array('OS' => 'Win8');
    $client->tags = $tags;

    $client->ignoreKeyPattern = '([pP][aA][sS][sS][wW][oO][rR][dD])';
    $client->ignoreGetBody = true;
    $client->ignorePostBody = true;
    $client->ignoreCookies = true;
    $client->ignoreFilesBody = true;
    $client->ignoreEnvironmentBody = true;
    $client->ignoreRequestBody = true;
    $client->ignoreServerVariables = true;

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

    $client->ignoreGetBody = true;

    $client->ignorePostBody = true;

    $client->ignoreCookies = true;

    $client->ignoreFilesBody = true;

    $client->ignoreEnvironmentBody = true;

    $client->ignoreRequestBody = true;

    $client->ignoreServerVariables = true;

    $client->offlineReportsCount = 20;

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

    $client->offlineReportsDirectory = '<directory-for-offline-reports>';

    $client->offlineReportsEnabled = true;
    $client->offlineReportsDirectory = '<directory-for-offline-reports>';

    $client->offlineReportsEnabled = true;

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

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

    $client->userId = "[email protected]";

    $client = LogifyAlertClient::get_instance();

    $client->start_exceptions_handling();

    $client->stop_exceptions_handling();

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

try {
    RunCode();
}
catch (Exception $ex) {
    $customdata = array('FailedOperation' => 'RunCode');
    $client->send($ex, $customdata);
}

use DevExpress\Logify\Core\Attachment;

    try {
        RunCode();
    }
    catch (Exception $ex) {
        $customdata = array('FailedOperation' => 'RunCode');
  
        $attachment = new Attachment();
        $attachment->name = "My attachment's unique name per one report";
        $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);
    }

use DevExpress\Logify\LogifyAlertClient;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.");

use DevExpress\Logify\LogifyAlertClient;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category");

use DevExpress\Logify\LogifyAlertClient;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category", date("c"));

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\BreadcrumbLevel;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category", date("c"), BreadcrumbLevel::Debug);

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\BreadcrumbLevel;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category", date("c"), BreadcrumbLevel::Debug, "MyEvent");

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\BreadcrumbLevel;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category", date("c"), BreadcrumbLevel::Debug, "MyEvent", "MyClass");

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\BreadcrumbLevel;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category", date("c"), BreadcrumbLevel::Debug, "MyEvent", "MyClass", "MyMethod");

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\BreadcrumbLevel;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->add("breadcrumb message", "debug_category", date("c"), BreadcrumbLevel::Debug, "MyEvent", "MyClass", "MyMethod", 10);

use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\BreadcrumbLevel;

    $client = LogifyAlertClient::get_instance();

    $customData = array('breadcrumb1' => 'breadcrumbData1', 'breadcrumb2' => 'breadcrumbData2');

    $client->breadcrumbs->add("A breadcrumb message.", "debug_category", date("c"), BreadcrumbLevel::Debug, "MyEvent", "MyClass", "MyMethod", 10, $customData);

use DevExpress\Logify\LogifyAlertClient;

    $client = LogifyAlertClient::get_instance();

    $breadcrumbs = $client->breadcrumbs->get();


use DevExpress\Logify\LogifyAlertClient;

    $client = LogifyAlertClient::get_instance();

    $client->breadcrumbs->clear();


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;
    }
 
use DevExpress\Logify\LogifyAlertClient;
use DevExpress\Logify\Core\Attachment;

    $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');
    }
 
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 />';
        }
    }
require_once('/Logify/LoadHelper.php');
require __DIR__ . '/vendor/autoload.php';