PHP code example of myoperator / centrallog

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

    

myoperator / centrallog example snippets


   

  use \MyOperator\CentralLog;

  CentralLog::configure('mylog.log'); //logs.log refers to log output file

  $log = CentralLog::getLogger('myLogger');
  $log->log("Something");


use \MyOperator\CentralLog;

CentralLog::configure("mylog.log");

$log = CentralLog::getLogger('myLogger');
$log->log("Something");

//Or you can also provide the title
$log->withTitle("Making curl request")->log("curl response");

  CentralLog::configure(string  $outputpath = null, string  $server = null, string|\MyOperator\class  $class = null, string  $pattern = null, string  $maxsize = null)

string	$outputpath	Output path of the log file

string	$server	Server on which the application is running. Ex- S6, API01

string	$class	Class name under which the logger is being used

string	$pattern	logger pattern as described in https://logging.apache.org/log4php/docs/layouts/pattern.html

string	$maxsize	Maximum size per log

   CentralLog::log(mixed  $message, string  $uid = null,  integer  $acl = null, string $loglevel="info")

mixed	$message	Item to be logged

string	$uid	The unique id of item. In case of sync script, this can be engine uid. (optional)

integer	$acl	The ACL to be used to log the item. (optional). Can be one of [1,2,4]

string	$loglevel The loglevel to use for the log. defaults to `info`. (optional)

  $logger->withTitle($title)->log($message, $uid, $acl);
  //This is same as above
  $logger->title($title)->log($message, $uid, $acl);

   $logger->slog(mixed  $message, string  $uid = null, string  $level = null)

   $logger->clog(mixed  $message, string  $uid = null, string  $level = null)

   $logger->dlog(mixed  $message, string  $uid = null, string  $level = null);

   $message = array(
                  'dmsg' => 'Your developer log here',
                  'smsg' => 'Your support log here',
                  'cmsg' => 'Your customer log here'
              );

    try{
      throw new \Exception("Application error....", 400);
    } catch (\Exception $e) {
      $log->log(['dmsg' => $e, 'cmsg' => 'Some error occured', 'smsg' => $e->getMessage()]);
    }