Browse Source

Truncate arguments and remove LFs in logging output

Fixes issue #10
tags/0.6
Chris Smith 15 years ago
parent
commit
8c72eeb438
1 changed files with 11 additions and 0 deletions
  1. 11
    0
      logging.inc.php

+ 11
- 0
logging.inc.php View File

@@ -26,6 +26,7 @@ class Logger {
26 26
 
27 27
  const ENABLE_LOGGING = true;
28 28
  const LOGGING_FILENAME = '/tmp/poidsy-debug.log';
29
+ const TRUNCATE_ARGS = true;
29 30
 
30 31
  private static $fh;
31 32
 
@@ -44,9 +45,19 @@ class Logger {
44 45
  protected static function getCaller() {
45 46
   $trace = debug_backtrace(); // First two will be log and getCaller
46 47
   $trace = $trace[2];
48
+
49
+  array_walk($trace['args'], array('Logger', 'formatArg'));
50
+
47 51
   return sprintf('%s:%s %s%s%s(%s)', basename($trace['file']), $trace['line'], $trace['class'], $trace['type'], $trace['function'], implode(', ', $trace['args']));
48 52
  }
49 53
 
54
+ protected static function formatArg(&$value, $key) {
55
+  if (strlen($value) > 30 && self::TRUNCATE_ARGS) {
56
+   $value = substr($value, 0, 27) . '...';
57
+  }
58
+  $value = str_replace("\n", '  ', $value);
59
+ }
60
+
50 61
 }
51 62
 
52 63
 ?>

Loading…
Cancel
Save