PHP code example of danielme85 / laravel-log-to-db
1. Go to this page and download the library: Download danielme85/laravel-log-to-db 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/ */
Log::debug("This is an test DEBUG log event");
Log::info("This is an test INFO log event");
Log::notice("This is an test NOTICE log event");
Log::warning("This is an test WARNING log event");
Log::error("This is an test ERROR log event");
Log::critical("This is an test CRITICAL log event");
Log::alert("This is an test ALERT log event");
Log::emergency("This is an test EMERGENCY log event");
$model = LogToDB::model();
$model->get(); //All logs for default channel/connection
$logsFromDefault = LogDB::model()->get(); //Get the logs from the default log channel and default connection.
$logsFromChannel = LogDB::model('database')->get(); //Get logs from the 'database' log channel.
$logsFromChannel = LogDB::model('customname')->get(); //Get logs from the 'customname' log channel.
$logsFromMysql = LogToDB::model(null, 'mysql')->get(); //Get all logs from the mysql connection (from Laravel database config)
$logsFromMongoDB = LogToDB::model(null, 'mongodb')->get(); //Get all logs from the mongodb connection (from Laravel database config)
$logsFromMysqlTable = LogToDB::model(null, 'mysql', 'table')->get(); //Get all logs from the mysql table: 'table'
namespace App\Models;
use danielme85\LaravelLogToDB\Models\LogToDbCreateObject;
use Illuminate\Database\Eloquent\Model;
class CustomLog extends Model
{
use LogToDbCreateObject;
protected $table = 'log';
protected $connection = 'mysql';
}
namespace App\Models;
use danielme85\LaravelLogToDB\Models\LogToDbCreateObject;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class CustomLogMongo extends Eloquent
{
use LogToDbCreateObject;
protected $collection = 'log';
protected $connection = 'mongodb';
}
namespace App\CustomProcessors;
use Monolog\Processor\ProcessorInterface;
class PhpVersionProcessor implements ProcessorInterface {
/**
* @return array The processed record
*/
public function __invoke(array $record) {
$record['extra']['php_version'] = phpversion();
return $record;
}
}