PHP code example of easonlee / monolog-mysql

1. Go to this page and download the library: Download easonlee/monolog-mysql 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/ */

    

easonlee / monolog-mysql example snippets



use Monolog\Logger;
use Easonlee\MonologMysql\MySQLHandler;

$mysqlHandler = new MySQLHandler(DB::connection('your_connection')->table("logs"));
$logger->pushHandler($mysqlHandler);



use Eason\Monolog\Processer\ExceptionProcessor;
use Monolog\Logger;

// 創建一個 Logger 實例
$logger = new Logger('name');

// 將 ExceptionProcessor 添加到 Logger 中
$logger->pushProcessor(new ExceptionProcessor());



try {
    // 模擬一個異常
    throw new Exception('test');
} catch (Throwable $exception) {
    // 記錄異常,並將異常對象作為上下文數據的一部分
    $logger->alert('An exception occurred', ['exception' => $exception]);
}