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

Used for testing purposes. More...

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

Public Member Functions

 getRecords ()
 
 clear ()
 
 hasRecords ($level)
 
 hasRecord ($record, $level)
 
 hasRecordThatContains ($message, $level)
 
 hasRecordThatMatches ($regex, $level)
 
 hasRecordThatPasses ($predicate, $level)
 
 __call ($method, $args)
 
- 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)
 {} 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

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

Detailed Description

Used for testing purposes.

It records all records and gives you access to them for verification.

Author
Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be

bool hasEmergency($record) bool hasAlert($record) bool hasCritical($record) bool hasError($record) bool hasWarning($record) bool hasNotice($record) bool hasInfo($record) bool hasDebug($record)

bool hasEmergencyRecords() bool hasAlertRecords() bool hasCriticalRecords() bool hasErrorRecords() bool hasWarningRecords() bool hasNoticeRecords() bool hasInfoRecords() bool hasDebugRecords()

bool hasEmergencyThatContains($message) bool hasAlertThatContains($message) bool hasCriticalThatContains($message) bool hasErrorThatContains($message) bool hasWarningThatContains($message) bool hasNoticeThatContains($message) bool hasInfoThatContains($message) bool hasDebugThatContains($message)

bool hasEmergencyThatMatches($message) bool hasAlertThatMatches($message) bool hasCriticalThatMatches($message) bool hasErrorThatMatches($message) bool hasWarningThatMatches($message) bool hasNoticeThatMatches($message) bool hasInfoThatMatches($message) bool hasDebugThatMatches($message)

bool hasEmergencyThatPasses($message) bool hasAlertThatPasses($message) bool hasCriticalThatPasses($message) bool hasErrorThatPasses($message) bool hasWarningThatPasses($message) bool hasNoticeThatPasses($message) bool hasInfoThatPasses($message) bool hasDebugThatPasses($message)

Definition at line 66 of file TestHandler.php.

Member Function Documentation

◆ __call()

Monolog\Handler\TestHandler::__call (   $method,
  $args 
)

Definition at line 150 of file TestHandler.php.

References Monolog\Handler\AbstractHandler\$level.

151  {
152  if (preg_match('/(.*)(Debug|Info|Notice|Warning|Error|Critical|Alert|Emergency)(.*)/', $method, $matches) > 0) {
153  $genericMethod = $matches[1] . ('Records' !== $matches[3] ? 'Record' : '') . $matches[3];
154  $level = constant('Monolog\Logger::' . strtoupper($matches[2]));
155  if (method_exists($this, $genericMethod)) {
156  $args[] = $level;
157 
158  return call_user_func_array(array($this, $genericMethod), $args);
159  }
160  }
161 
162  throw new \BadMethodCallException('Call to undefined method ' . get_class($this) . '::' . $method . '()');
163  }

◆ clear()

Monolog\Handler\TestHandler::clear ( )

Definition at line 76 of file TestHandler.php.

77  {
78  $this->records = array();
79  $this->recordsByLevel = array();
80  }

◆ getRecords()

Monolog\Handler\TestHandler::getRecords ( )

Definition at line 71 of file TestHandler.php.

References Monolog\Handler\TestHandler\$records.

72  {
73  return $this->records;
74  }

◆ hasRecord()

Monolog\Handler\TestHandler::hasRecord (   $record,
  $level 
)
Parameters
string | array$recordEither a message string or an array containing message and optionally context keys that will be checked against all records
int$levelLogger::LEVEL constant value

Definition at line 91 of file TestHandler.php.

References Monolog\Handler\AbstractHandler\$level, and Monolog\Handler\TestHandler\hasRecordThatPasses().

92  {
93  if (is_string($record)) {
94  $record = array('message' => $record);
95  }
96 
97  return $this->hasRecordThatPasses(function ($rec) use ($record) {
98  if ($rec['message'] !== $record['message']) {
99  return false;
100  }
101  if (isset($record['context']) && $rec['context'] !== $record['context']) {
102  return false;
103  }
104  return true;
105  }, $level);
106  }
hasRecordThatPasses($predicate, $level)
+ Here is the call graph for this function:

◆ hasRecords()

Monolog\Handler\TestHandler::hasRecords (   $level)

Definition at line 82 of file TestHandler.php.

References Monolog\Handler\AbstractHandler\$level.

83  {
84  return isset($this->recordsByLevel[$level]);
85  }

◆ hasRecordThatContains()

Monolog\Handler\TestHandler::hasRecordThatContains (   $message,
  $level 
)

Definition at line 108 of file TestHandler.php.

References Monolog\Handler\AbstractHandler\$level, $message, and Monolog\Handler\TestHandler\hasRecordThatPasses().

109  {
110  return $this->hasRecordThatPasses(function ($rec) use ($message) {
111  return strpos($rec['message'], $message) !== false;
112  }, $level);
113  }
hasRecordThatPasses($predicate, $level)
catch(Exception $e) $message
+ Here is the call graph for this function:

◆ hasRecordThatMatches()

Monolog\Handler\TestHandler::hasRecordThatMatches (   $regex,
  $level 
)

Definition at line 115 of file TestHandler.php.

References Monolog\Handler\AbstractHandler\$level, and Monolog\Handler\TestHandler\hasRecordThatPasses().

116  {
117  return $this->hasRecordThatPasses(function ($rec) use ($regex) {
118  return preg_match($regex, $rec['message']) > 0;
119  }, $level);
120  }
hasRecordThatPasses($predicate, $level)
+ Here is the call graph for this function:

◆ hasRecordThatPasses()

Monolog\Handler\TestHandler::hasRecordThatPasses (   $predicate,
  $level 
)

Definition at line 122 of file TestHandler.php.

References $i, and Monolog\Handler\AbstractHandler\$level.

Referenced by Monolog\Handler\TestHandler\hasRecord(), Monolog\Handler\TestHandler\hasRecordThatContains(), and Monolog\Handler\TestHandler\hasRecordThatMatches().

123  {
124  if (!is_callable($predicate)) {
125  throw new \InvalidArgumentException("Expected a callable for hasRecordThatSucceeds");
126  }
127 
128  if (!isset($this->recordsByLevel[$level])) {
129  return false;
130  }
131 
132  foreach ($this->recordsByLevel[$level] as $i => $rec) {
133  if (call_user_func($predicate, $rec, $i)) {
134  return true;
135  }
136  }
137 
138  return false;
139  }
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ write()

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

{}

Definition at line 144 of file TestHandler.php.

145  {
146  $this->recordsByLevel[$record['level']][] = $record;
147  $this->records[] = $record;
148  }

Field Documentation

◆ $records

Monolog\Handler\TestHandler::$records = array()
protected

Definition at line 68 of file TestHandler.php.

Referenced by Monolog\Handler\TestHandler\getRecords().

◆ $recordsByLevel

Monolog\Handler\TestHandler::$recordsByLevel = array()
protected

Definition at line 69 of file TestHandler.php.


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