← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1773: [logging] Do not change whitespace in messages; cleanups

 

------------------------------------------------------------
revno: 1773
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Sun 2010-03-21 15:45:20 +0100
message:
  [logging] Do not change whitespace in messages; cleanups
  
  No longer reformat the logged strings, which means log
  message can now be any string (including newlines).
  
  Also removed some unused left-over cruft that I forgot to
  remove when adding color support.
modified:
  logging/logging.test.php
  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/logging.test.php'
--- logging/logging.test.php	2010-03-20 22:02:02 +0000
+++ logging/logging.test.php	2010-03-21 14:45:20 +0000
@@ -25,5 +25,6 @@
 AnewtLog::message('This is a message');
 AnewtLog::info('This is an info message');
 AnewtLog::debug('This is a debug message');
+AnewtLog::debug("This is a debug message with\nembedded\nnewlines.\n");
 
 ?>

=== modified file 'logging/loghandlers.lib.php'
--- logging/loghandlers.lib.php	2010-03-20 22:02:02 +0000
+++ logging/loghandlers.lib.php	2010-03-21 14:45:20 +0000
@@ -61,37 +61,18 @@
 	 * \return
 	 *   Formatted log string.
 	 */
-	protected function format_log_message($domain=null, $level, $message, $ansi_color_escapes=false)
+	protected function format_log_message($domain=null, $level, $message)
 	{
+		assert('is_null($domain) || is_string($domain)');
 		assert('is_int($level)');
 		assert('is_string($message)');
 
 		$name = AnewtLog::loglevel_to_string($level);
 
-		/* Without logging domain */
 		if (is_null($domain))
-		{
-			$output = sprintf(
-					$ansi_color_escapes ? "\x1b[30;43m\x1b[2K%s: %s" : '%s: %s',
-					$name,
-					$message);
-
-		}
-		/* With logging domain */
+			$output = sprintf('%s: %s', $name, $message);
 		else
-		{
-			assert('is_string($domain)');
-			$output = sprintf(
-					'(%s) %s: %s',
-					$domain,
-					$name,
-					$message);
-		}
-
-		/* Reduce new lines and indentation and make it a single line, since
-		 * error logs should not contain newlines */
-		$output = str_join_wrap($output);
-		$output = str_replace("\n", ' ', $output);
+			$output = sprintf('(%s) %s: %s', $domain, $name, $message);
 
 		return $output;
 	}
@@ -125,23 +106,23 @@
 			$this->color_reset_escape = "\x1b[0m";
 
 			$this->color_escapes = array(
-				ANEWT_LOG_LEVEL_ERROR => "\x1b[0;31m", /* Red */
+				ANEWT_LOG_LEVEL_ERROR =>    "\x1b[0;31m", /* Red */
 				ANEWT_LOG_LEVEL_CRITICAL => "\x1b[0;31m", /* Red */
-				ANEWT_LOG_LEVEL_WARNING => "\x1b[0;31m", /* Red */
-				ANEWT_LOG_LEVEL_MESSAGE => "\x1b[0;32m", /* Green */
-				ANEWT_LOG_LEVEL_INFO => "\x1b[0;33m", /* Yellow */
-				ANEWT_LOG_LEVEL_DEBUG => "\x1b[0;33m", /* Yellow */
+				ANEWT_LOG_LEVEL_WARNING =>  "\x1b[0;31m", /* Red */
+				ANEWT_LOG_LEVEL_MESSAGE =>  "\x1b[0;32m", /* Green */
+				ANEWT_LOG_LEVEL_INFO =>     "\x1b[0;33m", /* Yellow */
+				ANEWT_LOG_LEVEL_DEBUG =>    "\x1b[0;33m", /* Yellow */
 			);
 		}
 		else
 		{
 			$this->color_escapes = array(
-				ANEWT_LOG_LEVEL_ERROR => '',
+				ANEWT_LOG_LEVEL_ERROR =>    '',
 				ANEWT_LOG_LEVEL_CRITICAL => '',
-				ANEWT_LOG_LEVEL_WARNING => '',
-				ANEWT_LOG_LEVEL_MESSAGE => '',
-				ANEWT_LOG_LEVEL_INFO => '',
-				ANEWT_LOG_LEVEL_DEBUG => '',
+				ANEWT_LOG_LEVEL_WARNING =>  '',
+				ANEWT_LOG_LEVEL_MESSAGE =>  '',
+				ANEWT_LOG_LEVEL_INFO =>     '',
+				ANEWT_LOG_LEVEL_DEBUG =>    '',
 			);
 		}
 	}