Constants

API_V1

API_V1 = 'v1'

Use API version 1

API_V2

API_V2 = 'v2'

Use API version v2

MAXIMUM_NAME_LENGTH

MAXIMUM_NAME_LENGTH = 15

The maximum allowed length for the name used in the "from" field.

MAXIMUM_MESSAGE_LENGTH

MAXIMUM_MESSAGE_LENGTH = 9500

The maximum allowed length for the message.

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

Type

string

$room

$room : string

Type

string

$name

$name : string

Type

string

$notify

$notify : boolean

Type

boolean

$format

$format : string

Type

string

$host

$host : string

Type

string

$version

$version : string

Type

string

Methods

__construct()

__construct(string  $token, string  $room, string  $name = 'Monolog', boolean  $notify = false, integer  $level = \Monolog\Logger::CRITICAL, boolean  $bubble = true, boolean  $useSSL = true, string  $format = 'text', string  $host = 'api.hipchat.com', string  $version = self::API_V1) 

Parameters

string $token

HipChat API Token

string $room

The room that should be alerted of the message (Id or Name)

string $name

Name used in the "from" field.

boolean $notify

Trigger a notification in clients or not

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 $useSSL

Whether to connect via SSL.

string $format

The format of the messages (default to text, can be set to html if you have html in the messages)

string $host

The HipChat server hostname.

string $version

The HipChat API version (default HipChatHandler::API_V1)

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) 

{@inheritdoc}

Parameters

array $records

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

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() 

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

getAlertColor()

getAlertColor(integer  $level) : string

Assigns a color to each level of log records.

Parameters

integer $level

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

combineRecords()

combineRecords(  $records) : array

Combines multiple records into one. Error level of the combined record will be the highest level from the given records. Datetime will be taken from the first record.

Parameters

$records

Returns

array

validateStringLength()

validateStringLength(string  $str, integer  $length) : boolean

Validates the length of a string.

If the mb_strlen() function is available, it will use that, as HipChat allows UTF-8 characters. Otherwise, it will fall back to strlen().

Note that this might cause false failures in the specific case of using a valid name with less than 16 characters, but 16 or more bytes, on a system where mb_strlen() is unavailable.

Parameters

string $str
integer $length

Returns

boolean