ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Monolog\Handler\NewRelicHandler Class Reference

Class to record a log on a NewRelic application. More...

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

Public Member Functions

 __construct ( $level=Logger::ERROR, $bubble=true, $appName=null, $explodeArrays=false, $transactionName=null)
 
- 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 ()
 

Protected Member Functions

 write (array $record)
 
 isNewRelicEnabled ()
 Checks whether the NewRelic extension is enabled in the system. More...
 
 getAppName (array $context)
 Returns the appname where this log should be sent. More...
 
 getTransactionName (array $context)
 Returns the name of the current transaction. More...
 
 setNewRelicAppName ($appName)
 Sets the NewRelic application that should receive this log. More...
 
 setNewRelicTransactionName ($transactionName)
 Overwrites the name of the current transaction. More...
 
 setNewRelicParameter ($key, $value)
 
 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

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

Detailed Description

Class to record a log on a NewRelic application.

Enabling New Relic High Security mode may prevent capture of useful information.

See also
https://docs.newrelic.com/docs/agents/php-agent
https://docs.newrelic.com/docs/accounts-partnerships/accounts/security/high-security

Definition at line 24 of file NewRelicHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\NewRelicHandler::__construct (   $level = Logger::ERROR,
  $bubble = true,
  $appName = null,
  $explodeArrays = false,
  $transactionName = null 
)

Member Function Documentation

◆ getAppName()

Monolog\Handler\NewRelicHandler::getAppName ( array  $context)
protected

Returns the appname where this log should be sent.

Each log can override the default appname, set in this handler's constructor, by providing the appname in it's context.

Parameters
array$context
Returns
null|string

Definition at line 136 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$appName.

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

137  {
138  if (isset($context['appname'])) {
139  return $context['appname'];
140  }
141 
142  return $this->appName;
143  }
+ Here is the caller graph for this function:

◆ getDefaultFormatter()

Monolog\Handler\NewRelicHandler::getDefaultFormatter ( )
protected

Definition at line 198 of file NewRelicHandler.php.

199  {
200  return new NormalizerFormatter();
201  }

◆ getTransactionName()

Monolog\Handler\NewRelicHandler::getTransactionName ( array  $context)
protected

Returns the name of the current transaction.

Each log can override the default transaction name, set in this handler's constructor, by providing the transaction_name in it's context

Parameters
array$context
Returns
null|string

Definition at line 153 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$transactionName.

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

154  {
155  if (isset($context['transaction_name'])) {
156  return $context['transaction_name'];
157  }
158 
159  return $this->transactionName;
160  }
+ Here is the caller graph for this function:

◆ isNewRelicEnabled()

Monolog\Handler\NewRelicHandler::isNewRelicEnabled ( )
protected

Checks whether the NewRelic extension is enabled in the system.

Returns
bool

Definition at line 124 of file NewRelicHandler.php.

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

125  {
126  return extension_loaded('newrelic');
127  }
+ Here is the caller graph for this function:

◆ setNewRelicAppName()

Monolog\Handler\NewRelicHandler::setNewRelicAppName (   $appName)
protected

Sets the NewRelic application that should receive this log.

Parameters
string$appName

Definition at line 167 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$appName, and Monolog\Handler\newrelic_set_appname().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setNewRelicParameter()

Monolog\Handler\NewRelicHandler::setNewRelicParameter (   $key,
  $value 
)
protected
Parameters
string$key
mixed$value

Definition at line 186 of file NewRelicHandler.php.

References $key, and Monolog\Handler\newrelic_add_custom_parameter().

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

187  {
188  if (null === $value || is_scalar($value)) {
190  } else {
191  newrelic_add_custom_parameter($key, @json_encode($value));
192  }
193  }
newrelic_add_custom_parameter($key, $value)
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setNewRelicTransactionName()

Monolog\Handler\NewRelicHandler::setNewRelicTransactionName (   $transactionName)
protected

Overwrites the name of the current transaction.

Parameters
string$transactionName

Definition at line 177 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$transactionName, and Monolog\Handler\newrelic_name_transaction().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

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

Definition at line 72 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$appName, $key, Monolog\Handler\NewRelicHandler\$transactionName, Monolog\Handler\NewRelicHandler\getAppName(), Monolog\Handler\NewRelicHandler\getTransactionName(), Monolog\Handler\NewRelicHandler\isNewRelicEnabled(), Monolog\Handler\newrelic_notice_error(), Monolog\Handler\NewRelicHandler\setNewRelicAppName(), Monolog\Handler\NewRelicHandler\setNewRelicParameter(), and Monolog\Handler\NewRelicHandler\setNewRelicTransactionName().

73  {
74  if (!$this->isNewRelicEnabled()) {
75  throw new MissingExtensionException('The newrelic PHP extension is required to use the NewRelicHandler');
76  }
77 
78  if ($appName = $this->getAppName($record['context'])) {
80  }
81 
82  if ($transactionName = $this->getTransactionName($record['context'])) {
84  unset($record['formatted']['context']['transaction_name']);
85  }
86 
87  if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
88  newrelic_notice_error($record['message'], $record['context']['exception']);
89  unset($record['formatted']['context']['exception']);
90  } else {
91  newrelic_notice_error($record['message']);
92  }
93 
94  if (isset($record['formatted']['context']) && is_array($record['formatted']['context'])) {
95  foreach ($record['formatted']['context'] as $key => $parameter) {
96  if (is_array($parameter) && $this->explodeArrays) {
97  foreach ($parameter as $paramKey => $paramValue) {
98  $this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue);
99  }
100  } else {
101  $this->setNewRelicParameter('context_' . $key, $parameter);
102  }
103  }
104  }
105 
106  if (isset($record['formatted']['extra']) && is_array($record['formatted']['extra'])) {
107  foreach ($record['formatted']['extra'] as $key => $parameter) {
108  if (is_array($parameter) && $this->explodeArrays) {
109  foreach ($parameter as $paramKey => $paramValue) {
110  $this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue);
111  }
112  } else {
113  $this->setNewRelicParameter('extra_' . $key, $parameter);
114  }
115  }
116  }
117  }
setNewRelicTransactionName($transactionName)
Overwrites the name of the current transaction.
setNewRelicAppName($appName)
Sets the NewRelic application that should receive this log.
getTransactionName(array $context)
Returns the name of the current transaction.
getAppName(array $context)
Returns the appname where this log should be sent.
isNewRelicEnabled()
Checks whether the NewRelic extension is enabled in the system.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Field Documentation

◆ $appName

◆ $explodeArrays

Monolog\Handler\NewRelicHandler::$explodeArrays
protected

Definition at line 46 of file NewRelicHandler.php.

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

◆ $transactionName


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