Properties

$processors

$processors : callable[]

Type

callable[]

$formatter

$formatter : ?\Monolog\Formatter\FormatterInterface

Type

FormatterInterface

$level

$level : int

Type

int

$bubble

$bubble : bool

Type

bool

$connectionString

$connectionString : string

Type

string

$connectionTimeout

$connectionTimeout : float

Type

float

$timeout

$timeout : float

Type

float

$writingTimeout

$writingTimeout : float

Type

float

$lastSentBytes

$lastSentBytes : ?int

Type

?int

$chunkSize

$chunkSize : ?int

Type

?int

$persistent

$persistent : bool

Type

bool

$errno

$errno : ?int

Type

?int

$errstr

$errstr : ?string

Type

?string

$lastWritingAt

$lastWritingAt : ?float

Type

?float

$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

SlackRecord

Methods

__construct()

__construct(string  $token, string  $channel, string|null  $username = null, bool  $useAttachment = true, string|null  $iconEmoji = null, mixed  $level = Logger::CRITICAL, bool  $bubble = true, bool  $useShortAttachment = false, bool  $includeContextAndExtra = false, string[]  $excludeFields = array(), bool  $persistent = false, float  $timeout = 0.0, float  $writingTimeout = 10.0, ?float  $connectionTimeout = null, ?int  $chunkSize = null) : mixed

Parameters

string $token

Slack API token

string $channel

Slack channel (encoded ID or name)

string|null $username

Name of a bot

bool $useAttachment

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

string|null $iconEmoji

The emoji name to use (or null)

mixed $level
bool $bubble
bool $useShortAttachment

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

bool $includeContextAndExtra

Whether the attachment should include context and extra data

string[] $excludeFields

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

bool $persistent

Flag to enable/disable persistent connections

float $timeout

Socket timeout to wait until the request is being aborted

float $writingTimeout

Socket timeout to wait until the request should've been sent/written

?float $connectionTimeout

Socket connect timeout to wait until the connection should've been established

?int $chunkSize

Sets the chunk size. Only has effect during connection in the writing cycle

Throws

\Monolog\Handler\MissingExtensionException

If no OpenSSL PHP extension configured

Returns

mixed —

close()

close() : void

Closes the handler.

closeSocket()

closeSocket() : void

Close socket, if open

setPersistent()

setPersistent(bool  $persistent) : self

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

Parameters

bool $persistent

Returns

self —

setConnectionTimeout()

setConnectionTimeout(float  $seconds) : self

Set connection timeout. Only has effect before we connect.

Parameters

float $seconds

Returns

self —

setTimeout()

setTimeout(float  $seconds) : self

Set write timeout. Only has effect before we connect.

Parameters

float $seconds

Returns

self —

setWritingTimeout()

setWritingTimeout(float  $seconds) : self

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

Parameters

float $seconds

0 for no timeout

Returns

self —

setChunkSize()

setChunkSize(int  $bytes) : self

Set chunk size. Only has effect during connection in the writing cycle.

Parameters

int $bytes

Returns

self —

getConnectionString()

getConnectionString() : string

Get current connection string

Returns

string —

isPersistent()

isPersistent() : bool

Get persistent setting

Returns

bool —

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 —

getChunkSize()

getChunkSize() : ?int

Get current chunk size

Returns

?int —

isConnected()

isConnected() : bool

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

bool —

handle()

handle(array  $record) : bool

{@inheritDoc}

Parameters

array $record

Returns

bool —

reset()

reset() : void

pushProcessor()

pushProcessor(callable  $callback) : \Monolog\Handler\HandlerInterface

{@inheritDoc}

Parameters

callable $callback

Returns

\Monolog\Handler\HandlerInterface —

popProcessor()

popProcessor() : callable

{@inheritDoc}

Returns

callable —

setFormatter()

setFormatter(\Monolog\Formatter\FormatterInterface  $formatter) : \Monolog\Handler\HandlerInterface

Parameters

\Monolog\Formatter\FormatterInterface $formatter

Returns

\Monolog\Handler\HandlerInterface —

getFormatter()

getFormatter() : \Monolog\Formatter\FormatterInterface

Returns

\Monolog\Formatter\FormatterInterface —

isHandling()

isHandling(array  $record) : bool

{@inheritDoc}

Parameters

array $record

Returns

bool —

setLevel()

setLevel(mixed  $level) : self

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

Parameters

mixed $level

Returns

self —

getLevel()

getLevel() : int

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

Returns

int —

setBubble()

setBubble(bool  $bubble) : self

Sets the bubbling behavior.

Parameters

bool $bubble

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

Returns

self —

getBubble()

getBubble() : bool

Gets the bubbling behavior.

Returns

bool —

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

handleBatch()

handleBatch(array  $records) : void

Handles a set of records at once.

Parameters

array $records

The records to handle (an array of record arrays)

__destruct()

__destruct() : mixed

Returns

mixed —

__sleep()

__sleep() : mixed

Returns

mixed —

getSlackRecord()

getSlackRecord() : \Monolog\Handler\Slack\SlackRecord

Returns

\Monolog\Handler\Slack\SlackRecord —

getToken()

getToken() : string

Returns

string —

setChannel()

setChannel(string  $channel) : self

Channel used by the bot when posting

Parameters

string $channel

Returns

self —

setUsername()

setUsername(string  $username) : self

Username used by the bot when posting

Parameters

string $username

Returns

self —

useAttachment()

useAttachment(bool  $useAttachment) : self

Parameters

bool $useAttachment

Returns

self —

setIconEmoji()

setIconEmoji(string  $iconEmoji) : self

Parameters

string $iconEmoji

Returns

self —

useShortAttachment()

useShortAttachment(bool  $useShortAttachment) : self

Parameters

bool $useShortAttachment

Returns

self —

includeContextAndExtra()

includeContextAndExtra(bool  $includeContextAndExtra) : self

Parameters

bool $includeContextAndExtra

Returns

self —

excludeFields()

excludeFields(string[]  $excludeFields) : self

Parameters

string[] $excludeFields

Returns

self —

write()

write(array  $record) : void

Connect (if necessary) and write to the socket

Parameters

array $record

pfsockopen()

pfsockopen() : resource|false

Wrapper to allow mocking

Returns

resource|false —

fsockopen()

fsockopen() : resource|false

Wrapper to allow mocking

Returns

resource|false —

streamSetTimeout()

streamSetTimeout() : bool

Wrapper to allow mocking

Returns

bool —

streamSetChunkSize()

streamSetChunkSize() : int|bool

Wrapper to allow mocking

Returns

int|bool —

fwrite()

fwrite(string  $data) : int|bool

Wrapper to allow mocking

Parameters

string $data

Returns

int|bool —

streamGetMetadata()

streamGetMetadata() : array|bool

Wrapper to allow mocking

Returns

array|bool —

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 —

resetProcessors()

resetProcessors() : void

getDefaultFormatter()

getDefaultFormatter() : \Monolog\Formatter\FormatterInterface

Gets the default formatter.

Overwrite this if the LineFormatter is not a good default for your handler.

Returns

\Monolog\Formatter\FormatterInterface —

prepareContentData()

prepareContentData(array  $record) : string[]

Parameters

array $record

Returns

string[] —

finalizeWrite()

finalizeWrite() : void

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.

validateTimeout()

validateTimeout(float  $value) : void

Parameters

float $value

connectIfNotConnected()

connectIfNotConnected() : void

connect()

connect() : void

createSocketResource()

createSocketResource() : void

setSocketTimeout()

setSocketTimeout() : void

setStreamChunkSize()

setStreamChunkSize() : void

writeToSocket()

writeToSocket(string  $data) : void

Parameters

string $data

writingIsTimedOut()

writingIsTimedOut(int  $sent) : bool

Parameters

int $sent

Returns

bool —

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 —