\Ite\LoggerPhpMailLogger

Sends log messages to email

This class uses php internal mail() function to sends log messages

Summary

Methods
Properties
Constants
__construct()
log()
getDefaultTo()
getDefaultEncoding()
getDefaultContentType()
getConfig()
setDefaultTo()
setDefaultEncoding()
setDefaultContentType()
setConfig()
setDateFormat()
getDateFormat()
No public properties found
No constants found
prepareEmailParts()
send()
parseException()
prepareContext()
prepareMessage()
$defaultTo
$defaultEncoding
$defaultContentType
$config
$dateFormat
N/A
No private methods found
No private properties found
N/A

Properties

$defaultTo

$defaultTo : string

The default receiver of emails

If in email config for a level the 'to' or 'from' element is missed this value will be used

Type

string

$defaultEncoding

$defaultEncoding : string

The default encoding

If in email config for a level the 'Content-Type' header is missed this value will be used for charset in conjuction with the $defaultContentType

Type

string

$defaultContentType

$defaultContentType : string

The default content type

If in email config for a level the Content-Type header is missed this value will be used in conjuction with the $defaultEncoding

Type

string

$config

$config : array

Email configs for log levels

The keys are the log levels and their values are array with the email parts - 'from', 'to', 'subject' and 'headers'

Type

array

$dateFormat

$dateFormat : string

The log date format

Type

string

Methods

__construct()

__construct(array|string  $config = null, string  $defaultTo = '') 

Abstract email logger class with the base methods for logging, parsing and preparing the email and log message for sending

Parameters

array|string $config

[Optional]

string $defaultTo

[Optional]

log()

log(string  $level, string  $message, array  $context = array()) 

Do the actual logging

Prepares the message body and email parts (from, to, headers, etc...) and calls the abstract send() method

Parameters

string $level
string $message
array $context

[Optional]

Throws

\Ite\Logger\InvalidArgumentException

getDefaultTo()

getDefaultTo() : string

Get default receiver email address

Returns

string

getDefaultEncoding()

getDefaultEncoding() : string

Get default mail encoding

Returns

string

getDefaultContentType()

getDefaultContentType() : string

Get defaul mail content type

Returns

string

getConfig()

getConfig() : array

Get logger config

Returns

array

setDefaultTo()

setDefaultTo(string  $defaultTo) : \Ite\Logger\AbstractEmailLogger

Sets default receiver email address

Parameters

string $defaultTo

Returns

\Ite\Logger\AbstractEmailLogger

setDefaultEncoding()

setDefaultEncoding(string  $defaultEncoding) : \Ite\Logger\AbstractEmailLogger

Sets default mail encoding

Parameters

string $defaultEncoding

Returns

\Ite\Logger\AbstractEmailLogger

setDefaultContentType()

setDefaultContentType(string  $defaultContentType) : \Ite\Logger\AbstractEmailLogger

sets default mail content type

Parameters

string $defaultContentType

Returns

\Ite\Logger\AbstractEmailLogger

setConfig()

setConfig(array  $config) : \Ite\Logger\AbstractEmailLogger

Sets logger config

Parameters

array $config

Returns

\Ite\Logger\AbstractEmailLogger

setDateFormat()

setDateFormat(string  $dateFormat) : self

Sets log date format

Parameters

string $dateFormat

Returns

self

getDateFormat()

getDateFormat() : string

Get log date format

Returns

string

prepareEmailParts()

prepareEmailParts(string  $level) : array

Prepares the email parts

Extracts the email config for the desired level and fills the missing parts with the defaults

Parameters

string $level

Throws

\Ite\Logger\Exception\RuntimeException

Returns

array

send()

send(string  $to, string  $subject, string  $message, array  $headers = array()) : boolean

Send email with log message via internal mail() function

Warning: This mehtod does NOT validate the email addresses

Parameters

string $to

The log receiver

string $subject

The email subject. Typicaly the log raw message

string $message

The prepared email message with datetime, context, etc...

array $headers

[Optional]

Returns

boolean

parseException()

parseException(\Trhowable|\Exception  $e) : array

Parameters

\Trhowable|\Exception $e

The exception to parse

Throws

\Ite\Logger\InvalidArgumentException

If the parameter is not exception or throwable object

Returns

array —

Parsed exception as an array

prepareContext()

prepareContext(array  $context) : string

Prepares context

Encodes context into json string

Parameters

array $context

Returns

string

prepareMessage()

prepareMessage(string  $message, array  $context = array()) : string

Prepares the log message for logging

This methods adds the current datetime to the message and the context if there is any. If there is an exception in the context it will be parsed to.

Parameters

string $message
array $context

Returns

string