← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1785: [logging] Include date and time in CLI logging output

 

------------------------------------------------------------
revno: 1785
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt
timestamp: Sat 2010-10-02 14:42:23 +0200
message:
  [logging] Include date and time in CLI logging output
  
  Also don't use the STDERR constant unconditionally, since it
  is not defined when running under Apache (only in CLI mode).
modified:
  logging/loghandlers.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription
=== modified file 'logging/loghandlers.lib.php'
--- logging/loghandlers.lib.php	2010-03-26 21:34:27 +0000
+++ logging/loghandlers.lib.php	2010-10-02 12:42:23 +0000
@@ -86,20 +86,27 @@
  * error.log or error_log).
  *
  * For command line applications the message will be written to the standard
- * error output (stderr). In interactive terminals, the output will be colored
- * using ANSI escape codes.
+ * error output (stderr), and all messages will be prefixed with the current
+ * date and time. (In a web server context date and time are usually included by
+ * the web server itself).
+ *
+ * In interactive terminals, the output will be colored using ANSI escape codes.
  */
 final class AnewtLogHandlerDefault extends AnewtLogHandlerBase
 {
 	private $stderr_is_tty;
 	private $color_escapes;
 	private $color_reset_escape = '';
+	private $show_ts = false;
 
 	function __construct()
 	{
 		/* Prepare color code escapes if on an interactive tty */
 
-		$this->stderr_is_tty = function_exists('posix_isatty') && posix_isatty(STDERR);
+		$this->stderr_is_tty = defined('STDERR') && function_exists('posix_isatty') && posix_isatty(STDERR);
+
+		if (php_sapi_name() === 'cli');
+			$this->show_ts = true;
 
 		if ($this->stderr_is_tty)
 		{
@@ -142,6 +149,9 @@
 
 		$output[] = $this->color_escapes[$level];
 
+		if ($this->show_ts)
+			$output[] = strftime('[%Y-%m-%d %H:%M:%S] ');
+
 		if ($domain)
 			$output[] = sprintf('(%s) ', $domain);