aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-12-23 09:09:31 +0100
committerLaurent Bachelier <laurent@bachelier.name>2010-12-23 19:26:10 +0100
commite72f853dc12767926787fe15bddd298d123c7bd2 (patch)
tree6d1c07d3760313c030c468fdd051d1c00229b954
parentFixed rare case when --kill would not work and spawn would continue (diff)
downloadsymfttpd-e72f853dc12767926787fe15bddd298d123c7bd2.tar.xz
Rationalize output messages
Everything uses log_message() instead of echo. log_message() is now able to output to stderr.
-rw-r--r--lib/bootstrap.php26
-rwxr-xr-xmksymlinks12
-rwxr-xr-xspawn29
3 files changed, 38 insertions, 29 deletions
diff --git a/lib/bootstrap.php b/lib/bootstrap.php
index 0f0e708..0a00738 100644
--- a/lib/bootstrap.php
+++ b/lib/bootstrap.php
@@ -1,10 +1,32 @@
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
+
+/**
+ * Display a message on the standard output
+ * @param string $message
+ * @param boolean $error Treat the message as an error.
+ *
+ * @author Laurent Bachelier <laurent@bachelier.name>
+ */
+function log_message($message, $error = false)
+{
+ if ($error)
+ {
+ file_put_contents('php://stderr', $message."\n");
+ }
+ else
+ {
+ echo $message."\n";
+ }
+}
+
+/* Needed for some weird reason; PHP will not display anything
+ * when there is an uncatched exception. */
function handle_exception($e)
{
- echo "Fatal error:\n";
- echo $e."\n";
+ log_message('Fatal error:', true);
+ log_message($e, true);
exit(1);
}
set_exception_handler('handle_exception');
diff --git a/mksymlinks b/mksymlinks
index 67294a2..3a7701b 100755
--- a/mksymlinks
+++ b/mksymlinks
@@ -28,17 +28,7 @@ function replace_symlink($project_path, $target, $link, $relative = true)
FileTools::mkdirs(dirname($project_path.'/'.$link));
$success = FileTools::symlink($target, $project_path.'/'.$link);
- log_message(' '.$link.' => '.$target.($success ? '' : ' ...FAILED!'));
-}
-
-/**
- * @param string $message
- *
- * @author Laurent Bachelier <laurent@bachelier.name>
- */
-function log_message($message)
-{
- echo $message."\n";
+ log_message(' '.$link.' => '.$target.($success ? '' : ' ...FAILED!'), !$success);
}
/**
diff --git a/spawn b/spawn
index fa9d1b1..4260b06 100755
--- a/spawn
+++ b/spawn
@@ -33,11 +33,11 @@ if (Argument::get('K', 'kill', false))
if ($pid)
{
posix_kill($pid, SIGTERM);
- echo 'Process '.$pid." killed\n";
+ log_message('Process '.$pid.' killed');
exit(0);
}
}
- echo "No running process found\n";
+ log_message('No running process found', true);
exit(1);
}
@@ -64,13 +64,10 @@ try
}
catch (ExecutableNotFoundError $e)
{
- /* Weird and ugly, sadly necessary to be sure
- * something will be shown to the user */
- echo "Required executable not found.\n ";
- echo $e->getMessage();
- echo ' not found in the specified paths: ';
- echo implode(', ', PosixTools::getPaths());
- echo "\n";
+ log_message("Required executable not found.", false);
+ log_message($e->getMessage()
+ . ' not found in the specified paths: '
+ . implode(', ', PosixTools::getPaths()), false);
exit(1);
}
@@ -81,10 +78,10 @@ file_put_contents(
);
// Pretty information. Nothing interesting code-wise.
-echo 'lighttpd started on ';
-echo strlen($options['bind']) ? $options['bind'] : 'all interfaces';
-echo ', port '.$options['port'].'.';
-echo "\n\nAvailable applications:\n";
+log_message('lighttpd started on '
+ . (strlen($options['bind']) ? $options['bind'] : 'all interfaces')
+ . ', port '.$options['port'].'.');
+log_message("\nAvailable applications");
$apps = array();
foreach (new DirectoryIterator($project_path.'/web') as $file)
{
@@ -99,11 +96,11 @@ $host = in_array($options['bind'], array(false, '0.0.0.0', '::'), true)
sort($apps);
foreach ($apps as $app)
{
- echo ' http://'.$host.':'.$options['port'].'/'.$app."\n";
+ log_message(' http://'.$host.':'.$options['port'].'/'.$app);
}
-echo "\nPress Ctrl+C to stop serving.\n";
+log_message("\nPress Ctrl+C to stop serving.");
flush();
passthru($options['lighttpd_cmd'].' -D -f '.escapeshellarg($config_file));
-echo "Terminated\n";
+log_message('Terminated');