ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 132 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$appName.

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

133  {
134  if (isset($context['appname'])) {
135  return $context['appname'];
136  }
137 
138  return $this->appName;
139  }
+ Here is the caller graph for this function:

◆ getDefaultFormatter()

Monolog\Handler\NewRelicHandler::getDefaultFormatter ( )
protected

Definition at line 194 of file NewRelicHandler.php.

195  {
196  return new NormalizerFormatter();
197  }

◆ 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 149 of file NewRelicHandler.php.

References Monolog\Handler\NewRelicHandler\$transactionName.

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

150  {
151  if (isset($context['transaction_name'])) {
152  return $context['transaction_name'];
153  }
154 
155  return $this->transactionName;
156  }
+ 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 120 of file NewRelicHandler.php.

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

121  {
122  return extension_loaded('newrelic');
123  }
+ 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 163 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 182 of file NewRelicHandler.php.

References Monolog\Handler\newrelic_add_custom_parameter().

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

183  {
184  if (null === $value || is_scalar($value)) {
185  newrelic_add_custom_parameter($key, $value);
186  } else {
187  newrelic_add_custom_parameter($key, @json_encode($value));
188  }
189  }
newrelic_add_custom_parameter($key, $value)
+ 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 173 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, 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  foreach ($record['formatted']['context'] as $key => $parameter) {
95  if (is_array($parameter) && $this->explodeArrays) {
96  foreach ($parameter as $paramKey => $paramValue) {
97  $this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue);
98  }
99  } else {
100  $this->setNewRelicParameter('context_' . $key, $parameter);
101  }
102  }
103 
104  foreach ($record['formatted']['extra'] as $key => $parameter) {
105  if (is_array($parameter) && $this->explodeArrays) {
106  foreach ($parameter as $paramKey => $paramValue) {
107  $this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue);
108  }
109  } else {
110  $this->setNewRelicParameter('extra_' . $key, $parameter);
111  }
112  }
113  }
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.
+ 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: