replace echo with Log:: calls
authorChristian Weiske <cweiske@cweiske.de>
Tue, 13 Sep 2016 15:03:48 +0000 (17:03 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 13 Sep 2016 15:03:48 +0000 (17:03 +0200)
src/shpub/Cli.php
src/shpub/Command/Connect.php
src/shpub/Command/Like.php
src/shpub/Command/Note.php
src/shpub/Command/Reply.php
src/shpub/Command/Server.php
src/shpub/Log.php
src/shpub/Request.php

index 12eeaed..30c2d1f 100644 (file)
@@ -41,7 +41,7 @@ class Cli
                 break;
             }
         } catch (\Exception $e) {
-            echo 'Error: ' . $e->getMessage() . "\n";
+            Log::err('Error: ' . $e->getMessage());
             exit(1);
         }
     }
index 668d7e9..2fd6d38 100644 (file)
@@ -36,9 +36,10 @@ class Command_Connect
 
         list($redirect_uri, $socketStr) = $this->getHttpServerData();
         $state = time();
-        echo "To authenticate, open the following URL:\n"
+        Log::msg(
+            "To authenticate, open the following URL:\n"
             . $this->getBrowserAuthUrl($host, $user, $redirect_uri, $state)
-            . "\n";
+        );
 
         $authParams = $this->startHttpServer($socketStr);
         if ($authParams['state'] != $state) {
@@ -72,7 +73,7 @@ class Command_Connect
         }
         $this->cfg->hosts[$hostKey] = $host;
         $this->cfg->save();
-        echo "Server configuration $hostKey saved successfully.\n";
+        Log::info("Server configuration $hostKey saved successfully.");
     }
 
     protected function fetchAccessToken(
index fb396be..5b456f9 100644 (file)
@@ -46,8 +46,8 @@ class Command_Like extends Command_AbstractProps
             Log::err($res->getBody());
             exit(20);
         } else {
-            echo "Like created at server\n";
-            echo $postUrl . "\n";
+            Log::info('Like created at server');
+            Log::msg($postUrl);
         }
     }
 }
index de67948..1ea599b 100644 (file)
@@ -36,8 +36,8 @@ class Command_Note extends Command_AbstractProps
 
         $res = $req->send();
         $postUrl = $res->getHeader('Location');
-        echo "Post created at server\n";
-        echo $postUrl . "\n";
+        Log::info('Post created at server');
+        Log::msg($postUrl);
     }
 }
 ?>
index e84a055..b67d46b 100644 (file)
@@ -50,8 +50,8 @@ class Command_Reply extends Command_AbstractProps
         $res = $req->send();
 
         $postUrl = $res->getHeader('Location');
-        echo "Reply created at server\n";
-        echo $postUrl . "\n";
+        Log::info('Reply created at server');
+        Log::msg($postUrl);
     }
 }
 ?>
index 59843d4..8553414 100644 (file)
@@ -11,10 +11,10 @@ class Command_Server
     public function run($verbose)
     {
         foreach ($this->cfg->hosts as $key => $host) {
-            echo $key . "\n";
+            Log::msg($key);
             if ($verbose) {
-                echo '  URL:  ' . $host->server . "\n";
-                echo '  User: ' . $host->user . "\n";
+                Log::msg('  URL:  ' . $host->server);
+                Log::msg('  User: ' . $host->user);
             }
         }
     }
index 99d9694..7b9dc71 100644 (file)
@@ -3,6 +3,16 @@ namespace shpub;
 
 class Log
 {
+    public static function info($msg)
+    {
+        echo $msg . "\n";
+    }
+
+    public static function msg($msg)
+    {
+        echo $msg . "\n";
+    }
+
     public static function err($msg)
     {
         file_put_contents('php://stderr', $msg . "\n", FILE_APPEND);
index 0924dda..8ee7c5a 100644 (file)
@@ -114,6 +114,6 @@ class Request
 
         $command .= ' ' . escapeshellarg((string) $this->req->getUrl());
 
-        echo $command . "\n";
+        Log::msg($command);
     }
 }
\ No newline at end of file