ImportLogWriter
in package
Row log of the import: a **jsonl** file in `privateDir`, one JSON object per row: `{phase, line, code, action, level, message, key?, value?}`.
Why a file and not a table: the design deliberately creates no row table in the DB; the job holds only counts and the detail is in the file. jsonl can be read and written line by line, so even a million-row log never sits whole in memory (written here, read by ImportLogReader).
Writing is streamed (the handle is held for the whole run); file_put_contents(FILE_APPEND) per
item would mean an open and close for every row.
Table of Contents
Constants
- LEVEL_ERROR : string = 'error'
- LEVEL_INFO : string = 'info'
- LEVEL_WARNING : string = 'warning'
- PHASE_EXECUTE : string = 'execute'
- PHASE_VALIDATE : string = 'validate'
Properties
- $absolutePath : string
- $append : bool
- $errorCount : int
- $handle : resource|null
- $infoCount : int
- $phase : string
- $warningCount : int
Methods
- __construct() : mixed
- close() : void
- Closes the handle. When no row was written during the whole run, an empty file is still created, so the admin report can tell "run finished without rows" from "log does not exist".
- error() : void
- Hard error: the item is not written at all.
- getErrorCount() : int
- getInfoCount() : int
- getWarningCount() : int
- info() : void
- warning() : void
- Soft error: the item is written without the problematic part and marked `importIncomplete`.
- getHandle() : resource
- write() : void
Constants
LEVEL_ERROR
public
string
LEVEL_ERROR
= 'error'
LEVEL_INFO
public
string
LEVEL_INFO
= 'info'
LEVEL_WARNING
public
string
LEVEL_WARNING
= 'warning'
PHASE_EXECUTE
public
string
PHASE_EXECUTE
= 'execute'
PHASE_VALIDATE
public
string
PHASE_VALIDATE
= 'validate'
Properties
$absolutePath read-only
private
string
$absolutePath
$append read-only
private
bool
$append
= false
$errorCount
private
int
$errorCount
= 0
$handle
private
resource|null
$handle
= null
$infoCount
private
int
$infoCount
= 0
$phase read-only
private
string
$phase
= self::PHASE_VALIDATE
$warningCount
private
int
$warningCount
= 0
Methods
__construct()
public
__construct(string $absolutePath[, string $phase = self::PHASE_VALIDATE ][, bool $append = false ]) : mixed
Parameters
- $absolutePath : string
- $phase : string = self::PHASE_VALIDATE
- $append : bool = false
-
trueappends rows to the end of an existing log (self-heal adds "run interrupted" to the log of a crashed run); by default the log is overwritten (new run).
close()
Closes the handle. When no row was written during the whole run, an empty file is still created, so the admin report can tell "run finished without rows" from "log does not exist".
public
close() : void
error()
Hard error: the item is not written at all.
public
error(int $line, string|null $code, string|null $action, string $message[, string|null $key = null ][, string|null $value = null ]) : void
Parameters
- $line : int
- $code : string|null
- $action : string|null
- $message : string
- $key : string|null = null
- $value : string|null = null
getErrorCount()
public
getErrorCount() : int
Return values
intgetInfoCount()
public
getInfoCount() : int
Return values
intgetWarningCount()
public
getWarningCount() : int
Return values
intinfo()
public
info(int $line, string|null $code, string|null $action, string $message[, string|null $key = null ][, string|null $value = null ]) : void
Parameters
- $line : int
- $code : string|null
- $action : string|null
- $message : string
- $key : string|null = null
- $value : string|null = null
warning()
Soft error: the item is written without the problematic part and marked `importIncomplete`.
public
warning(int $line, string|null $code, string|null $action, string $message[, string|null $key = null ][, string|null $value = null ]) : void
$value is the attempted value from the file; without it the admin would not know what to fix
in the file.
Parameters
- $line : int
- $code : string|null
- $action : string|null
- $message : string
- $key : string|null = null
- $value : string|null = null
getHandle()
private
getHandle() : resource
Return values
resourcewrite()
private
write(string $level, int $line, string|null $code, string|null $action, string $message, string|null $key, string|null $value) : void
Parameters
- $level : string
- $line : int
- $code : string|null
- $action : string|null
- $message : string
- $key : string|null
- $value : string|null