MediaWiki  1.30.0
MediaWiki\Logger\Monolog\KafkaHandler Class Reference

Log handler sends log events to a kafka server. More...

Inheritance diagram for MediaWiki\Logger\Monolog\KafkaHandler:
Collaboration diagram for MediaWiki\Logger\Monolog\KafkaHandler:

Public Member Functions

 __construct (Produce $produce, array $options, $level=Logger::DEBUG, $bubble=true)
 
 handleBatch (array $batch)
 @inheritDoc More...
 

Static Public Member Functions

static factory ( $kafkaServers, array $options=[], $level=Logger::DEBUG, $bubble=true)
 Constructs the necessary support objects and returns a KafkaHandler instance. More...
 

Protected Member Functions

 addMessages ( $channel, array $records)
 Adds records for a channel to the Kafka client internal queue. More...
 
 getRandomPartition ( $topic)
 
 send ()
 Send any records in the kafka client internal queue. More...
 
 warning ( $message, array $context=[])
 
 write (array $record)
 @inheritDoc More...
 

Protected Attributes

array $options
 Optional handler configuration. More...
 
array $partitions = []
 Map from topic name to partition this request produces to. More...
 
Produce $produce
 Sends requests to kafka. More...
 

Static Private Attributes

static array $defaultOptions
 defaults for constructor options More...
 

Detailed Description

Log handler sends log events to a kafka server.

Constructor options array arguments:

  • alias: map from monolog channel to kafka topic name. When no alias exists the topic "monolog_$channel" will be used.
  • swallowExceptions: Swallow exceptions that occur while talking to kafka. Defaults to false.
  • logExceptions: Log exceptions talking to kafka here. Either null, the name of a channel to log to, or an object implementing FormatterInterface. Defaults to null.

Requires the nmred/kafka-php library, version >= 1.3.0

Since
1.26
Author
Erik Bernhardson ebern.nosp@m.hard.nosp@m.son@w.nosp@m.ikim.nosp@m.edia..nosp@m.org
Note
© 2015 Erik Bernhardson and Wikimedia Foundation.

Definition at line 49 of file KafkaHandler.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Logger\Monolog\KafkaHandler::__construct ( Produce  $produce,
array  $options,
  $level = Logger::DEBUG,
  $bubble = true 
)
Parameters
Produce$produceKafka instance to produce through
array$optionsoptional handler configuration
int$levelThe minimum logging level at which this handler will be triggered
bool$bubbleWhether the messages that are handled can bubble up the stack or not

Definition at line 81 of file KafkaHandler.php.

References MediaWiki\Logger\Monolog\KafkaHandler\$options, MediaWiki\Logger\Monolog\KafkaHandler\$produce, and options().

Member Function Documentation

◆ addMessages()

MediaWiki\Logger\Monolog\KafkaHandler::addMessages (   $channel,
array  $records 
)
protected

Adds records for a channel to the Kafka client internal queue.

Parameters
string$channelName of Monolog channel records belong to
array$recordsList of records to append

Definition at line 256 of file KafkaHandler.php.

References MediaWiki\Logger\Monolog\KafkaHandler\getRandomPartition(), and options().

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\handleBatch(), and MediaWiki\Logger\Monolog\KafkaHandler\write().

◆ factory()

static MediaWiki\Logger\Monolog\KafkaHandler::factory (   $kafkaServers,
array  $options = [],
  $level = Logger::DEBUG,
  $bubble = true 
)
static

Constructs the necessary support objects and returns a KafkaHandler instance.

Parameters
string[]$kafkaServers
array$options
int$levelThe minimum logging level at which this handle will be triggered
bool$bubbleWhether the messages that are handled can bubble the stack or not
Returns
KafkaHandler

Definition at line 99 of file KafkaHandler.php.

References MediaWiki\Logger\Monolog\KafkaHandler\$options, MediaWiki\Logger\Monolog\KafkaHandler\$produce, and MediaWiki\Logger\LoggerFactory\getInstance().

◆ getRandomPartition()

MediaWiki\Logger\Monolog\KafkaHandler::getRandomPartition (   $topic)
protected
Parameters
string$topicName of topic to get partition for
Returns
int|null The random partition to produce to for this request, or null if a partition could not be determined.

Definition at line 219 of file KafkaHandler.php.

References $e, MediaWiki\Logger\Monolog\KafkaHandler\$partitions, and MediaWiki\Logger\Monolog\KafkaHandler\warning().

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\addMessages().

◆ handleBatch()

MediaWiki\Logger\Monolog\KafkaHandler::handleBatch ( array  $batch)

◆ send()

MediaWiki\Logger\Monolog\KafkaHandler::send ( )
protected

Send any records in the kafka client internal queue.

Definition at line 172 of file KafkaHandler.php.

References $e, $response, as, and MediaWiki\Logger\Monolog\KafkaHandler\warning().

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\handleBatch(), and MediaWiki\Logger\Monolog\KafkaHandler\write().

◆ warning()

MediaWiki\Logger\Monolog\KafkaHandler::warning (   $message,
array  $context = [] 
)
protected
Parameters
string$messagePSR3 compatible message string
array$contextPSR3 compatible log context
Returns
bool true if caller should ignore warning

Definition at line 273 of file KafkaHandler.php.

References MediaWiki\$context, and options().

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\getRandomPartition(), and MediaWiki\Logger\Monolog\KafkaHandler\send().

◆ write()

MediaWiki\Logger\Monolog\KafkaHandler::write ( array  $record)
protected

Member Data Documentation

◆ $defaultOptions

array MediaWiki\Logger\Monolog\KafkaHandler::$defaultOptions
staticprivate
Initial value:
= [
'alias' => [],
'swallowExceptions' => false,
'logExceptions' => null,
'requireAck' => 0,
]

defaults for constructor options

Definition at line 68 of file KafkaHandler.php.

◆ $options

array MediaWiki\Logger\Monolog\KafkaHandler::$options
protected

Optional handler configuration.

Definition at line 58 of file KafkaHandler.php.

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\__construct(), and MediaWiki\Logger\Monolog\KafkaHandler\factory().

◆ $partitions

array MediaWiki\Logger\Monolog\KafkaHandler::$partitions = []
protected

Map from topic name to partition this request produces to.

Definition at line 63 of file KafkaHandler.php.

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\getRandomPartition().

◆ $produce

Produce MediaWiki\Logger\Monolog\KafkaHandler::$produce
protected

Sends requests to kafka.

Definition at line 53 of file KafkaHandler.php.

Referenced by MediaWiki\Logger\Monolog\KafkaHandler\__construct(), and MediaWiki\Logger\Monolog\KafkaHandler\factory().


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