From a8c9fffed4cb58d611499d68cb8c000759d44d02 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 10 Oct 2013 10:18:03 +0100 Subject: [PATCH] Appending to debug.log file Until now debug.log files were loaded into memory, concatenated and then re-written to disk. This is an intensive operation on a large file. I've added the `FILE_APPEND` flag to append to this file instead. --- dev/Debug.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dev/Debug.php b/dev/Debug.php index fc3512bb0..1d3f98f07 100644 --- a/dev/Debug.php +++ b/dev/Debug.php @@ -205,11 +205,16 @@ class Debug { * @param $message string to output */ public static function log($message) { - $file = dirname(__FILE__).'/../../debug.log'; + if (defined('BASE_PATH')) { + $path = BASE_PATH; + } + else { + $path = dirname(__FILE__) . '/../..'; + } + $file = $path . '/debug.log'; $now = date('r'); - $oldcontent = (file_exists($file)) ? file_get_contents($file) : ''; - $content = $oldcontent . "\n\n== $now ==\n$message\n"; - file_put_contents($file, $content); + $content = "\n\n== $now ==\n$message\n"; + file_put_contents($file, $content, FILE_APPEND); } /**