Documentation

File extends AbstractWriter
in package

File log writer class

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

$file  : string|null
Log file
$formatter  : FormatterInterface|null
Formatter, null only when using the legacy xml/json whole-file-rewrite handling
$limit  : string|null
Log limit, stored as the canonical PSR-3 level string
$type  : string|null
Log file type

Methods

__construct()  : mixed
Constructor
getContext()  : string
Get context for log
getFile()  : string
Get file
getFormatter()  : FormatterInterface|null
Get formatter
getLogLimit()  : string|null
Get log limit
getType()  : string|null
Get type
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()  : File
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).
withExclusiveLock()  : void
Run a read-modify-write cycle against the log file under an exclusive lock, to prevent two concurrent writers from racing on file_get_contents()/file_put_contents() and silently losing one writer's entry. $transform receives the file's current content and must return the new content to write back.

Properties

$file

Log file

protected string|null $file = null

$formatter

Formatter, null only when using the legacy xml/json whole-file-rewrite handling

protected FormatterInterface|null $formatter = null

$limit

Log limit, stored as the canonical PSR-3 level string

protected string|null $limit = null

$type

Log file type

protected string|null $type = null

Methods

__construct()

Constructor

public __construct(string $file[, FormatterInterface|null $formatter = null ]) : mixed

Instantiate the file writer object

Parameters
$file : string
$formatter : FormatterInterface|null = null

getContext()

Get context for log

public getContext([array<string|int, mixed> $context = [] ]) : string
Parameters
$context : array<string|int, mixed> = []
Return values
string

getFile()

Get file

public getFile() : string
Return values
string

getLogLimit()

Get log limit

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

getType()

Get type

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

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 = [] ]) : File
Parameters
$level : string
$message : string
$context : array<string|int, mixed> = []
Return values
File

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

withExclusiveLock()

Run a read-modify-write cycle against the log file under an exclusive lock, to prevent two concurrent writers from racing on file_get_contents()/file_put_contents() and silently losing one writer's entry. $transform receives the file's current content and must return the new content to write back.

protected withExclusiveLock(callable $transform) : void
Parameters
$transform : callable
Tags
throws
Exception

        
On this page

Search results