Protokoll
Webman verwendet monolog/monolog zur Verarbeitung von Protokollen.
Verwendung
<?php
namespace app\controller;
use support\Request;
use support\Log;
class FooController
{
public function index(Request $request)
{
Log::info('log test');
return response('hello index');
}
}
Verfügbare Methoden
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 = [])
Entspricht
$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 = [])
Konfiguration
return [
// Standard-Log-Kanal
'default' => [
// Handler für den Standardkanal, mehrere können gesetzt werden
'handlers' => [
[
// Name der Handler-Klasse
'class' => Monolog\Handler\RotatingFileHandler::class,
// Konstruktionsparameter der Handler-Klasse
'constructor' => [
runtime_path() . '/logs/webman.log',
Monolog\Logger::DEBUG,
],
// Formatbezogene Einstellungen
'formatter' => [
// Name der Formatierungs-Klasse
'class' => Monolog\Formatter\LineFormatter::class,
// Konstruktionsparameter der Formatierungs-Klasse
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
];
Mehrere Kanäle
Monolog unterstützt mehrere Kanäle, standardmäßig wird der default
-Kanal verwendet. Wenn Sie einen log2
-Kanal hinzufügen möchten, konfigurieren Sie es wie folgt:
return [
// Standard-Log-Kanal
'default' => [
// Handler für den Standardkanal, mehrere können gesetzt werden
'handlers' => [
[
// Name der Handler-Klasse
'class' => Monolog\Handler\RotatingFileHandler::class,
// Konstruktionsparameter der Handler-Klasse
'constructor' => [
runtime_path() . '/logs/webman.log',
Monolog\Logger::DEBUG,
],
// Formatbezogene Einstellungen
'formatter' => [
// Name der Formatierungs-Klasse
'class' => Monolog\Formatter\LineFormatter::class,
// Konstruktionsparameter der Formatierungs-Klasse
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
// log2-Kanal
'log2' => [
// Handler für den log2-Kanal, mehrere können gesetzt werden
'handlers' => [
[
// Name der Handler-Klasse
'class' => Monolog\Handler\RotatingFileHandler::class,
// Konstruktionsparameter der Handler-Klasse
'constructor' => [
runtime_path() . '/logs/log2.log',
Monolog\Logger::DEBUG,
],
// Formatbezogene Einstellungen
'formatter' => [
// Name der Formatierungs-Klasse
'class' => Monolog\Formatter\LineFormatter::class,
// Konstruktionsparameter der Formatierungs-Klasse
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
];
Verwendung des log2
-Kanals:
<?php
namespace app\controller;
use support\Request;
use support\Log;
class FooController
{
public function index(Request $request)
{
$log = Log::channel('log2');
$log->info('log2 test');
return response('hello index');
}
}