ErrorLoggerTrait
trait ErrorLoggerTrait (View source)
Provides standardized and safe error logging with UTF-8 encoding, sensitive data masking, and controlled stack traces.
Methods
void
array
sanitizeSensitiveData(array $data)
Masks common sensitive fields (e.g., passwords, tokens) in the given context array.
array
encodeStringsUtf8(array $data)
Recursively converts all string values to UTF-8.
string
getLimitedTrace(Throwable $exception, int $maxLines = 10)
Returns a string representation of the exception trace, limited to the given number of lines.
Details
protected void
logError(string $message, Throwable $exception, array $context = [], string|null $channel = null)
Logs an error with consistent formatting and context.
protected array
sanitizeSensitiveData(array $data)
Masks common sensitive fields (e.g., passwords, tokens) in the given context array.
protected array
encodeStringsUtf8(array $data)
Recursively converts all string values to UTF-8.
protected string
getLimitedTrace(Throwable $exception, int $maxLines = 10)
Returns a string representation of the exception trace, limited to the given number of lines.