Syslog
extends AbstractWriter
in package
Syslog log writer class
Builds a real RFC-3164 packet (<PRI>HEADER TAG: MSG) and sends it over UDP to a syslog daemon/collector. Does not use Logger's configurable timestampFormat — RFC-3164 mandates an exact HEADER timestamp shape, generated independently on every write.
Tags
Table of Contents
Properties
- $facility : Facility
- $host : string
- $hostname : string
- Hostname written into the syslog HEADER
- $includePid : bool
- $limit : string|null
- Log limit, stored as the canonical PSR-3 level string
- $port : int
- $socket : mixed
- UDP socket resource
- $tag : string
- Tag (program identifier) written into the syslog TAG field
Methods
- __construct() : mixed
- Constructor
- __destruct() : mixed
- Destructor
- getContext() : string
- Get context for log
- getFacility() : Facility
- Get facility
- getHostname() : string
- Get hostname
- getLogLimit() : string|null
- Get log limit
- getTag() : string
- Get tag
- hasLogLimit() : bool
- Has log limit
- isWithinLogLimit() : bool
- Check if a log level is within the set log level limit
- setLogLimit() : AbstractWriter
- Set log limit
- writeLog() : Syslog
- Write to the log
- sanitize() : string
- Strip CR/LF from a value before it's written into a delimited/line-based log format, to prevent an embedded newline from forging a fake extra line (or, for writers that build header-style text like Mail's Subject line, a fake extra header).
Properties
$facility
protected
Facility
$facility
= Facility::USER
$host
protected
string
$host
= '127.0.0.1'
$hostname
Hostname written into the syslog HEADER
protected
string
$hostname
$includePid
protected
bool
$includePid
= true
$limit
Log limit, stored as the canonical PSR-3 level string
protected
string|null
$limit
= null
$port
protected
int
$port
= 514
$socket
UDP socket resource
protected
mixed
$socket
= null
$tag
Tag (program identifier) written into the syslog TAG field
protected
string
$tag
Methods
__construct()
Constructor
public
__construct([Facility $facility = Facility::USER ][, string $host = '127.0.0.1' ][, int $port = 514 ][, string|null $tag = null ][, string|null $hostname = null ][, bool $includePid = true ]) : mixed
Instantiate the syslog writer object
Parameters
- $facility : Facility = Facility::USER
- $host : string = '127.0.0.1'
- $port : int = 514
- $tag : string|null = null
- $hostname : string|null = null
- $includePid : bool = true
Tags
__destruct()
Destructor
public
__destruct() : mixed
getContext()
Get context for log
public
getContext([array<string|int, mixed> $context = [] ]) : string
Parameters
- $context : array<string|int, mixed> = []
Return values
stringgetFacility()
Get facility
public
getFacility() : Facility
Return values
FacilitygetHostname()
Get hostname
public
getHostname() : string
Return values
stringgetLogLimit()
Get log limit
public
getLogLimit() : string|null
Return values
string|nullgetTag()
Get tag
public
getTag() : string
Return values
stringhasLogLimit()
Has log limit
public
hasLogLimit() : bool
Return values
boolisWithinLogLimit()
Check if a log level is within the set log level limit
public
isWithinLogLimit(string|int $level) : bool
Parameters
- $level : string|int
Return values
boolsetLogLimit()
Set log limit
public
setLogLimit(string|int $level) : AbstractWriter
Accepts either a PSR-3 level string or a legacy severity int (0-7) for backward compatibility; always normalized and stored as the canonical PSR-3 string.
Parameters
- $level : string|int
Return values
AbstractWriterwriteLog()
Write to the log
public
writeLog(string $level, string $message[, array<string|int, mixed> $context = [] ]) : Syslog
Parameters
- $level : string
- $message : string
- $context : array<string|int, mixed> = []
Return values
Syslogsanitize()
Strip CR/LF from a value before it's written into a delimited/line-based log format, to prevent an embedded newline from forging a fake extra line (or, for writers that build header-style text like Mail's Subject line, a fake extra header).
protected
sanitize(string $value) : string
Parameters
- $value : string