ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\SyslogUdpHandler Class Reference

A Handler for logging to a remote syslogd server. More...

+ Inheritance diagram for Monolog\Handler\SyslogUdpHandler:
+ Collaboration diagram for Monolog\Handler\SyslogUdpHandler:

Public Member Functions

 __construct ($host, $port=514, $facility=LOG_USER, $level=Logger::DEBUG, $bubble=true, $ident='php')
 
 close ()
 
 setSocket ($socket)
 Inject your own socket, mainly used for testing. More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractSyslogHandler
 __construct ($facility=LOG_USER, $level=Logger::DEBUG, $bubble=true)
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
bool true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {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$recordPartial log record containing only a level key
Returns
bool
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 
 reset ()
 

Protected Member Functions

 write (array $record)
 
 makeCommonSyslogHeader ($severity)
 Make common syslog header (see rfc5424) More...
 
 getDateTime ()
 
- Protected Member Functions inherited from Monolog\Handler\AbstractSyslogHandler
 getDefaultFormatter ()
 {} More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $socket
 
 $ident
 
- Protected Attributes inherited from Monolog\Handler\AbstractSyslogHandler
 $facility
 
 $logLevels
 Translates Monolog log levels to syslog log priorities. More...
 
 $facilities
 List of valid log facility names. More...
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Private Member Functions

 splitMessageIntoLines ($message)
 

Detailed Description

A Handler for logging to a remote syslogd server.

Author
Jesper Skovgaard Nielsen nulpu.nosp@m.nkt@.nosp@m.gmail.nosp@m..com

Definition at line 22 of file SyslogUdpHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\SyslogUdpHandler::__construct (   $host,
  $port = 514,
  $facility = LOG_USER,
  $level = Logger::DEBUG,
  $bubble = true,
  $ident = 'php' 
)
Parameters
string$host
int$port
mixed$facility
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
string$identProgram name or tag for each log message.

Definition at line 35 of file SyslogUdpHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\AbstractSyslogHandler\$facility, Monolog\Handler\SyslogUdpHandler\$ident, and Monolog\Handler\AbstractHandler\$level.

36  {
37  parent::__construct($facility, $level, $bubble);
38 
39  $this->ident = $ident;
40 
41  $this->socket = new UdpSocket($host, $port ?: 514);
42  }

Member Function Documentation

◆ close()

Monolog\Handler\SyslogUdpHandler::close ( )

Definition at line 55 of file SyslogUdpHandler.php.

56  {
57  $this->socket->close();
58  }

◆ getDateTime()

Monolog\Handler\SyslogUdpHandler::getDateTime ( )
protected

Definition at line 91 of file SyslogUdpHandler.php.

Referenced by Monolog\Handler\SyslogUdpHandler\makeCommonSyslogHeader().

92  {
93  return date(\DateTime::RFC3339);
94  }
+ Here is the caller graph for this function:

◆ makeCommonSyslogHeader()

Monolog\Handler\SyslogUdpHandler::makeCommonSyslogHeader (   $severity)
protected

Make common syslog header (see rfc5424)

Definition at line 72 of file SyslogUdpHandler.php.

References Monolog\Handler\AbstractSyslogHandler\$facility, and Monolog\Handler\SyslogUdpHandler\getDateTime().

Referenced by Monolog\Handler\SyslogUdpHandler\write().

73  {
74  $priority = $severity + $this->facility;
75 
76  if (!$pid = getmypid()) {
77  $pid = '-';
78  }
79 
80  if (!$hostname = gethostname()) {
81  $hostname = '-';
82  }
83 
84  return "<$priority>1 " .
85  $this->getDateTime() . " " .
86  $hostname . " " .
87  $this->ident . " " .
88  $pid . " - - ";
89  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSocket()

Monolog\Handler\SyslogUdpHandler::setSocket (   $socket)

Inject your own socket, mainly used for testing.

Definition at line 99 of file SyslogUdpHandler.php.

References Monolog\Handler\SyslogUdpHandler\$socket.

100  {
101  $this->socket = $socket;
102  }

◆ splitMessageIntoLines()

Monolog\Handler\SyslogUdpHandler::splitMessageIntoLines (   $message)
private

Definition at line 60 of file SyslogUdpHandler.php.

References $message.

Referenced by Monolog\Handler\SyslogUdpHandler\write().

61  {
62  if (is_array($message)) {
63  $message = implode("\n", $message);
64  }
65 
66  return preg_split('/$\R?^/m', $message, -1, PREG_SPLIT_NO_EMPTY);
67  }
catch(Exception $e) $message
+ Here is the caller graph for this function:

◆ write()

Monolog\Handler\SyslogUdpHandler::write ( array  $record)
protected

Definition at line 44 of file SyslogUdpHandler.php.

References $header, Monolog\Handler\SyslogUdpHandler\makeCommonSyslogHeader(), and Monolog\Handler\SyslogUdpHandler\splitMessageIntoLines().

45  {
46  $lines = $this->splitMessageIntoLines($record['formatted']);
47 
48  $header = $this->makeCommonSyslogHeader($this->logLevels[$record['level']]);
49 
50  foreach ($lines as $line) {
51  $this->socket->write($line, $header);
52  }
53  }
makeCommonSyslogHeader($severity)
Make common syslog header (see rfc5424)
+ Here is the call graph for this function:

Field Documentation

◆ $ident

Monolog\Handler\SyslogUdpHandler::$ident
protected

Definition at line 25 of file SyslogUdpHandler.php.

Referenced by Monolog\Handler\SyslogUdpHandler\__construct().

◆ $socket

Monolog\Handler\SyslogUdpHandler::$socket
protected

Definition at line 24 of file SyslogUdpHandler.php.

Referenced by Monolog\Handler\SyslogUdpHandler\setSocket().


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