Properties

$level

$level : 

Type

$bubble

$bubble : 

Type

$processors

$processors : 

Type

$connectionString

$connectionString : 

Type

$connectionTimeout

$connectionTimeout : 

Type

$resource

$resource : 

Type

$timeout

$timeout : 

Type

$writingTimeout

$writingTimeout : 

Type

$lastSentBytes

$lastSentBytes : 

Type

$persistent

$persistent : 

Type

$errno

$errno : 

Type

$errstr

$errstr : 

Type

$lastWritingAt

$lastWritingAt : 

Type

$token

$token : string

Slack API token

Type

string

$slackRecord

$slackRecord : \Monolog\Handler\Slack\SlackRecord

Instance of the SlackRecord util class preparing data for Slack API.

Type

\Monolog\Handler\Slack\SlackRecord

Methods

__construct()

__construct(string  $token, string  $channel, string|null  $username = null, boolean  $useAttachment = true, string|null  $iconEmoji = null, integer  $level = \Monolog\Logger::CRITICAL, boolean  $bubble = true, boolean  $useShortAttachment = false, boolean  $includeContextAndExtra = false, array  $excludeFields = array()) 

Parameters

string $token

Slack API token

string $channel

Slack channel (encoded ID or name)

string|null $username

Name of a bot

boolean $useAttachment

Whether the message should be added to Slack as attachment (plain text otherwise)

string|null $iconEmoji

The emoji name to use (or null)

integer $level

The minimum logging level at which this handler will be triggered

boolean $bubble

Whether the messages that are handled can bubble up the stack or not

boolean $useShortAttachment

Whether the the context/extra messages added to Slack as attachments are in a short style

boolean $includeContextAndExtra

Whether the attachment should include context and extra data

array $excludeFields

Dot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']

Throws

\Monolog\Handler\MissingExtensionException

If no OpenSSL PHP extension configured

close()

close() 

Closes the handler.

This will be called automatically when the object is destroyed

closeSocket()

closeSocket() 

Close socket, if open

setPersistent()

setPersistent(boolean  $persistent) 

Set socket connection to nbe persistent. It only has effect before the connection is initiated.

Parameters

boolean $persistent

setConnectionTimeout()

setConnectionTimeout(float  $seconds) 

Set connection timeout. Only has effect before we connect.

Parameters

float $seconds

setTimeout()

setTimeout(float  $seconds) 

Set write timeout. Only has effect before we connect.

Parameters

float $seconds

setWritingTimeout()

setWritingTimeout(float  $seconds) 

Set writing timeout. Only has effect during connection in the writing cycle.

Parameters

float $seconds

0 for no timeout

getConnectionString()

getConnectionString() : string

Get current connection string

Returns

string

isPersistent()

isPersistent() : boolean

Get persistent setting

Returns

boolean

getConnectionTimeout()

getConnectionTimeout() : float

Get current connection timeout setting

Returns

float

getTimeout()

getTimeout() : float

Get current in-transfer timeout

Returns

float

getWritingTimeout()

getWritingTimeout() : float

Get current local writing timeout

Returns

float

isConnected()

isConnected() : boolean

Check to see if the socket is currently available.

UDP might appear to be connected but might fail when writing. See http://php.net/fsockopen for details.

Returns

boolean

handle()

handle(array  $record) 

{@inheritdoc}

Parameters

array $record

isHandling()

isHandling(array  $record) : Boolean

Checks whether the given record will be handled by this handler.

This is mostly done for performance reasons, to avoid calling processors for nothing.

Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.

Parameters

array $record

Partial log record containing only a level key

Returns

Boolean

handleBatch()

handleBatch(array  $records) 

Handles a set of records at once.

Parameters

array $records

The records to handle (an array of record arrays)

pushProcessor()

pushProcessor(callable  $callback) : self

Adds a processor in the stack.

Parameters

callable $callback

Returns

self

popProcessor()

popProcessor() : callable

Removes the processor on top of the stack and returns it.

Returns

callable

getFormatter()

getFormatter() 

setLevel()

setLevel(integer|string  $level) : self

Sets minimum logging level at which this handler will be triggered.

Parameters

integer|string $level

Level or level name

Returns

self

getLevel()

getLevel() : integer

Gets minimum logging level at which this handler will be triggered.

Returns

integer

setBubble()

setBubble(Boolean  $bubble) : self

Sets the bubbling behavior.

Parameters

Boolean $bubble

true means that this handler allows bubbling. false means that bubbling is not permitted.

Returns

self

getBubble()

getBubble() : Boolean

Gets the bubbling behavior.

Returns

Boolean —

true means that this handler allows bubbling. false means that bubbling is not permitted.

__destruct()

__destruct() 

getSlackRecord()

getSlackRecord() 

write()

write(array  $record) : void

Connect (if necessary) and write to the socket

Parameters

array $record

pfsockopen()

pfsockopen() 

Wrapper to allow mocking

fsockopen()

fsockopen() 

Wrapper to allow mocking

streamSetTimeout()

streamSetTimeout() 

Wrapper to allow mocking

fwrite()

fwrite(  $data) 

Wrapper to allow mocking

Parameters

$data

streamGetMetadata()

streamGetMetadata() 

Wrapper to allow mocking

generateDataStream()

generateDataStream(array  $record) : string

Parameters

array $record

Returns

string

getResource()

getResource() : resource|null

Returns

resource|null

processRecord()

processRecord(array  $record) : array

Processes a record.

Parameters

array $record

Returns

array

prepareContentData()

prepareContentData(array  $record) : array

Prepares content data

Parameters

array $record

Returns

array

finalizeWrite()

finalizeWrite() 

Finalizes the request by reading some bytes and then closing the socket

If we do not read some but close the socket too early, slack sometimes drops the request entirely.

getAttachmentColor()

getAttachmentColor(integer  $level) : string

Returned a Slack message attachment color associated with provided level.

Parameters

integer $level

Returns

string

stringify()

stringify(array  $fields) : string

Stringifies an array of key/value pairs to be used in attachment fields

Parameters

array $fields

Returns

string

validateTimeout()

validateTimeout(  $value) 

Parameters

$value

connectIfNotConnected()

connectIfNotConnected() 

connect()

connect() 

createSocketResource()

createSocketResource() 

setSocketTimeout()

setSocketTimeout() 

writeToSocket()

writeToSocket(  $data) 

Parameters

$data

writingIsTimedOut()

writingIsTimedOut(  $sent) 

Parameters

$sent

buildContent()

buildContent(array  $record) : string

Builds the body of API call

Parameters

array $record

Returns

string

buildHeader()

buildHeader(string  $content) : string

Builds the header of the API Call

Parameters

string $content

Returns

string