PHP code example of oasis / logging

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

    

oasis / logging example snippets




// quick logging methods as global functions
mdebug("This is a debug message");
minfo("This is a info-level log message");
mnotice("Notice is also available");
mwarning("WARNING: something is possibly wrong!");
merror("ERROR: something is definitely wrong!");
mcritical("This is CRITICAL!");
malert("ALERT! ALERT!");
memergency("URGENT!");

// sprintf compatible logging
$name = 'test';
mdebug("The object %s is being processed", $name);




use Monolog\Logger as MonoLogger;
use Oasis\Mlib\Logging\MLogging;

/** @var MonoLogger $logger */
$logger = MLogging::getLogger();

// the $logger object can then be injected into any place in need of a MonoLogger




use Oasis\Mlib\Logging\ConsoleHandler;
use Oasis\Mlib\Logging\LocalFileHandler;
use Oasis\Mlib\Logging\MLogging;

MLogging::addHandler(new ConsoleHandler());

// or

(new LocalFileHandler())->install();



use Oasis\Mlib\Logging\LocalFileHandler;

$lfh = new LocalFileHandler('/my-log-path', '%date%/%hour%-%minute%-%script%.log');

// This tells the filename to rotate every 30 minutes
$lfh->setRefreshRate(1800);




use Oasis\Mlib\Logging\AwsSnsHandler;
use Oasis\Mlib\AwsWrappers\SnsPublisher;

/** @var string $the_topic_arn      the topic's AWS Resource Name */
/** @var array $some_aws_config     config data to initialize an Sns Publisher */
$publisher = new SnsPublisher($some_aws_config, $the_topic_arn);

$snsHandler = new AwsSnsHandler($publisher, 'This is the subject');
$snsHandler->enableAutoPublishingOnFatalError();
$snsHandler->install();