Do not use STDOUT and STDERR constants
[phinde.git] / src / phinde / Log.php
index 2369a2bc86b8dc0f261dfb921b0ccaded38733c8..7ae0d82ebc70324e2bd3b272b514ecea8619a3f8 100644 (file)
@@ -5,7 +5,7 @@ class Log
 {
     public static function error($msg)
     {
-        static::log($msg);
+        static::log($msg, 'php://stderr');
     }
 
     public static function info($msg)
@@ -15,9 +15,18 @@ class Log
         }
     }
 
-    public static function log($msg)
+    public static function log($msg, $stream = 'php://stdout')
     {
-        echo $msg . "\n";
+        if (isset($GLOBALS['phinde']['logfile'])
+            && $GLOBALS['phinde']['logfile'] != ''
+        ) {
+            file_put_contents(
+                $GLOBALS['phinde']['logfile'],
+                $msg . "\n", FILE_APPEND
+            );
+        } else {
+            fwrite($stream, $msg . "\n");
+        }
     }
 }
 ?>