From 5c0d922ddb2b7ab38058e655ecb904b5a85230a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gon=C3=A7alo=20Queir=C3=B3s?= <goncalo.queiros@portugalmail.net>
Date: Tue, 2 Aug 2011 11:08:35 +0100
Subject: [PATCH] Make every log handler, handle the message ident on their own

---
 framework/Core/lib/Horde/Core/Factory/Logger.php   |    1 +
 framework/Core/lib/Horde/Core/Log/Logger.php       |    3 +--
 .../lib/Horde/Kolab/Filter/Factory.php             |    3 ++-
 framework/Log/lib/Horde/Log/Handler/Firebug.php    |    7 ++++++-
 framework/Log/lib/Horde/Log/Handler/Scribe.php     |    7 ++++++-
 framework/Log/lib/Horde/Log/Handler/Stream.php     |   12 ++++++++++++
 6 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/framework/Core/lib/Horde/Core/Factory/Logger.php b/framework/Core/lib/Horde/Core/Factory/Logger.php
index 355fdd7..de76856 100644
--- a/framework/Core/lib/Horde/Core/Factory/Logger.php
+++ b/framework/Core/lib/Horde/Core/Factory/Logger.php
@@ -53,6 +53,7 @@ class Horde_Core_Factory_Logger extends Horde_Core_Factory_Injector
 
             try {
                 $handler = new Horde_Log_Handler_Stream($conf['log']['name'], $append, $formatter);
+                $handler->setOption('ident', $conf['log']['ident']);
             } catch (Horde_Log_Exception $e) {
                 $this->error = $e;
                 return new Horde_Core_Log_Logger(new Horde_Log_Handler_Null());
diff --git a/framework/Core/lib/Horde/Core/Log/Logger.php b/framework/Core/lib/Horde/Core/Log/Logger.php
index a5b1cc5..315e95c 100644
--- a/framework/Core/lib/Horde/Core/Log/Logger.php
+++ b/framework/Core/lib/Horde/Core/Log/Logger.php
@@ -107,8 +107,7 @@ class Horde_Core_Log_Logger extends Horde_Log_Logger
             ? $GLOBALS['registry']->getApp()
             : 'horde';
 
-        $message = (empty($GLOBALS['conf']['log']['ident']) ? '' : $GLOBALS['conf']['log']['ident'] . ' ') .
-            ($app ? '[' . $app . '] ' : '') .
+        $message = ($app ? '[' . $app . '] ' : '') .
             $text .
             ' [pid ' . getmypid() . ' on line ' . $line . ' of "' . $file . '"]';
 
diff --git a/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Factory.php b/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Factory.php
index 7318b66..1528c84 100644
--- a/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Factory.php
+++ b/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Factory.php
@@ -69,6 +69,7 @@ class Horde_Kolab_Filter_Factory
 
             try {
                 $handler = new Horde_Log_Handler_Stream($conf['log']['name'], $append, $formatter);
+                $this->setOption('ident', $conf['log']['ident']);
             } catch (Horde_Log_Exception $e) {
                 return new Horde_Log_Logger(new Horde_Log_Handler_Null());
             }
@@ -120,4 +121,4 @@ class Horde_Kolab_Filter_Factory
             new Horde_Kolab_Server_Schema_Base()
         );
     }
-}
\ No newline at end of file
+}
diff --git a/framework/Log/lib/Horde/Log/Handler/Firebug.php b/framework/Log/lib/Horde/Log/Handler/Firebug.php
index f9e9761..a2642d8 100644
--- a/framework/Log/lib/Horde/Log/Handler/Firebug.php
+++ b/framework/Log/lib/Horde/Log/Handler/Firebug.php
@@ -33,7 +33,8 @@ class Horde_Log_Handler_Firebug extends Horde_Log_Handler_Base
      * @var array
      */
     protected $_options = array(
-        'buffering' => false
+        'buffering' => false,
+        'ident' => ''
     );
 
     /**
@@ -84,6 +85,10 @@ class Horde_Log_Handler_Firebug extends Horde_Log_Handler_Base
      */
     public function write($event)
     {
+        if (!empty($this->_options['ident'])) {
+            $event['message'] = $this->_options['ident'] . ' ' . $event['message'];
+        }
+
         $this->_buffer[] = $event;
 
         if (empty($this->_options['buffering'])) {
diff --git a/framework/Log/lib/Horde/Log/Handler/Scribe.php b/framework/Log/lib/Horde/Log/Handler/Scribe.php
index 8638f94..2972547 100644
--- a/framework/Log/lib/Horde/Log/Handler/Scribe.php
+++ b/framework/Log/lib/Horde/Log/Handler/Scribe.php
@@ -41,7 +41,8 @@ class Horde_Log_Handler_Scribe extends Horde_Log_Handler_Base
      */
     protected $_options = array(
         'addNewline' => false,
-        'category'   => 'default'
+        'category'   => 'default',
+        'ident' => ''
     );
 
     /**
@@ -68,6 +69,10 @@ class Horde_Log_Handler_Scribe extends Horde_Log_Handler_Base
      */
     public function write($event)
     {
+        if (!empty($this->_options['ident'])) {
+            $event['message'] = $this->_options['ident'] . ' ' . $event['message'];
+        }
+
         $category = isset($event['category'])
             ? $event['category']
             : $this->_options['category'];
diff --git a/framework/Log/lib/Horde/Log/Handler/Stream.php b/framework/Log/lib/Horde/Log/Handler/Stream.php
index 760bafd..c6b3182 100644
--- a/framework/Log/lib/Horde/Log/Handler/Stream.php
+++ b/framework/Log/lib/Horde/Log/Handler/Stream.php
@@ -25,6 +25,15 @@
 class Horde_Log_Handler_Stream extends Horde_Log_Handler_Base
 {
     /**
+     * Options to be set by setOption().
+     *
+     * @var array
+     */
+    protected $_options = array(
+        'ident'            => ''
+    );
+
+    /**
      * Formats the log message before writing.
      *
      * @var Horde_Log_Formatter
@@ -109,6 +118,9 @@ class Horde_Log_Handler_Stream extends Horde_Log_Handler_Base
      */
     public function write($event)
     {
+        if (!empty($this->_options['ident'])) {
+            $event['message'] = $this->_options['ident'] . ' ' . $event['message'];
+        }
         $line = $this->_formatter->format($event);
 
         if (!@fwrite($this->_stream, $line)) {
-- 
1.7.1