library/log4php/appenders/LoggerAppenderFirePHP.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Licensed to the Apache Software Foundation (ASF) under one or more
       
     4  * contributor license agreements.  See the NOTICE file distributed with
       
     5  * this work for additional information regarding copyright ownership.
       
     6  * The ASF licenses this file to You under the Apache License, Version 2.0
       
     7  * (the "License"); you may not use this file except in compliance with
       
     8  * the License.  You may obtain a copy of the License at
       
     9  *
       
    10  *     http://www.apache.org/licenses/LICENSE-2.0
       
    11  *
       
    12  * Unless required by applicable law or agreed to in writing, software
       
    13  * distributed under the License is distributed on an "AS IS" BASIS,
       
    14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    15  * See the License for the specific language governing permissions and
       
    16  * limitations under the License.
       
    17  */
       
    18 
       
    19 /**
       
    20  * Logs messages as HTTP headers using the FirePHP Insight API.
       
    21  *
       
    22  * This appender requires the FirePHP server library version 1.0 or later.
       
    23  *
       
    24  * ## Configurable parameters: ##
       
    25  *
       
    26  * - **target** - (string) The target to which messages will be sent. Possible options are
       
    27  *            'page' (default), 'request', 'package' and 'controller'. For more details,
       
    28  *            see FirePHP documentation.
       
    29  *
       
    30  * This class was originally contributed by Bruce Ingalls (Bruce.Ingalls-at-gmail-dot-com).
       
    31  *
       
    32  * @link https://github.com/firephp/firephp FirePHP homepage.
       
    33  * @link http://sourcemint.com/github.com/firephp/firephp/1:1.0.0b1rc6/-docs/Welcome FirePHP documentation.
       
    34  * @link http://sourcemint.com/github.com/firephp/firephp/1:1.0.0b1rc6/-docs/Configuration/Constants FirePHP constants documentation.
       
    35  * @link http://logging.apache.org/log4php/docs/appenders/firephp.html Appender documentation
       
    36  *
       
    37  * @version $Revision: 1343684 $
       
    38  * @package log4php
       
    39  * @subpackage appenders
       
    40  * @since 2.3
       
    41  */
       
    42 class LoggerAppenderFirePHP extends LoggerAppender {
       
    43 
       
    44     /**
       
    45      * Instance of the Insight console class.
       
    46      * @var Insight_Plugin_Console
       
    47      */
       
    48     protected $console;
       
    49 
       
    50     /**
       
    51      * The target for log messages. Possible values are: 'page' (default),
       
    52      * 'request', 'package' and 'contoller'.
       
    53      */
       
    54     protected $target = 'page';
       
    55 
       
    56     public function activateOptions() {
       
    57         if (method_exists('FirePHP', 'to')) {
       
    58             $this->console = FirePHP::to($this->target)->console();
       
    59             $this->closed = false;
       
    60         } else {
       
    61             $this->warn('FirePHP is not installed correctly. Closing appender.');
       
    62         }
       
    63     }
       
    64 
       
    65     public function append(LoggerLoggingEvent $event) {
       
    66         $msg = $event->getMessage();
       
    67 
       
    68         // Skip formatting for objects and arrays which are handled by FirePHP.
       
    69         if (!is_array($msg) && !is_object($msg)) {
       
    70             $msg = $this->getLayout()->format($event);
       
    71         }
       
    72 
       
    73         switch ($event->getLevel()->toInt()) {
       
    74             case LoggerLevel::TRACE:
       
    75             case LoggerLevel::DEBUG:
       
    76                 $this->console->log($msg);
       
    77                 break;
       
    78             case LoggerLevel::INFO:
       
    79                 $this->console->info($msg);
       
    80                 break;
       
    81             case LoggerLevel::WARN:
       
    82                 $this->console->warn($msg);
       
    83                 break;
       
    84             case LoggerLevel::ERROR:
       
    85             case LoggerLevel::FATAL:
       
    86                 $this->console->error($msg);
       
    87                 break;
       
    88         }
       
    89     }
       
    90 
       
    91     /** Returns the target. */
       
    92     public function getTarget() {
       
    93         return $this->target;
       
    94     }
       
    95 
       
    96     /** Sets the target. */
       
    97     public function setTarget($target) {
       
    98         $this->setString('target', $target);
       
    99     }
       
   100 }