Overview

Namespaces

  • None
  • VSP
    • Core
      • Abstracts
      • Interfaces
      • Traits
        • WC_Compatibility
    • Deprecation
    • Helper
    • Modules
      • Addons
      • Logger

Classes

  • File_Handler
  • Levels
  • Overview
  • Namespace
  • Class

Class File_Handler

Class VSP_Log_Handler_File

VSP\Core\Abstracts\Log_Handler implements VSP\Core\Interfaces\Log_Handler
Extended by VSP\Modules\Logger\File_Handler
Namespace: VSP\Modules\Logger
Author: Varun Sridharan varunsridharan23@gmail.com
Located at includes/modules/logger/class-file-handler.php
Methods summary
public
# __construct( boolean $sub_path = false, string|boolean|null $file_name = null, integer $log_size_limit = null )

VSP_Log_Handler_File constructor.

VSP_Log_Handler_File constructor.

Parameters

$sub_path
$file_name
$log_size_limit
Optional. Size limit for log files. Default 5mb.
public
# __destruct( )

Destructor.

Destructor.

Cleans up open file handles.

public boolean
# handle( integer $timestamp, string $level, string $message, array $context )

Handle a log entry.

Handle a log entry.

Parameters

$timestamp
Log timestamp.
$level
emergency|alert|critical|error|warning|notice|info|debug.
$message
Log message.
$context

{ Additional information for log handlers.

Returns

boolean
False if value was not handled and true if value was handled.

Type

string $source Optional. Determines log file to write to. Default 'log'.

bool $_legacy Optional. Default false. True to use outdated log format originally used in deprecated VSP_Logger::add calls. }


protected static string
# format_entry( integer $timestamp, string $level, string $message, array $context )

Builds a log entry text from timestamp, level and message.

Builds a log entry text from timestamp, level and message.

Parameters

$timestamp
Log timestamp.
$level
emergency|alert|critical|error|warning|notice|info|debug.
$message
Log message.
$context
Additional information for log handlers.

Returns

string
Formatted log entry.

Overrides

VSP\Core\Abstracts\Log_Handler::format_entry()
protected boolean
# add( string $entry, string $handle )

Add a log entry to chosen file.

Add a log entry to chosen file.

Parameters

$entry
Log entry text.
$handle
Log entry handle.

Returns

boolean
True if write was successful.
protected boolean
# should_rotate( string $handle )

Check if log file should be rotated.

Check if log file should be rotated.

Compares the size of the log file to determine whether it is over the size limit.

Parameters

$handle
Log handle.

Returns

boolean
True if if should be rotated.
public boolean|string
# get_log_file_path( string $handle )

Get a log file path.

Get a log file path.

Parameters

$handle
Log name.

Returns

boolean|string
The log file path or false if path cannot be determined.
public boolean|string
# get_log_file_name( string $handle )

Get a log file name.

Get a log file name.

Parameters

$handle
Log name.

Returns

boolean|string
The log file name or false if cannot be determined.
protected boolean
# is_open( string $handle )

Check if a handle is open.

Check if a handle is open.

Parameters

$handle
Log handle.

Returns

boolean
True if $handle is open.
protected
# log_rotate( string $handle )

Rotate log files.

Rotate log files.

Logs are rotated by prepending '.x' to the '.log' suffix. The current log plus 10 historical logs are maintained. For example: base.9.log -> [ REMOVED ] base.8.log -> base.9.log ... base.0.log -> base.1.log base.log -> base.0.log

Parameters

$handle
Log handle.
protected boolean
# increment_log_infix( string $handle, null|integer $number = null )

Increment a log file suffix.

Increment a log file suffix.

Parameters

$handle
Log handle.
$number
Optional. Default null. Log suffix number to be incremented.

Returns

boolean
True if increment was successful, otherwise false.
protected boolean
# close( string $handle )

Close a handle.

Close a handle.

Parameters

$handle
Log handle.

Returns

boolean
success
protected boolean
# open( string $handle, string $mode = 'a' )

Open log file for writing.

Open log file for writing.

Parameters

$handle
Log handle.
$mode
Optional. File mode. Default 'a'.

Returns

boolean
Success.
protected
# cache_log( string $entry, string $handle )

Cache log to write later.

Cache log to write later.

Parameters

$entry
Log entry text.
$handle
Log entry handle.
public boolean
# clear( string $handle )

Clear entries from chosen file.

Clear entries from chosen file.

Parameters

$handle
Log handle.

Returns

boolean
public boolean
# remove( string $handle )

Remove/delete the chosen file.

Remove/delete the chosen file.

Parameters

$handle
Log handle.

Returns

boolean
public
# write_cached_logs( )

Write cached logs.

Write cached logs.

Methods inherited from VSP\Core\Abstracts\Log_Handler
format_time()
Properties summary
protected boolean $sub_path

sub_path

sub_path

# false
protected array $handles

Stores open file handles.

Stores open file handles.

# array()
protected integer $log_size_limit

File size limit for log files in bytes.

File size limit for log files in bytes.

#
protected array $cached_logs

Cache logs that could not be written.

Cache logs that could not be written.

If a log is written too early in the request, pluggable functions may be unavailable. These logs will be cached and written on 'plugins_loaded' action.

# array()
protected null $file_name
# null
API documentation generated by ApiGen