السجلات
يستخدم Webman monolog/monolog لمعالجة السجلات.
الاستخدام
<?php
namespace app\controller;
use support\Request;
use support\Log;
class FooController
{
public function index(Request $request)
{
Log::info('اختبار السجل');
return response('مرحبا بالصفحة الرئيسية');
}
}
الطرق المتاحة
Log::log($level, $message, array $context = [])
Log::debug($message, array $context = [])
Log::info($message, array $context = [])
Log::notice($message, array $context = [])
Log::warning($message, array $context = [])
Log::error($message, array $context = [])
Log::critical($message, array $context = [])
Log::alert($message, array $context = [])
Log::emergency($message, array $context = [])
يعادل
$log = Log::channel('default');
$log->log($level, $message, array $context = [])
$log->debug($message, array $context = [])
$log->info($message, array $context = [])
$log->notice($message, array $context = [])
$log->warning($message, array $context = [])
$log->error($message, array $context = [])
$log->critical($message, array $context = [])
$log->alert($message, array $context = [])
$log->emergency($message, array $context = [])
التكوين
return [
// قناة السجل الافتراضية
'default' => [
// معالجة Handlers لقناة السجل الافتراضية، يمكن تعيين أكثر من واحد
'handlers' => [
[
// اسم فئة المعالج
'class' => Monolog\Handler\RotatingFileHandler::class,
// معلمات البناء لفئة المعالج
'constructor' => [
runtime_path() . '/logs/webman.log',
Monolog\Logger::DEBUG,
],
// القضايا المتعلقة بالتنسيق
'formatter' => [
// اسم فئة التنسيق
'class' => Monolog\Formatter\LineFormatter::class,
// معلمات البناء لفئة التنسيق
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
];
القنوات المتعددة
يدعم Monolog القنوات المتعددة، والقناة الافتراضية هي default
. إذا كنت ترغب في إضافة قناة log2
، فإن التكوين سيكون كما يلي:
return [
// قناة السجل الافتراضية
'default' => [
// معالجة Handlers لقناة السجل الافتراضية، يمكن تعيين أكثر من واحد
'handlers' => [
[
// اسم فئة المعالج
'class' => Monolog\Handler\RotatingFileHandler::class,
// معلمات البناء لفئة المعالج
'constructor' => [
runtime_path() . '/logs/webman.log',
Monolog\Logger::DEBUG,
],
// القضايا المتعلقة بالتنسيق
'formatter' => [
// اسم فئة التنسيق
'class' => Monolog\Formatter\LineFormatter::class,
// معلمات البناء لفئة التنسيق
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
// قناة log2
'log2' => [
// معالجة Handlers لقناة السجل الافتراضية، يمكن تعيين أكثر من واحد
'handlers' => [
[
// اسم فئة المعالج
'class' => Monolog\Handler\RotatingFileHandler::class,
// معلمات البناء لفئة المعالج
'constructor' => [
runtime_path() . '/logs/log2.log',
Monolog\Logger::DEBUG,
],
// القضايا المتعلقة بالتنسيق
'formatter' => [
// اسم فئة التنسيق
'class' => Monolog\Formatter\LineFormatter::class,
// معلمات البناء لفئة التنسيق
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
];
استخدام قناة log2
سيكون كما يلي:
<?php
namespace app\controller;
use support\Request;
use support\Log;
class FooController
{
public function index(Request $request)
{
$log = Log::channel('log2');
$log->info('اختبار log2');
return response('مرحبا بالصفحة الرئيسية');
}
}