You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by ma...@apache.org on 2004/03/08 22:22:43 UTC

cvs commit: logging-log4php/src/tests/levels MyLoggerLevel.php test.php test_body.php

marco       2004/03/08 13:22:43

  Added:       src/tests/levels/configs LoggerLevel_01.properties
                        LoggerLevel_02.xml LoggerLevel_03.properties
               src/tests/levels MyLoggerLevel.php test.php test_body.php
  Log:
  Initial Import
  
  Revision  Changes    Path
  1.1                  logging-log4php/src/tests/levels/configs/LoggerLevel_01.properties
  
  Index: LoggerLevel_01.properties
  ===================================================================
  ;   Copyright 2004 The Apache Software Foundation.
  ;
  ;   This software is published under the terms of the Apache Software
  ;   License version 2.0, a copy of which has been included with this
  ;   distribution in the LICENSE file.
  ;
  ;   @author Marco V. <ma...@apache.org>
  ;   @version $Revision: 1.1 $
  ;   @since 0.5
  ;
  log4php.debug = false
  log4php.rootLogger=ALL, A1
  log4php.appender.A1=LoggerAppenderEcho
  log4php.appender.A1.layout=LoggerLayoutHtml
  log4php.logger.Test=INFO
  log4php.logger.Test.Test=WARN
  log4php.logger.bar=ERROR
  log4php.logger.main=FATAL
  
  
  
  
  1.1                  logging-log4php/src/tests/levels/configs/LoggerLevel_02.xml
  
  Index: LoggerLevel_02.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!--
      Copyright 2004 The Apache Software Foundation.
  
      This software is published under the terms of the Apache Software
      License version 2.0, a copy of which has been included with this
      distribution in the LICENSE file.
   
      @author Marco V. <ma...@apache.org>
      @version $Revision: 1.1 $
      @since 0.5
  -->
  <log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/" threshold="all" debug="false">
      <log4php:appender name="A1" class="LoggerAppenderEcho">
          <layout class="LoggerLayoutHtml" />
      </log4php:appender>
  
      <log4php:root>
          <log4php:level value="ALL" />
          <log4php:appender_ref ref="A1" />        
      </log4php:root>
  
      <log4php:logger name="Test">
          <log4php:level value="INFO" />
      </log4php:logger>
      
      <log4php:logger name="Test.Test">
          <log4php:level value="WARN" />
      </log4php:logger>
      
      <log4php:logger name="bar">
          <log4php:level value="ERROR" />
      </log4php:logger>
      
      <log4php:logger name="main">        
          <log4php:level value="FATAL" />
      </log4php:logger>
  </log4php:configuration>
  
  
  
  1.1                  logging-log4php/src/tests/levels/configs/LoggerLevel_03.properties
  
  Index: LoggerLevel_03.properties
  ===================================================================
  ;   Copyright 2004 The Apache Software Foundation.
  ;
  ;   This software is published under the terms of the Apache Software
  ;   License version 2.0, a copy of which has been included with this
  ;   distribution in the LICENSE file.
  ;
  ;   @author Marco V. <ma...@apache.org>
  ;   @version $Revision: 1.1 $
  ;   @since 0.5
  ;
  log4php.debug = "false"
  log4php.rootLogger=ALL, A1
  log4php.appender.A1=LoggerAppenderEcho
  log4php.appender.A1.layout=LoggerLayoutHtml
  log4php.appender.A1.layout.locationInfo= "true"
  log4php.logger.Test=INFO
  log4php.logger.Test.Test=LETHAL#MyLoggerLevel
  log4php.logger.bar=ERROR
  log4php.logger.main=FATAL
  
  
  
  
  1.1                  logging-log4php/src/tests/levels/MyLoggerLevel.php
  
  Index: MyLoggerLevel.php
  ===================================================================
  <?php
  /**
   * Copyright 2004 The Apache Software Foundation.
   *
   * This software is published under the terms of the Apache Software
   * License version 2.0, a copy of which has been included with this
   * distribution in the LICENSE file.
   * 
   * @package tests
   * @author Marco V. <ma...@apache.org>
   * @subpackage levels
   * @version $Revision: 1.1 $
   * @since 0.6
   */
   
  /**
   */
  define('LOG4PHP_LEVEL_TRACE_INT',        LOG4PHP_LEVEL_DEBUG_INT - 1); 
  define('LOG4PHP_LEVEL_LETHAL_INT',       LOG4PHP_LEVEL_FATAL_INT + 1);
  
  
  /**
   * This class introduces a new level level called TRACE. TRACE has
   * lower level than DEBUG.
   *
   * @package tests
   * @subpackage levels
   * @author Marco V. <ma...@apache.org>
   * @version $Revision: 1.1 $
   * @since 0.6
   */
  class MyLoggerLevel extends LoggerLevel {
  
      /**
       * @param integer $level
       * @param string $strLevel
       * @param integer $syslogEquiv
       */
      function MyLoggerLevel($level, $strLevel, $syslogEquiv)
      {
          $this->LoggerLevel($level, $strLevel, $syslogEquiv);
      }
      
      /**
       * Returns a TRACE Level
       * @static
       * @return LoggerLevel
       */
      function getLevelTrace()
      {
          static $level;
          if (!isset($level)) $level = new MyLoggerLevel(LOG4PHP_LEVEL_TRACE_INT, 'TRACE', 7);
          return $level;
      }
      
      /**
       * Returns a LETHAL Level
       * @static
       * @return LoggerLevel
       */
      function getLevelLethal()
      {
          static $level;
          if (!isset($level)) $level = new MyLoggerLevel(LOG4PHP_LEVEL_LETHAL_INT, 'LETHAL', 0);
          return $level;
      }
  
      /**
       * Convert the string passed as argument to a level. If the
       * conversion fails, then this method returns a TRACE Level.
       *
       * @param mixed $arg
       * @param LoggerLevel $defaultLevel
       * @static 
       */
      function toLevel($arg, $defaultLevel = null)
      {
          if ($arg === null) {
              return $defaultLevel;
          }
          if (is_int($arg)) {
              switch($arg) {
                  case LOG4PHP_LEVEL_TRACE_INT:   return MyLoggerLevel::getLevelTrace();
                  case LOG4PHP_LEVEL_LETHAL_INT:  return MyLoggerLevel::getLevelLethal();
                  default:                        return LoggerLevel::toLevel($arg, $defaultLevel);
              }
          } else {
              switch(strtoupper($arg)) {
                  case 'TRACE':   return MyLoggerLevel::getLevelTrace();
                  case 'LETHAL':  return MyLoggerLevel::getLevelLethal();
                  default:        return LoggerLevel::toLevel($arg, $defaultLevel);
              }
          }
      } 
  }
  ?>
  
  
  1.1                  logging-log4php/src/tests/levels/test.php
  
  Index: test.php
  ===================================================================
  <?php
  /**
   * Copyright 2004 The Apache Software Foundation.
   *
   * This software is published under the terms of the Apache Software
   * License version 2.0, a copy of which has been included with this
   * distribution in the LICENSE file.
   * 
   * @package tests
   * @author Marco V. <ma...@apache.org>
   * @subpackage levels
   * @version $Revision: 1.1 $
   * @since 0.5
   */
  
  /**
   * @var array Test array
   */
  $tests = array(
      'LoggerLevel_01'     => array(
          'LOG4PHP_CONFIGURATION' => './configs/LoggerLevel_01.properties'
       ),
      'LoggerLevel_02'     => array(
          'LOG4PHP_CONFIGURATION' => './configs/LoggerLevel_02.xml'
       ),
      'LoggerLevel_03'     => array(
          'LOG4PHP_CONFIGURATION' => './configs/LoggerLevel_03.properties',
          'INCLUDES'              => './MyLoggerLevel.php'
       ),
  );
  
  require_once('../test_core.php');
  
  ?>
  
  
  1.1                  logging-log4php/src/tests/levels/test_body.php
  
  Index: test_body.php
  ===================================================================
  <?php
  /**
   * Copyright 2004 The Apache Software Foundation.
   *
   * This software is published under the terms of the Apache Software
   * License version 2.0, a copy of which has been included with this
   * distribution in the LICENSE file.
   * 
   * @package tests
   * @author Marco V. <ma...@apache.org>
   * @subpackage levels
   * @version $Revision: 1.1 $
   * @since 0.6
   */
  
  /**
   */
  require_once('./MyLoggerLevel.php');
   
  $mylogger =& LoggerManager::getLogger('mylogger');
  
  $mylogger->log(MyLoggerLevel::getLevelTrace(), 'this is a TRACE log generated by main() function');
  $mylogger->debug('this is a DEBUG log generated by main() function');
  $mylogger->info('this is an INFO log generated by main() function');
  $mylogger->warn('this is a WARN log generated by main() function');
  $mylogger->error('this is an ERROR log generated by main() function');
  $mylogger->fatal('this is a FATAL log generated by main() function');
  $mylogger->log(MyLoggerLevel::getLevelLethal(), 'this is a LETHAL log generated by main() function');
  
  ?>