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:59 UTC
cvs commit: logging-log4php/src/tests/loggers/configs MyLogger.properties MyLogger.xml
marco 2004/03/08 13:22:59
Added: src/tests/loggers MyLogger.php MyLoggerFactory.php test.php
test_body.php
src/tests/loggers/configs MyLogger.properties MyLogger.xml
Log:
Initial Import
Revision Changes Path
1.1 logging-log4php/src/tests/loggers/MyLogger.php
Index: MyLogger.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 loggers
* @version $Revision: 1.1 $
* @since 0.6
*/
/**
*/
require_once('./MyLoggerFactory.php');
/**
* A simple example showing logger subclassing.
*
* @package tests
* @subpackage loggers
* @author Marco V. <ma...@apache.org>
* @version $Revision: 1.1 $
* @since 0.6
*/
class MyLogger extends Logger {
var $fqcn = "MyLogger.";
/**
* Just calls the parent constuctor.
*
* @param string $name
*/
function MyLogger($name)
{
$this->Logger($name);
}
/**
* Overrides the standard debug method by appending " world" at the
* end of each message.
*
* @param mixed $message
* @param mixed $caller
*/
function debug($message, $caller = null)
{
if (is_string($message)) {
$this->log(LoggerLevel::getLevelDebug(), $message . ' Hi, by MyLogger.', $caller);
} else {
$this->log(LoggerLevel::getLevelDebug(), $message, $caller);
}
}
/**
* This method overrides {@link Logger#getInstance} by supplying
* its own factory type as a parameter.
*
* @param string $name
* @return Logger
* @static
*/
function getInstance($name)
{
return Logger::getLogger($name, MyLogger::getMyFactory());
}
/**
* This method overrides {@link Logger#getLogger} by supplying
* its own factory type as a parameter.
*
* @param string $name
* @return Logger
* @static
*
*/
function getLogger($name)
{
return Logger::getLogger($name, MyLogger::getMyFactory());
}
/**
* @return LoggerFactory
* @static
*/
function getMyFactory()
{
static $factory;
if (!isset($factory))
$factory = new MyLoggerFactory();
return $factory;
}
}
?>
1.1 logging-log4php/src/tests/loggers/MyLoggerFactory.php
Index: MyLoggerFactory.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 loggers
* @version $Revision: 1.1 $
* @since 0.6
*/
/**
*/
require_once(LOG4PHP_DIR . '/spi/LoggerFactory.php');
require_once('./MyLogger.php');
/**
* A factory that makes new {@link MyLogger} objects.
*
* @package tests
* @subpackage loggers
* @author Marco V. <ma...@apache.org>
* @version $Revision: 1.1 $
* @since 0.6
*/
class MyLoggerFactory extends LoggerFactory {
/**
* The constructor should be public as it will be called by
* configurators in different packages.
*/
function MyLoggerFactory()
{
return;
}
/**
* @param string $name
* @return Logger
*/
function makeNewLoggerInstance($name)
{
return new MyLogger($name);
}
}
?>
1.1 logging-log4php/src/tests/loggers/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 loggers
* @version $Revision: 1.1 $
* @since 0.6
*/
/**
* @var array Test array
*/
$tests = array(
'MyLogger_01' => array(
'__COMMENT__' => 'Configured using LoggerPropertyConfigurator. Note "Hi, by MyLogger" in DEBUG/MyTest.',
'LOG4PHP_CONFIGURATION' => './configs/MyLogger.properties'
),
'MyLogger_02' => array(
'__COMMENT__' => 'Configured using LoggerDOMConfigurator. Note "Hi, by MyLogger" in DEBUG/MyTest.',
'LOG4PHP_CONFIGURATION' => './configs/MyLogger.xml'
),
);
require_once('../test_core.php');
?>
1.1 logging-log4php/src/tests/loggers/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 loggers
* @version $Revision: 1.1 $
* @since 0.6
*/
/**
*/
require_once('./MyLogger.php');
$mylogger =& MyLogger::getInstance("myTest");
$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');
?>
1.1 logging-log4php/src/tests/loggers/configs/MyLogger.properties
Index: MyLogger.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=DEBUG, A1
log4php.appender.A1=LoggerAppenderEcho
log4php.appender.A1.layout=LoggerLayoutHtml
log4php.appender.A1.layout.locationInfo = "true"
log4php.logger.Test=INFO
log4php.logger.Test.Test=WARN
log4php.logger.bar=ERROR
log4php.logger.main=FATAL
1.1 logging-log4php/src/tests/loggers/configs/MyLogger.xml
Index: MyLogger.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="DEBUG" />
<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>