ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Monolog\Handler\LogglyHandler Class Reference

Sends errors to Loggly. More...

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

Public Member Functions

 __construct ($token, $level=Logger::DEBUG, $bubble=true)
 
 setTag ($tag)
 
 addTag ($tag)
 
 handleBatch (array $records)
 Handles a set of records at once. More...
 
- 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
Boolean 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
Boolean
} 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 ()
 

Data Fields

const HOST = 'logs-01.loggly.com'
 
const ENDPOINT_SINGLE = 'inputs'
 
const ENDPOINT_BATCH = 'bulk'
 

Protected Member Functions

 write (array $record)
 
 send ($data, $endpoint)
 
 getDefaultFormatter ()
 
- 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

 $token
 
 $tag = array()
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Sends errors to Loggly.

Author
Przemek Sobstel przem.nosp@m.ek@s.nosp@m.obste.nosp@m.l.or.nosp@m.g
Adam Pancutt adam@.nosp@m.panc.nosp@m.utt.c.nosp@m.om
Gregory Barchard grego.nosp@m.ry@b.nosp@m.archa.nosp@m.rd.n.nosp@m.et

Definition at line 24 of file LogglyHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\LogglyHandler::__construct (   $token,
  $level = Logger::DEBUG,
  $bubble = true 
)

Definition at line 34 of file LogglyHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\AbstractHandler\$level, and Monolog\Handler\LogglyHandler\$token.

35  {
36  if (!extension_loaded('curl')) {
37  throw new \LogicException('The curl extension is needed to use the LogglyHandler');
38  }
39 
40  $this->token = $token;
41 
42  parent::__construct($level, $bubble);
43  }

Member Function Documentation

◆ addTag()

Monolog\Handler\LogglyHandler::addTag (   $tag)

Definition at line 51 of file LogglyHandler.php.

References Monolog\Handler\LogglyHandler\$tag, and array.

52  {
53  if (!empty($tag)) {
54  $tag = is_array($tag) ? $tag : array($tag);
55  $this->tag = array_unique(array_merge($this->tag, $tag));
56  }
57  }
Create styles array
The data for the language used.

◆ getDefaultFormatter()

Monolog\Handler\LogglyHandler::getDefaultFormatter ( )
protected

Definition at line 98 of file LogglyHandler.php.

99  {
100  return new LogglyFormatter();
101  }

◆ handleBatch()

Monolog\Handler\LogglyHandler::handleBatch ( array  $records)

Handles a set of records at once.

Parameters
array$recordsThe records to handle (an array of record arrays)

Implements Monolog\Handler\HandlerInterface.

Definition at line 64 of file LogglyHandler.php.

References Monolog\Handler\AbstractHandler\$level, Monolog\Handler\AbstractHandler\getFormatter(), and Monolog\Handler\LogglyHandler\send().

65  {
67 
68  $records = array_filter($records, function ($record) use ($level) {
69  return ($record['level'] >= $level);
70  });
71 
72  if ($records) {
73  $this->send($this->getFormatter()->formatBatch($records), self::ENDPOINT_BATCH);
74  }
75  }
$records
Definition: simple_test.php:22
getFormatter()
{Gets the formatter.FormatterInterface}
+ Here is the call graph for this function:

◆ send()

Monolog\Handler\LogglyHandler::send (   $data,
  $endpoint 
)
protected

Definition at line 77 of file LogglyHandler.php.

References $data, $url, array, and Monolog\Handler\Curl\Util\execute().

Referenced by Monolog\Handler\LogglyHandler\handleBatch(), and Monolog\Handler\LogglyHandler\write().

78  {
79  $url = sprintf("https://%s/%s/%s/", self::HOST, $endpoint, $this->token);
80 
81  $headers = array('Content-Type: application/json');
82 
83  if (!empty($this->tag)) {
84  $headers[] = 'X-LOGGLY-TAG: '.implode(',', $this->tag);
85  }
86 
87  $ch = curl_init();
88 
89  curl_setopt($ch, CURLOPT_URL, $url);
90  curl_setopt($ch, CURLOPT_POST, true);
91  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
92  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
93  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
94 
95  Curl\Util::execute($ch);
96  }
$url
Definition: shib_logout.php:72
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Definition: Util.php:32
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTag()

Monolog\Handler\LogglyHandler::setTag (   $tag)

Definition at line 45 of file LogglyHandler.php.

References Monolog\Handler\LogglyHandler\$tag, and array.

46  {
47  $tag = !empty($tag) ? $tag : array();
48  $this->tag = is_array($tag) ? $tag : array($tag);
49  }
Create styles array
The data for the language used.

◆ write()

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

Definition at line 59 of file LogglyHandler.php.

References Monolog\Handler\LogglyHandler\send().

60  {
61  $this->send($record["formatted"], self::ENDPOINT_SINGLE);
62  }
+ Here is the call graph for this function:

Field Documentation

◆ $tag

Monolog\Handler\LogglyHandler::$tag = array()
protected

◆ $token

Monolog\Handler\LogglyHandler::$token
protected

Definition at line 30 of file LogglyHandler.php.

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

◆ ENDPOINT_BATCH

const Monolog\Handler\LogglyHandler::ENDPOINT_BATCH = 'bulk'

Definition at line 28 of file LogglyHandler.php.

◆ ENDPOINT_SINGLE

const Monolog\Handler\LogglyHandler::ENDPOINT_SINGLE = 'inputs'

Definition at line 27 of file LogglyHandler.php.

◆ HOST

const Monolog\Handler\LogglyHandler::HOST = 'logs-01.loggly.com'

Definition at line 26 of file LogglyHandler.php.


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