PHP code example of moktech / mocklogger-sdk

1. Go to this page and download the library: Download moktech/mocklogger-sdk 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/ */

    

moktech / mocklogger-sdk example snippets


'providers' => [
    // ...
    Moktech\MockLoggerSDK\MockloggerServiceProvider::class,
],

use Moktech\MockLoggerSDK\MockLogger;

class TerminableMiddleware
{
    protected $logger;

    public function __construct(MockLogger $logger)
    {
        $this->logger = $logger;
    }

    public function handle(Request $request, Closure $next): Response
    {
        return $next($request);
    }

    public function terminate(Request $request, Response $response)
    {  
        try {
            $this->logger->sendLog($request, $response);
        } catch (\Throwable $th) {
            Log::info($th->getMessage());
        }
    }
}

use Moktech\MockLoggerSDK\MockLogger;

$data = [
    "request" => [
        'user' => [
            'name' => 'Kevin Muchwat',
            'email' => '[email protected]',
        ],
        'ip_address' => $request->ip(),
        'full_url' => $request->fullUrl(),
        'route_name' => $request->route()->getName(),
        'method' => $request->method(),
        'payload' => $request->all(),
        'agent' => $request->userAgent(),
    ],
    "response" => [
        'status_code' => $response->getStatusCode(),
        'content' => $response->getContent(),
        'format' => $response->headers->get('content-type'),
        'location' => $response->headers->get('location'),
    ],
];

$logger = new MockLogger();
$logger->sendData($data);

return [
    ...
    // Configure server health monitor.
    'monitor' => [
        // Specify the web server service running, e.g., 'nginx' or 'apache2'.
        'server_service' => 'nginx',

        // Set email configuarations, default is 4 emails per 30mins interval.
        'email' => [
            // Set time interval to get emails (minutes), default is 30 minutes
            'interval' => 30,

            // Set number of emails to be sent in an interval, default is 4 emails.
            'count'  => 4,
        ],

        // Configure thresholds for resources.
        'thresholds' => [
            // Set the CPU usage threshold (percentage).
            'cpu_usage' => env('MOCKLOGGER_CPU_THRESHOLD', 90),

            // Set the memory usage threshold (percentage). 
            'memory_usage' => env('MOCKLOGGER_MEMORY_THRESHOLD', 80),

            // Set the hard disk drive usage threshold (percentage).
            'hard_disk_space' => env('MOCKLOGGER_HDD_THRESHOLD', 80),
        ],
    ],
]
bash
php artisan vendor:publish --tag=mocklogger-config
bash
php artisan mocklogger:monitor