22namespace DreamFactory \Core \Logger \Components ;
33
44use DreamFactory \Core \Exceptions \BadRequestException ;
5+ use Illuminate \Support \Facades \Log ;
56use Monolog \Logger ;
67
78abstract class NetworkLogger
@@ -42,72 +43,78 @@ public function __construct($host, $port, $protocol = 'udp')
4243 }
4344
4445 /** {@inheritdoc} */
45- public function log ($ level , $ message , array $ context = [])
46+ public function log ($ level , string | \ Stringable $ message , array $ context = []): void
4647 {
47- $ levelVal = Logger::toMonologLevel ($ level );
48- if (!is_int ($ levelVal )){
49- throw new BadRequestException ('Unknown log level [ ' . $ level . '] ' );
48+ try {
49+ $ levelVal = Logger::toMonologLevel ($ level );
50+ if (!is_int ($ levelVal )){
51+ throw new BadRequestException ('Unknown log level [ ' . $ level . '] ' );
52+ }
53+ $ context ['_message ' ] = $ message ;
54+ $ context ['_level ' ] = $ levelVal ;
55+
56+ $ this ->send (json_encode ($ context , JSON_UNESCAPED_SLASHES ));
57+ } catch (\Throwable $ exception ) {
58+ Log::error ($ exception ->getMessage ());
59+ Log::error ($ exception ->getTraceAsString ());
5060 }
51- $ context ['_message ' ] = $ message ;
52- $ context ['_level ' ] = $ levelVal ;
5361
54- return $ this ->send (json_encode ($ context , JSON_UNESCAPED_SLASHES ));
5562 }
5663
5764 /** {@inheritdoc} */
58- public function emergency ($ message , array $ context = [])
65+ public function emergency (string | \ Stringable $ message , array $ context = []): void
5966 {
6067 $ this ->log (Logger::EMERGENCY , $ message , $ context );
6168 }
6269
6370 /** {@inheritdoc} */
64- public function alert ($ message , array $ context = [])
71+ public function alert (string | \ Stringable $ message , array $ context = []): void
6572 {
6673 $ this ->log (Logger::ALERT , $ message , $ context );
6774 }
6875
6976 /** {@inheritdoc} */
70- public function critical ($ message , array $ context = [])
77+ public function critical (string | \ Stringable $ message , array $ context = []): void
7178 {
7279 $ this ->log (Logger::CRITICAL , $ message , $ context );
7380 }
7481
7582 /** {@inheritdoc} */
76- public function error ($ message , array $ context = [])
83+ public function error (string | \ Stringable $ message , array $ context = []): void
7784 {
7885 $ this ->log (Logger::ERROR , $ message , $ context );
7986 }
8087
8188 /** {@inheritdoc} */
82- public function warning ($ message , array $ context = [])
89+ public function warning (string | \ Stringable $ message , array $ context = []): void
8390 {
8491 $ this ->log (Logger::WARNING , $ message , $ context );
8592 }
8693
8794 /** {@inheritdoc} */
88- public function notice ($ message , array $ context = [])
95+ public function notice (string | \ Stringable $ message , array $ context = []): void
8996 {
9097 $ this ->log (Logger::NOTICE , $ message , $ context );
9198 }
9299
93100 /** {@inheritdoc} */
94- public function info ($ message , array $ context = [])
101+ public function info (string | \ Stringable $ message , array $ context = []): void
95102 {
96103 $ this ->log (Logger::INFO , $ message , $ context );
97104 }
98105
99106 /** {@inheritdoc} */
100- public function debug ($ message , array $ context = [])
107+ public function debug (string | \ Stringable $ message , array $ context = []): void
101108 {
102109 $ this ->log (Logger::DEBUG , $ message , $ context );
103110 }
104111
105112 /**
106- * @param $message
113+ * @param string|\Stringable $message
107114 *
108115 * @return bool
109116 */
110- public function send ($ message )
117+ public function send (string | \ Stringable $ message )
111118 {
112119 try {
113120 $ _url = $ this ->protocol . ':// ' . $ this ->host . ': ' . $ this ->port ;
@@ -116,7 +123,9 @@ public function send($message)
116123 if (!fwrite ($ _sock , $ message )) {
117124 return false ;
118125 }
119- } catch (\Exception $ _ex ) {
126+ } catch (\Exception $ ex ) {
127+ Log::error ($ ex ->getMessage ());
128+ Log::error ($ ex ->getTraceAsString ());
120129 // Failure is not an option
121130 return false ;
122131 }
0 commit comments