1. Go to this page and download the library: Download dansol/monolog-extensions 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/ */
dansol / monolog-extensions example snippets
use MonologExtensions\Handler\PDOHandler;
use Monolog\Logger;
...
// PDO
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
//---------------------------------------------------------------------
// Logger Initialization
// *** example*** adapat tablename, dateformat, mapping to your needs
// tb_log ->([Date] [datetime] NULL,[Type] [nvarchar](50) NULL,[Event] [nvarchar](max) NULL,[UserName] [nvarchar](50) NULL)
$dbTableName="Tb_Logs";
// database date format
$databaseDateFormat="Y-m-d H:i:s";
// map log properties to database table fields
$mapping = [
'datetime' => 'date',
'level' => 'type',
'message' => 'event',
'context' => [
'username' => 'username' // custom fields/info
]
];
// monolog new pdo Handler
$pdoHandler= new PDOHandler($pdo,$dbTableName,$databaseDateFormat,$mapping);
$logger = new Logger('channel name');
$logger->pushHandler($pdoHandler, \Monolog\Logger::DEBUG );
//----------------------------------------------------------------
....
// write log example
$this->logger->info('successfully login for user ' . $identity ,['username'=>$identity]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.