PHP code example of district5 / mondoc-log-handler
1. Go to this page and download the library: Download district5/mondoc-log-handler 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/ */
district5 / mondoc-log-handler example snippets
use District5\MondocLogHandler\Handler\MondocLogHandler;
use District5\MondocLogHandler\MondocLogConfig;
use Monolog\Level;
use Monolog\Logger;
// Set up MondocConfig
$client = new \MongoDB\Client('mongodb://localhost:27017');
\District5\Mondoc\MondocConfig::getInstance()->addDatabase(
$client->selectDatabase('my_database'),
'default' // This is the default connection id
)
// Set up MondocLogConfig
$config = MondocLogConfig::getInstance()->setConnectionId(
'default' // This is the default connection id
)->setCollectionName(
'mondoc_log' // This is the default collection name
);
// Set up the logger
$logger = new Logger('my_app');
$handler = new MondocLogHandler(
$level = Level::Debug,
$bubble = true
);
$handler->setFormatter(
new LineFormatter('%message%') // This is the default formatter and format
);
$logger->pushHandler($handler);
$logger->info('A test log from MondocLogHandler');
$lastLogModel = $handler->getLastLog();
echo $lastLogModel->getMessage(); // 'A test log from MondocLogHandler'