ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
NewRelicHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
16
25{
31 protected $appName;
32
39
46 protected $explodeArrays;
47
55 public function __construct(
57 $bubble = true,
58 $appName = null,
59 $explodeArrays = false,
60 $transactionName = null
61 ) {
62 parent::__construct($level, $bubble);
63
64 $this->appName = $appName;
65 $this->explodeArrays = $explodeArrays;
66 $this->transactionName = $transactionName;
67 }
68
72 protected function write(array $record)
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 }
114
120 protected function isNewRelicEnabled()
121 {
122 return extension_loaded('newrelic');
123 }
124
132 protected function getAppName(array $context)
133 {
134 if (isset($context['appname'])) {
135 return $context['appname'];
136 }
137
138 return $this->appName;
139 }
140
149 protected function getTransactionName(array $context)
150 {
151 if (isset($context['transaction_name'])) {
152 return $context['transaction_name'];
153 }
154
156 }
157
163 protected function setNewRelicAppName($appName)
164 {
166 }
167
174 {
176 }
177
182 protected function setNewRelicParameter($key, $value)
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 }
190
194 protected function getDefaultFormatter()
195 {
196 return new NormalizerFormatter();
197 }
198}
Normalizes incoming records to remove objects/resources so it's easier to dump to various targets.
Base Handler class providing the Handler structure.
Exception can be thrown if an extension for an handler is missing.
Class to record a log on a NewRelic application.
write(array $record)
Writes the record down to the log of the implementing handler.void
getTransactionName(array $context)
Returns the name of the current transaction.
setNewRelicAppName($appName)
Sets the NewRelic application that should receive this log.
getDefaultFormatter()
Gets the default formatter.FormatterInterface
setNewRelicTransactionName($transactionName)
Overwrites 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.
__construct( $level=Logger::ERROR, $bubble=true, $appName=null, $explodeArrays=false, $transactionName=null)
Monolog log channel.
Definition: Logger.php:28
const ERROR
Runtime errors.
Definition: Logger.php:57
newrelic_set_appname($appname)
newrelic_add_custom_parameter($key, $value)
newrelic_name_transaction($transactionName)