Plop
A simple logging library for PHP
Plop\Formatter Class Reference

A class that provides basic formatting for log records. More...

+ Inheritance diagram for Plop\Formatter:

Public Member Functions

 __construct ($format=self::DEFAULT_FORMAT, $dateFormat=self::DEFAULT_DATE_FORMAT, $timezone=null, $pythonLike=false,\Plop\InterpolatorInterface $interpolator=null)
 
 format (\Plop\RecordInterface $record)
 
 getDateFormat ()
 
 getFormat ()
 
 getInterpolator ()
 
 getPythonLike ()
 
 getTimezone ()
 
 setDateFormat ($dateFormat)
 
 setFormat ($format)
 
 setInterpolator (\Plop\InterpolatorInterface $interpolator)
 
 setPythonLike ($pythonLike)
 
 setTimezone (\DateTimeZone $timezone=null)
 

Public Attributes

const DEFAULT_DATE_FORMAT = "Y-m-d H:i:s,u"
 Default format for dates.
 
const DEFAULT_FORMAT = '%(message)s'
 Default format for log messages.
 

Protected Member Functions

 formatException (\Exception $exception)
 
 formatTime (\Plop\RecordInterface $record, $dateFormat=self::DEFAULT_DATE_FORMAT)
 

Protected Attributes

 $dateFormat
 Format to use for dates/times.
 
 $format
 General format for log records.
 
 $interpolator
 Object to use for interpolation in the final log message.
 
 $pythonLike
 Whether formatException() generates Python-like traces.
 
 $timezone
 Timezone to use to represent dates/times.
 

Detailed Description

A class that provides basic formatting for log records.

Definition at line 28 of file Formatter.php.

Constructor & Destructor Documentation

Plop\Formatter::__construct (   $format = self::DEFAULT_FORMAT,
  $dateFormat = self::DEFAULT_DATE_FORMAT,
  $timezone = null,
  $pythonLike = false,
\Plop\InterpolatorInterface  $interpolator = null 
)

Construct a new formatter.

Parameters
string$format(optional) The format specification for log records, which may contain special formatting-sequences. Defaults to the value of the Plop::Formatter::DEFAULT_FORMAT constant.
string$dateFormat(optional) The format specification to use to format dates. The default is to use the value of the Plop::Formatter::DEFAULT_DATE_FORMAT constant.
DateTimeZone | string$timezone(optional) Timezone to use when formatting dates/times. This must be a valid timezone (see http://php.net/timezones.php). Defaults to using the default timezone, as returned by date_default_timezone_get().
bool$pythonLike(optional) Whether exceptions should be formatted to resemble Python stack traces (true) or if they should keep their original PHP format (false). Defaults to false (display PHP stack traces).
Plop::InterpolatorInterface$interpolator(optional) An object to use for message interpolation. The default is to create a new Plop::Interpolator::Percent instance. Hence, percent-style interpolation is available by default (see Plop::Interpolator::Percent::interpolate() for more information on percent-style interpolation).
See also
The documentation from the PHP manual on the date() function for a list of valid format specifiers for the $dateFormat parameter.

Definition at line 93 of file Formatter.php.

Member Function Documentation

Plop\Formatter::format ( \Plop\RecordInterface  $record)

Implements Plop\FormatterInterface.

Definition at line 203 of file Formatter.php.

Plop\Formatter::formatException ( \Exception  $exception)
protected

Format an exception.

Parameters
::Exception$exceptionThe exception to format.
Return values
stringThe full trace of the exception, with proper formatting or false if the current PHP settings prevent errors from being displayed.

Definition at line 265 of file Formatter.php.

Plop\Formatter::formatTime ( \Plop\RecordInterface  $record,
  $dateFormat = self::DEFAULT_DATE_FORMAT 
)
protected

Format the creation date of a log record.

Parameters
Plop::RecordInterface$recordThe log record whose creation date will be formatted.
string$dateFormat(optional) The format to apply. By default, Plop::Formatter::DEFAULT_DATE_FORMAT is used.
See also
The documentation from the PHP manual on the date() function for a list of valid format specifiers.

Definition at line 243 of file Formatter.php.

Plop\Formatter::getDateFormat ( )

Return the format used to render dates.

Return values
stringThe format used to render dates.

Implements Plop\FormatterInterface.

Definition at line 131 of file Formatter.php.

Plop\Formatter::getFormat ( )

Return the general format used to render records.

Return values
stringThe format used to render records.

Implements Plop\FormatterInterface.

Definition at line 118 of file Formatter.php.

Plop\Formatter::getPythonLike ( )

Return whether exceptions are rendered like Python stack traces or not.

Return values
booltrue if the exceptions will look like Python stack traces or false if they will look like regular PHP stack traces.

Implements Plop\FormatterInterface.

Definition at line 165 of file Formatter.php.

Plop\Formatter::getTimezone ( )

Return the timezone object used to format dates/times.

Return values
DateTimeZoneTimezone object used to format dates/times.
nullReturned when no particular timezone is used to format dates/times (ie. the local timezone is used).

Implements Plop\FormatterInterface.

Definition at line 144 of file Formatter.php.

Plop\Formatter::setDateFormat (   $dateFormat)

Implements Plop\FormatterInterface.

Definition at line 137 of file Formatter.php.

Plop\Formatter::setFormat (   $format)

Implements Plop\FormatterInterface.

Definition at line 124 of file Formatter.php.

Plop\Formatter::setPythonLike (   $pythonLike)

Set the format used to render exceptions.

Parameters
bool$pythonLikeIf this is true, exception stack traces will be rendered using a format close to the one Python uses. Otherwise, the original (PHP) format is kept.
Return values
Plop::FormatterInterfaceThe formatter instance (ie. $this).

Implements Plop\FormatterInterface.

Definition at line 182 of file Formatter.php.

Plop\Formatter::setTimezone ( \DateTimeZone  $timezone = null)

Implements Plop\FormatterInterface.

Definition at line 150 of file Formatter.php.


The documentation for this class was generated from the following file: