Documentation

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
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

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

$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

$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
throws
Exception

__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
string

getHostname()

Get hostname

public getHostname() : string
Return values
string

getLogLimit()

Get log limit

public getLogLimit() : string|null
Return values
string|null

getTag()

Get tag

public getTag() : string
Return values
string

hasLogLimit()

Has log limit

public hasLogLimit() : bool
Return values
bool

isWithinLogLimit()

Check if a log level is within the set log level limit

public isWithinLogLimit(string|int $level) : bool
Parameters
$level : string|int
Return values
bool

setLogLimit()

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
AbstractWriter

writeLog()

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
Syslog

sanitize()

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
Return values
string

        
On this page

Search results