44
55use Bugsnag \Client ;
66use Bugsnag \Report ;
7- use Exception ;
7+ use Psr \ Log \ AbstractLogger ;
88use Psr \Log \LogLevel ;
99use Throwable ;
1010
@@ -15,7 +15,7 @@ class BugsnagLogger extends AbstractLogger
1515 *
1616 * @var \Bugsnag\Client
1717 */
18- protected $ client ;
18+ protected Client $ client ;
1919
2020 /**
2121 * The minimum level required to notify bugsnag.
@@ -24,7 +24,7 @@ class BugsnagLogger extends AbstractLogger
2424 *
2525 * @var string
2626 */
27- protected $ notifyLevel = LogLevel::NOTICE ;
27+ protected string $ notifyLevel = LogLevel::NOTICE ;
2828
2929 /**
3030 * Create a new bugsnag logger instance.
@@ -45,7 +45,7 @@ public function __construct(Client $client)
4545 *
4646 * @return void
4747 */
48- public function setNotifyLevel ($ notifyLevel )
48+ public function setNotifyLevel (string $ notifyLevel ): void
4949 {
5050 if (!in_array ($ notifyLevel , $ this ->getLogLevelOrder ())) {
5151 syslog (LOG_WARNING , 'Bugsnag Warning: Invalid notify level supplied to Bugsnag Logger ' );
@@ -57,13 +57,13 @@ public function setNotifyLevel($notifyLevel)
5757 /**
5858 * Log a message to the logs.
5959 *
60- * @param string $level
61- * @param mixed $message
62- * @param array $context
60+ * @param mixed $level
61+ * @param string|\Stringable $message
62+ * @param mixed[] $context
6363 *
6464 * @return void
6565 */
66- public function log ($ level , $ message , array $ context = [])
66+ public function log (mixed $ level , string | \ Stringable $ message , array $ context = []): void
6767 {
6868 $ title = 'Log ' .$ level ;
6969 if (isset ($ context ['title ' ])) {
@@ -72,10 +72,10 @@ public function log($level, $message, array $context = [])
7272 }
7373
7474 $ exception = null ;
75- if (isset ($ context ['exception ' ]) && ( $ context ['exception ' ] instanceof Exception || $ context [ ' exception ' ] instanceof Throwable) ) {
75+ if (isset ($ context ['exception ' ]) && $ context ['exception ' ] instanceof Throwable) {
7676 $ exception = $ context ['exception ' ];
7777 unset($ context ['exception ' ]);
78- } elseif ($ message instanceof Exception || $ message instanceof Throwable) {
78+ } elseif ($ message instanceof Throwable) {
7979 $ exception = $ message ;
8080 }
8181
@@ -118,12 +118,12 @@ public function log($level, $message, array $context = [])
118118 /**
119119 * Checks whether the selected level is above another level.
120120 *
121- * @param string $level
121+ * @param mixed $level
122122 * @param string $base
123123 *
124124 * @return bool
125125 */
126- protected function aboveLevel ($ level , $ base )
126+ protected function aboveLevel (mixed $ level , string $ base ): bool
127127 {
128128 $ levelOrder = $ this ->getLogLevelOrder ();
129129 $ baseIndex = array_search ($ base , $ levelOrder );
@@ -137,7 +137,7 @@ protected function aboveLevel($level, $base)
137137 *
138138 * @return string[]
139139 */
140- protected function getLogLevelOrder ()
140+ protected function getLogLevelOrder (): array
141141 {
142142 return [
143143 LogLevel::DEBUG ,
@@ -154,11 +154,11 @@ protected function getLogLevelOrder()
154154 /**
155155 * Get the severity for the logger.
156156 *
157- * @param string $level
157+ * @param mixed $level
158158 *
159159 * @return string
160160 */
161- protected function getSeverity ($ level )
161+ protected function getSeverity (mixed $ level ): string
162162 {
163163 if ($ this ->aboveLevel ($ level , 'error ' )) {
164164 return 'error ' ;
@@ -172,32 +172,16 @@ protected function getSeverity($level)
172172 /**
173173 * Format the parameters for the logger.
174174 *
175- * @param mixed $message
175+ * @param string|\Stringable $message
176176 *
177177 * @return string
178178 */
179- protected function formatMessage ($ message )
179+ protected function formatMessage (string | \ Stringable $ message ): string
180180 {
181- if (is_array ($ message )) {
182- return var_export ( $ message, true ) ;
181+ if (is_string ($ message )) {
182+ return $ message ;
183183 }
184184
185- return $ message ;
186- }
187-
188- /**
189- * Ensure the given string is less than 100 characters.
190- *
191- * @param string $str
192- *
193- * @return string
194- */
195- protected function limit ($ str )
196- {
197- if (strlen ($ str ) <= 100 ) {
198- return $ str ;
199- }
200-
201- return rtrim (substr ($ str , 0 , 97 )).'... ' ;
185+ return (string ) $ message ;
202186 }
203187}
0 commit comments