Browse Source

log exception

walkor 9 years ago
parent
commit
3f8a1dfc40
9 changed files with 67 additions and 55 deletions
  1. 4 4
      Connection/AsyncTcpConnection.php
  2. 17 14
      Connection/TcpConnection.php
  3. 6 4
      Events/Ev.php
  4. 4 2
      Events/Event.php
  5. 4 2
      Events/Libevent.php
  6. 9 8
      Protocols/Websocket.php
  7. 10 8
      Protocols/Ws.php
  8. 2 2
      WebServer.php
  9. 11 11
      Worker.php

+ 4 - 4
Connection/AsyncTcpConnection.php

@@ -109,10 +109,10 @@ class AsyncTcpConnection extends TcpConnection
             try {
                 call_user_func($this->onError, $this, $code, $msg);
             } catch (\Exception $e) {
-                echo $e;
+                Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                Worker::log($e);
                 exit(250);
             }
         }
@@ -151,10 +151,10 @@ class AsyncTcpConnection extends TcpConnection
                 try {
                     call_user_func($this->onConnect, $this);
                 } catch (\Exception $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 }
             }

+ 17 - 14
Connection/TcpConnection.php

@@ -259,10 +259,10 @@ class TcpConnection extends ConnectionInterface
                         try {
                             call_user_func($this->onError, $this, WORKERMAN_SEND_FAIL, 'client closed');
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     }
@@ -283,7 +283,10 @@ class TcpConnection extends ConnectionInterface
                     try {
                         call_user_func($this->onError, $this, WORKERMAN_SEND_FAIL, 'send buffer full and drop package');
                     } catch (\Exception $e) {
-                        echo $e;
+                        Worker::log($e);
+                        exit(250);
+                    } catch (\Error $e) {
+                        Worker::log($e);
                         exit(250);
                     }
                 }
@@ -418,13 +421,13 @@ class TcpConnection extends ConnectionInterface
                     continue;
                 }
                 try {
-                    // Decode request buffer before Emiting onMessage callback.
+                    // Decode request buffer before Emitting onMessage callback.
                     call_user_func($this->onMessage, $this, $parser::decode($one_request_buffer, $this));
                 } catch (\Exception $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 }
             }
@@ -444,10 +447,10 @@ class TcpConnection extends ConnectionInterface
         try {
             call_user_func($this->onMessage, $this, $this->_recvBuffer);
         } catch (\Exception $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         } catch (\Error $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         }
         // Clean receive buffer.
@@ -470,10 +473,10 @@ class TcpConnection extends ConnectionInterface
                 try {
                     call_user_func($this->onBufferDrain, $this);
                 } catch (\Exception $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 }
             }
@@ -567,10 +570,10 @@ class TcpConnection extends ConnectionInterface
                 try {
                     call_user_func($this->onBufferFull, $this);
                 } catch (\Exception $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 }
             }
@@ -603,10 +606,10 @@ class TcpConnection extends ConnectionInterface
             try {
                 call_user_func($this->onClose, $this);
             } catch (\Exception $e) {
-                echo $e;
+                Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                Worker::log($e);
                 exit(250);
             }
         }

+ 6 - 4
Events/Ev.php

@@ -12,6 +12,8 @@
  */
 namespace Workerman\Events;
 
+use Workerman\Worker;
+
 /**
  * ev eventloop
  */
@@ -56,10 +58,10 @@ class Ev implements EventInterface
             try {
                 call_user_func($func, $fd);
             } catch (\Exception $e) {
-                echo $e;
+                Worker::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                Worker::log($e);
                 exit(250);
             }
         };
@@ -138,10 +140,10 @@ class Ev implements EventInterface
         try {
             call_user_func_array($param[0], $param[1]);
         } catch (\Exception $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         } catch (\Error $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         }
     }

+ 4 - 2
Events/Event.php

@@ -13,6 +13,8 @@
  */
 namespace Workerman\Events;
 
+use Workerman\Worker;
+
 /**
  * libevent eventloop
  */
@@ -155,10 +157,10 @@ class Event implements EventInterface
         try {
             call_user_func_array($param[0], $param[1]);
         } catch (\Exception $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         } catch (\Error $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         }
     }

+ 4 - 2
Events/Libevent.php

@@ -13,6 +13,8 @@
  */
 namespace Workerman\Events;
 
+use Workerman\Worker;
+
 /**
  * libevent eventloop
  */
@@ -170,10 +172,10 @@ class Libevent implements EventInterface
         try {
             call_user_func_array($this->_eventTimer[$timer_id][0], $this->_eventTimer[$timer_id][1]);
         } catch (\Exception $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         } catch (\Error $e) {
-            echo $e;
+            Worker::log($e);
             exit(250);
         }
         if (isset($this->_eventTimer[$timer_id]) && $this->_eventTimer[$timer_id][3] === self::EV_TIMER_ONCE) {

+ 9 - 8
Protocols/Websocket.php

@@ -14,6 +14,7 @@
 namespace Workerman\Protocols;
 
 use Workerman\Connection\ConnectionInterface;
+use Workerman\Worker;
 
 /**
  * WebSocket protocol.
@@ -90,10 +91,10 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                         try {
                             call_user_func($connection->onWebSocketClose, $connection);
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     } // Close connection.
@@ -108,10 +109,10 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                         try {
                             call_user_func($connection->onWebSocketPing, $connection);
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     } // Send pong package to client.
@@ -135,10 +136,10 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                         try {
                             call_user_func($connection->onWebSocketPong, $connection);
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     }
@@ -346,10 +347,10 @@ class Websocket implements \Workerman\Protocols\ProtocolInterface
                 try {
                     call_user_func($connection->onWebSocketConnect, $connection, $buffer);
                 } catch (\Exception $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 }
                 $_GET = $_COOKIE = $_SERVER = array();

+ 10 - 8
Protocols/Ws.php

@@ -1,6 +1,8 @@
 <?php
 namespace Workerman\Protocols;
 
+use Workerman\Worker;
+
 /**
  * Websocket protocol for client.
  */
@@ -76,10 +78,10 @@ class Ws
                         try {
                             call_user_func($connection->onWebSocketClose, $connection);
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     } // Close connection.
@@ -94,10 +96,10 @@ class Ws
                         try {
                             call_user_func($connection->onWebSocketPing, $connection);
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     } // Send pong package to client.
@@ -120,10 +122,10 @@ class Ws
                         try {
                             call_user_func($connection->onWebSocketPong, $connection);
                         } catch (\Exception $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         } catch (\Error $e) {
-                            echo $e;
+                            Worker::log($e);
                             exit(250);
                         }
                     }
@@ -319,10 +321,10 @@ class Ws
                 try {
                     call_user_func($connection->onWebSocketConnect, $connection, substr($buffer, 0, $handshake_respnse_length));
                 } catch (\Exception $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    Worker::log($e);
                     exit(250);
                 }
             }

+ 2 - 2
WebServer.php

@@ -108,10 +108,10 @@ class WebServer extends Worker
             try {
                 call_user_func($this->_onWorkerStart, $this);
             } catch (\Exception $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             }
         }

+ 11 - 11
Worker.php

@@ -1110,10 +1110,10 @@ class Worker
                 try {
                     call_user_func($worker->onWorkerReload, $worker);
                 } catch (\Exception $e) {
-                    echo $e;
+                    self::log($e);
                     exit(250);
                 } catch (\Error $e) {
-                    echo $e;
+                    self::log($e);
                     exit(250);
                 }
             }
@@ -1291,7 +1291,7 @@ class Worker
      * @param string $msg
      * @return void
      */
-    protected static function log($msg)
+    public static function log($msg)
     {
         $msg = $msg . "\n";
         if (!self::$daemonize) {
@@ -1460,10 +1460,10 @@ class Worker
             try {
                 call_user_func($this->onWorkerStart, $this);
             } catch (\Exception $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             }
         }
@@ -1484,10 +1484,10 @@ class Worker
             try {
                 call_user_func($this->onWorkerStop, $this);
             } catch (\Exception $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             }
         }
@@ -1527,10 +1527,10 @@ class Worker
             try {
                 call_user_func($this->onConnect, $connection);
             } catch (\Exception $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             }
         }
@@ -1560,10 +1560,10 @@ class Worker
             try {
                 call_user_func($this->onMessage, $connection, $recv_buffer);
             } catch (\Exception $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             } catch (\Error $e) {
-                echo $e;
+                self::log($e);
                 exit(250);
             }
         }