Open source Exception Management platform Jcatch

Source: Internet
Author: User
Tags error handling getmessage php class php framework yii
Github

Https://github.com/wucao/JCatch what is Jcatch

When the program is abnormal (Exception), the processing is generally recorded through the log file, this way is easy to ignore, and query more trouble.

Jcatch provides a scheme, when the program is abnormal, through the Jcatch platform interface submitted to the Jcatch platform, by the Jcatch Platform Unified management of all exceptions, so that can be easily queried, and jcatch platform to provide abnormal monitoring functions, When an exception occurs in an application, the person is alerted by mail.

Application list:

Application configuration:

List of exceptions:

Exception Details:

Mail notification:

PHP Exception:
Deploy Jcatch MySQL Database

Create a table using the MySQL database to execute SQL scripts in Doc/sql.sql

To modify the database connection configuration in Src/main/resources/mybatis.xml and Src/main/resources/generatorconfig.xml files log on to the Administrator account

Default Administrator account: User name admin password xxg

Administrator login based on the spring security implementation, you can configure the Src/main/resources/springsecurity.xml file to support the mail subscription feature

The mail subscription feature sends an email to an application subscriber every hour when an exception is applied, and the message content is an exception in this hour, configured src/main/resources/messageservice.xml support Mail subscription package

MVN package API submits a exception

Url:http://[your Baseurl]/api/submitexceptionjson?appid=[your AppId]

Request Type: POST

Request Body:

{"
    fileName": "Main.java",
    "methodname": "Main",
    "ClassName": "Com.xxg.jcatch.Main",
    "StackTrace" : "Java.lang.ArithmeticException:/By Zero\n\tat Com.xxg.jcatch.Main.main (main.java:16) \n\tat Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method) \n\tat Sun.reflect.NativeMethodAccessorImpl.invoke ( nativemethodaccessorimpl.java:62) \n\tat Sun.reflect.DelegatingMethodAccessorImpl.invoke ( delegatingmethodaccessorimpl.java:43) \n\tat Java.lang.reflect.Method.invoke (method.java:498) \n\tat Com.intellij.rt.execution.application.AppMain.main (appmain.java:144) \ n ",
    " message ":"/By Zero ",
    " LineNumber ":"
    exceptionname ":" Java.lang.ArithmeticException "
}

Response Body:

{
    ' success ': true
}
Client Access Java

Jcatch Java Client Portal: https://github.com/wucao/jcatch-java-client PHP General

<?php function Submittojcatch ($e) {$json = Json_encode ($e);
    $ch = Curl_init (' http://<your baseurl>/api/submitexceptionjson?appid=<your appid> '); Curl_setopt_array ($ch, Array (Curlopt_post => true, Curlopt_returntransfer => true, Curlopt_
        Httpheader => Array (' Content-type:application/json '), Curlopt_postfields => $json,
    Curlopt_connecttimeout => 2, Curlopt_timeout => 4,));
Curl_exec ($ch); 
        function Error_Handler ($errno, $errstr, $errfile, $errline) {submittojcatch (Array (' message ' => $errstr,
' FileName ' => $errfile, ' linenumber ' => $errline,));
        The function Exception_handler ($exception) {Submittojcatch (Array ("FileName" => $exception->getfile (), "LineNumber" => $exception->getline (), "StackTrace" => $exception->gettraceasstring (), " Message "=> $exception->getmEssage (), "Exceptionname" => Get_class ($exception));
} set_error_handler ("Error_Handler"); Set_exception_handler ("Exception_handler");

The errors and exceptions of PHP will be handled by Set_error_handler, Set_exception_handler, and the general PHP framework will have its own set of error handling mechanisms, If you use the PHP framework to recommend that you submit errors to jcatch through the framework's own error handling mechanism, there are several ways for each frame to access the Jcatch. Laravel

To modify the app/exceptions/handler.php file:

public function (Exception $exception) {$appId = ' <your appid> '; $SUBMITURL = ' Http://<your baseurl>/api/submitexceptionjson?appid= '.
    $appId; $data = Json_encode (["FileName" => $exception->getfile (), "linenumber" => $exceptio N->getline (), "StackTrace" => $exception->gettraceasstring (), "message" => $exception

    ->getmessage (), "Exceptionname" => Get_class ($exception)]);
    $ch = Curl_init ($SUBMITURL);
        Curl_setopt_array ($ch, Array (Curlopt_post => true, Curlopt_returntransfer => true,     Curlopt_httpheader => Array (' Content-type:application/json '), Curlopt_postfields
    => $data, Curlopt_connecttimeout => 2, Curlopt_timeout => 4,));

    Curl_exec ($ch);
Return Parent::report ($exception); }
CodeIgniter 3.x

Under Application/core directory, create a new file my_exceptions.php with the following code:

<?php

class My_exceptions extends ci_exceptions
{public

    function log_exception ($severity, $message, $ filepath, $line)
    {
        parent::log_exception ($severity, $message, $filepath, $line);

        $json = Json_encode (Array (
            "message" => $message,
            "FileName" => $filepath,
            "linenumber" => $line c9/>));

        $ch = Curl_init (' http://<your baseurl>/api/submitexceptionjson?appid=<your appid> ');
        Curl_setopt_array ($ch, Array (
            curlopt_post => true,
            Curlopt_returntransfer => true,
            Curlopt_ Httpheader => Array (
                ' Content-type:application/json '
            ),
            curlopt_postfields => $json,
            Curlopt_connecttimeout => 2,
            curlopt_timeout => 4,
        ));
        Curl_exec ($ch);
    }

When an error or exception occurs, the CI framework automatically invokes the above code and submits the exception information to the Jcatch API. YII 1.1

Create a new file in the Protected/components directory errorhandler.php, the code is as follows:

<?php Class ErrorHandler extends Cerrorhandler {public $jcatchBaseUrl;
    Public $jcatchAppId;

    Public $jcatchSecretKey;
        protected function HandleException ($exception) {parent::handleexception ($exception); $this->submittojcatch (Array ("FileName" => $exception->getfile (), "linenumber" => $exc Eption->getline (), "StackTrace" => $exception->gettraceasstring (), "message" => $EXCEP

    Tion->getmessage (), "Exceptionname" => Get_class ($exception));
        } protected function HandleError ($event) {parent::handleerror ($event); $this->submittojcatch (' message ' => $event->message, ' fileName ' => $event->fi
    Le, ' linenumber ' => $event->line,));

        Private Function Submittojcatch ($e) {$json = Json_encode ($e); $ch = Curl_init ($this->jcatchbaseurl.'
        /api/submitexceptionjson?appid= '. $this->jcatchappid);
            Curl_setopt_array ($ch, Array (Curlopt_post => true, Curlopt_returntransfer => true, Curlopt_httpheader => Array (' Content-type:application/json '), Curlopt_po
        Stfields => $json, Curlopt_connecttimeout => 2, Curlopt_timeout => 4,));
    Curl_exec ($ch); }
}

Modify the configuration file used, such as protected/config/main.php:

' ErrorHandler ' =>array (
    ' erroraction ' => ' site/error ',
    ' class ' => ' ErrorHandler ',
    ' Jcatchbaseurl ' => ' <your baseurl> ', ' jcatchappid ' => ' <your appid> ', ' Jcatchsecretkey '
    > ' <your secretkey> ',
),

When an error or exception occurs, the YII framework automatically invokes ErrorHandler to handle the exception, submitting the exception information to the Jcatch API.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.