public class Log

class.log.php #12

The Log class acts a simple wrapper to write errors to a file so that it can be read at a later date. There is one Log file in Symphony, stored in the main LOGS directory.

Constants

public static
class.log.php #18
static integer APPEND = 10

A constant for if this message should add to an existing log file

public static
class.log.php #24
static integer OVERWRITE = 11

A constant for if this message should overwrite the existing log

Methods

void __construct(string $path)

The log constructor takes a path to the folder where the Log should be written to.

Parameters
  • $path stringThe path to the folder where the Log files should be written

void close()

Writes a end of file block at the end of the log file with a datetime stamp of when the log file was closed.

array getLog()

Accessor for the $_log.

string getLogPath()

Accessor for the $_log_path.

void initialise(mixed $name)
integer open(integer $flag, integer $mode)

The function handles the rotation of the log files. By default it will open the current log file, 'main', which is written to $_log_path and check it's file size doesn't exceed $_max_size. If it does, the log is appended with a date stamp and if $_archive has been set, it will be archived and stored. If a log file has exceeded it's size, or Log::OVERWRITE flag is set, the existing log file is removed and a new one created. Essentially, if a log file has not reached it's $_max_size and the the flag is not set to Log::OVERWRITE, this function does nothing.

Parameters
  • $flag integerOne of the Log constants, either Log::APPEND or Log::OVERWRITE By default this is Log::APPEND

  • $mode integerThe file mode used to apply to the archived log, by default this is 0777. Note that this parameter is modified using PHP's intval function with base 8.

Returns

Returns 1 if the log was overwritten, or 2 otherwise.

See Also
array|boolean popFromLog()

Function will return the last message added to $_log and remove it from the array.

Returns

Returns an associative array of a log message, containing the type of the log message, the actual message and the time at the which it was added to the log. If the log is empty, this function removes false.

boolean|null pushDeprecateWarningToLog(string $method, string $alternative, array $opts, string $opts.message-format, string $opts.alternative-format, string $opts.removal-format, string $opts.removal-version, boolean $opts.write-to-log, boolean $opts.addbreak, boolean $opts.append, boolean $opts.addtrace)

Given an method name, this function will properly format a message and pass it down to pushToLog()

Parameters
  • $method stringThe name of the deprecated call

  • $alternative stringThe name of the new method to use

  • $opts array(optional)

  • $opts.message-format stringThe sprintf format to apply to $method

  • $opts.alternative-format stringThe sprintf format to apply to $alternative

  • $opts.removal-format stringThe sprintf format to apply to $opts.removal-version

  • $opts.removal-version stringThe Symphony version at which the removal is planned

  • $opts.write-to-log booleanIf set to true, this message will be immediately written to the log. By default this is set to false, which means that it will only be added to the array ready for writing

  • $opts.addbreak booleanTo be used in conjunction with $opts.write-to-log, this will add a line break before writing this message in the log file. Defaults to true.

  • $opts.append booleanIf set to true, the given $message will be append to the previous log message found in the $_log array

  • $opts.addtrace booleanIf set to true, the caller of the function will be added. Defaults to true.

Returns

If $writeToLog is passed, this function will return boolean, otherwise void

See Also
boolean|null pushExceptionToLog(Throwable $exception, boolean $writeToLog, boolean $addbreak, boolean $append)

Given an Throwable, this function will add it to the internal $_log so that it can be written to the Log.

Parameters
  • $writeToLog booleanIf set to true, this message will be immediately written to the log. By default this is set to false, which means that it will only be added to the array ready for writing

  • $addbreak booleanTo be used in conjunction with $writeToLog, this will add a line break before writing this message in the log file. Defaults to true.

  • $append booleanIf set to true, the given $message will be append to the previous log message found in the $_log array

Returns

If $writeToLog is passed, this function will return boolean, otherwise void

boolean|null pushToLog(string $message, integer $type, boolean $writeToLog, boolean $addbreak, boolean $append)

Given a message, this function will add it to the internal $_log so that it can be written to the Log. Optional parameters all the message to be immediately written, insert line breaks or add to the last log message

Parameters
  • $message stringThe message to add to the Log

  • $type integerA PHP error constant for this message, defaults to ENOTICE. If null or 0, will be converted to EERROR.

  • $writeToLog booleanIf set to true, this message will be immediately written to the log. By default this is set to false, which means that it will only be added to the array ready for writing

  • $addbreak booleanTo be used in conjunction with $writeToLog, this will add a line break before writing this message in the log file. Defaults to true.

  • $append booleanIf set to true, the given $message will be append to the previous log message found in the $_log array

Returns

If $writeToLog is passed, this function will return boolean, otherwise void

void setArchive(boolean $archive)

Setter for the $_archive.

Parameters
  • $archive booleanIf true, Log files will be archived using gz when they are rotated, otherwise they will just be overwritten when they are due for rotation

void setDateTimeFormat(string $format)

Setter for the $_date_format.

Parameters
  • $format stringTakes a valid date format using the PHP date tokens

See Also
void setFilter(mixed $filter)

Setter for the $_filter.

Parameters
  • $filter mixedThe filter used on log $type parameter.

void setLogPath(string $path)

Setter for the $_log_path.

Parameters
  • $path stringThe path to the folder where the Log files should be written

void setMaxSize(integer $size)

Setter for the $_max_size.

Parameters
  • $size integerThe size, in bytes, that the Log can reach before it is rotated.

boolean writeToLog(string $message, boolean $addbreak)

This function will write the given message to the log file. Messages will be appended the existing log file.

Parameters
  • $message stringThe message to add to the Log

  • $addbreak booleanTo be used in conjunction with $writeToLog, this will add a line break before writing this message in the log file. Defaults to true.

Returns

Returns true if the message was written successfully, false otherwise

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details