Kotchasan Framework Documentation

Kotchasan Framework Documentation

Kotchasan\Logger\SystemLogger

TH 05 Feb 2026 07:40

Kotchasan\Logger\SystemLogger

SystemLogger เขียน log ไปยัง system log (syslog)

การใช้งาน

use Kotchasan\Logger\SystemLogger;

$logger = new SystemLogger('myapp');

$logger->info('Application started');
$logger->error('Critical error occurred');

Constructor

public function __construct(string $ident = 'kotchasan')

Parameters:

  • $ident - ชื่อ identifier สำหรับ syslog

เมื่อไหร่ควรใช้

  • Production servers
  • เมื่อต้องการ centralized logging
  • Integration กับ log management systems
  • Security และ audit logging

ตัวอย่าง

Production Logging

use Kotchasan\Logger\SystemLogger;

$logger = new SystemLogger('mywebapp');

// Log สำหรับ security events
$logger->warning('Failed login attempt', [
    'ip' => $_SERVER['REMOTE_ADDR'],
    'username' => $username
]);

// Critical errors
$logger->critical('Database connection lost');

ดู Logs

# Linux
tail -f /var/log/syslog | grep myapp

# macOS
log show --predicate 'process == "myapp"' --last 1h

คลาสที่เกี่ยวข้อง