List Info

Thread: Log.php




Log.php
user name
2006-12-05 22:02:25
Update of /var/cvs/Geeklog-2.x/Geeklog-2.x/system/libraries
In directory
iowaoutdoors:/tmp/cvs-serv15190/system/libraries

Modified Files:
	Log.php 
Log Message:
Various updates

Index: Log.php
============================================================
=======
RCS file:
/var/cvs/Geeklog-2.x/Geeklog-2.x/system/libraries/Log.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Log.php	1 Jun 2005 20:53:04 -0000	1.1
--- Log.php	5 Dec 2006 22:02:23 -0000	1.2
***************
*** 71,74 ****
--- 71,75 ----
      /**
       * The bitmask of allowed log levels.
+      *
       * var integer
       * access private
***************
*** 84,87 ****
--- 85,104 ----
      var $_listeners = array();
  
+     /**
+      * Maps canonical format keys to position arguments
for use in building
+      * "line format" strings.
+      *
+      * var array
+      * access private
+      */
+     var $_formatMap = array('%'  => '%1$s',
+                             '%'      => '%2$s',
+                             '%'   => '%3$s',
+                             '%'    => '%4$s',
+                             '%'       => '%5$s',
+                             '%'       => '%6$s',
+                             '%'   => '%7$s',
+                             '%{'           => '%%{');
+ 
  
      /**
***************
*** 105,110 ****
       * param int $level        Log messages up to and
including this level.
       *
!      * return object Log       The newly created concrete
Log instance, or an
!      *                          false on an error.
       * access public
       * since Log 1.0
--- 122,127 ----
       * param int $level        Log messages up to and
including this level.
       *
!      * return object Log       The newly created concrete
Log instance, or
!      *                          null on an error.
       * access public
       * since Log 1.0
***************
*** 122,133 ****
           * version of the named class.
           */
!         include_once $classfile;
  
          /* If the class exists, return a new instance of
it. */
          if (class_exists($class)) {
!             return new $class($name, $ident, $conf,
$level);
          }
  
!         return false;
      }
  
--- 139,154 ----
           * version of the named class.
           */
!         if (!class_exists($class)) {
!             include_once $classfile;
!         }
  
          /* If the class exists, return a new instance of
it. */
          if (class_exists($class)) {
!             $obj = &new $class($name, $ident, $conf,
$level);
!             return $obj;
          }
  
!         $null = null;
!         return $null;
      }
  
***************
*** 163,168 ****
       * param int $level        Log messages up to and
including this level.
       *
!      * return object Log       The newly created concrete
Log instance, or an
!      *                          false on an error.
       * access public
       * since Log 1.0
--- 184,189 ----
       * param int $level        Log messages up to and
including this level.
       *
!      * return object Log       The newly created concrete
Log instance, or
!      *                          null on an error.
       * access public
       * since Log 1.0
***************
*** 387,391 ****
                  $message = $message->toString();
              } else if (method_exists($message,
'__tostring')) {
!                 $message = (string)$message;
              } else {
                  $message = print_r($message, true);
--- 408,416 ----
                  $message = $message->toString();
              } else if (method_exists($message,
'__tostring')) {
!                 if (version_compare(PHP_VERSION, '5.0.0',
'ge')) {
!                     $message = (string)$message;
!                 } else {
!                     $message = $message->__toString();
!                 }
              } else {
                  $message = print_r($message, true);
***************
*** 404,407 ****
--- 429,526 ----
  
      /**
+      * Using debug_backtrace(), returns the file, line,
and enclosing function
+      * name of the source code context from which log()
was invoked.
+      *
+      * param   int     $depth  The initial number of frames
we should step
+      *                          back into the trace.
+      *
+      * return  array   Array containing three strings: the
filename, the line,
+      *                  and the function name from which
log() was called.
+      *
+      * access  private
+      * since   Log 1.9.4
+      */
+     function _getBacktraceVars($depth)
+     {
+         /* Start by generating a backtrace from the
current call (here). */
+         $backtrace = debug_backtrace();
+ 
+         /*
+          * If we were ultimately invoked by the composite
handler, we need to
+          * increase our depth one additional level to
compensate.
+          */
+         if (strcasecmp($backtrace[$depth+1]['class'], 'Log_composite') == 0)
{
+             $depth++;
+         }
+ 
+         /*
+          * We're interested in the frame which invoked the
log() function, so
+          * we need to walk back some number of frames into
the backtrace.  The
+          * $depth parameter tells us where to start
looking.   We go one step
+          * further back to find the name of the
encapsulating function from
+          * which log() was called.
+          */
+         $file = $backtrace[$depth]['file'];
+         $line = $backtrace[$depth]['line'];
+         $func = $backtrace[$depth + 1]['function'];
+ 
+         /*
+          * However, if log() was called from one of our
"shortcut" functions,
+          * we're going to need to go back an additional
step.
+          */
+         if (in_array($func, array('emerg', 'alert',
'crit', 'err', 'warning',
+                                   'notice', 'info',
'debug'))) {
+             $file = $backtrace[$depth + 1]['file'];
+             $line = $backtrace[$depth + 1]['line'];
+             $func = $backtrace[$depth + 2]['function'];
+         }
+ 
+         /*
+          * If we couldn't extract a function name (perhaps
because we were
+          * executed from the "main" context),
provide a default value.
+          */
+         if (is_null($func)) {
+             $func = '(none)';
+         }
+ 
+         /* Return a 3-tuple containing (file, line,
function). */
+         return array($file, $line, $func);
+     }
+ 
+     /**
+      * Produces a formatted log line based on a format
string and a set of
+      * variables representing the current log record and
state.
+      *
+      * return  string  Formatted log string.
+      *
+      * access  private
+      * since   Log 1.9.4
+      */
+     function _format($format, $timestamp, $priority,
$message)
+     {
+         /*
+          * If the format string references any of the
backtrace-driven
+          * variables (%5, %6, %7), generate the backtrace
and fetch them.
+          */
+         if (strpos($format, '%5') || strpos($format, '%6')
|| strpos($format, '%7')) {
+             list($file, $line, $func) =
$this->_getBacktraceVars(2);
+         }
+ 
+         /*
+          * Build the formatted string.  We use the
sprintf() function's
+          * "argument swapping" capability to
dynamically select and position
+          * the variables which will ultimately appear in
the log string.
+          */
+         return sprintf($format,
+                        $timestamp,
+                        $this->_ident,
+                       
$this->priorityToString($priority),
+                        $message,
+                        isset($file) ? $file : '',
+                        isset($line) ? $line : '',
+                        isset($func) ? $func : '');
+     }
+ 
+     /**
       * Returns the string representation of a PEAR_LOG_*
integer constant.
       *
***************
*** 429,434 ****
--- 548,583 ----
  
      /**
+      * Returns the the PEAR_LOG_* integer constant for the
given string
+      * representation of a priority name.  This function
performs a
+      * case-insensitive search.
+      *
+      * param string $name      String containing a priority
name.
+      *
+      * return string           The PEAR_LOG_* integer
contstant corresponding
+      *                          the the specified priority
name.
+      *
+      * since   Log 1.9.0
+      */
+     function stringToPriority($name)
+     {
+         $levels = array(
+             'emergency' => PEAR_LOG_EMERG,
+             'alert'     => PEAR_LOG_ALERT,
+             'critical'  => PEAR_LOG_CRIT,
+             'error'     => PEAR_LOG_ERR,
+             'warning'   => PEAR_LOG_WARNING,
+             'notice'    => PEAR_LOG_NOTICE,
+             'info'      => PEAR_LOG_INFO,
+             'debug'     => PEAR_LOG_DEBUG
+         );
+ 
+         return $levels[strtolower($name)];
+     }
+ 
+     /**
       * Calculate the log mask for the given priority.
       *
+      * This method may be called statically.
+      *
       * param integer   $priority   The priority whose mask
will be calculated.
       *
***************
*** 446,458 ****
       * Calculate the log mask for all priorities up to the
given priority.
       *
       * param integer   $priority   The maximum priority
covered by this mask.
       *
!      * return integer  The calculated log mask.
       *
       * access  public
       * since   Log 1.7.0
       */
      function UPTO($priority)
      {
          return ((1 << ($priority + 1)) - 1);
      }
--- 595,649 ----
       * Calculate the log mask for all priorities up to the
given priority.
       *
+      * This method may be called statically.
+      *
       * param integer   $priority   The maximum priority
covered by this mask.
       *
!      * return integer  The resulting log mask.
       *
       * access  public
       * since   Log 1.7.0
+      *
+      * deprecated deprecated since Log 1.9.4; use Log::MAX()
instead
       */
      function UPTO($priority)
      {
+         return Log::MAX($priority);
+     }
+ 
+     /**
+      * Calculate the log mask for all priorities greater
than or equal to the
+      * given priority.  In other words, $priority will be
the lowest priority
+      * matched by the resulting mask.
+      *
+      * This method may be called statically.
+      *
+      * param integer   $priority   The minimum priority
covered by this mask.
+      *
+      * return integer  The resulting log mask.
+      *
+      * access  public
+      * since   Log 1.9.4
+      */
+     function MIN($priority)
+     {
+         return PEAR_LOG_ALL ^ ((1 << $priority) -
1);
+     }
+ 
+     /**
+      * Calculate the log mask for all priorities less than
or equal to the
+      * given priority.  In other words, $priority will be
the highests priority
+      * matched by the resulting mask.
+      *
+      * This method may be called statically.
+      *
+      * param integer   $priority   The maximum priority
covered by this mask.
+      *
+      * return integer  The resulting log mask.
+      *
+      * access  public
+      * since   Log 1.9.4
+      */
+     function MAX($priority)
+     {
          return ((1 << ($priority + 1)) - 1);
      }
***************
*** 632,635 ****
      }
  }
- 
- ?>
--- 823,824 ----

_______________________________________________
geeklog2-cvs mailing list
geeklog2-cvslists.geeklog.net
http://lists.geeklog.net/mailman/listinfo/geeklog2-cvs

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )