You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ih...@apache.org on 2011/12/12 16:41:20 UTC
svn commit: r1213283 - in /logging/log4php/trunk/src: changes/ main/php/
main/php/appenders/ main/php/filters/ main/php/helpers/ main/php/layouts/
test/php/appenders/ test/php/filters/ test/php/layouts/
Author: ihabunek
Date: Mon Dec 12 15:41:19 2011
New Revision: 1213283
URL: http://svn.apache.org/viewvc?rev=1213283&view=rev
Log:
LOG4PHP-161: All configurable components should trigger warnings when given invalid values
Added:
logging/log4php/trunk/src/main/php/LoggerConfigurable.php
Modified:
logging/log4php/trunk/src/changes/changes.xml
logging/log4php/trunk/src/main/php/Logger.php
logging/log4php/trunk/src/main/php/LoggerAppender.php
logging/log4php/trunk/src/main/php/LoggerFilter.php
logging/log4php/trunk/src/main/php/LoggerLayout.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderEcho.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMail.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSocket.php
logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSyslog.php
logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelMatch.php
logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelRange.php
logging/log4php/trunk/src/main/php/filters/LoggerFilterStringMatch.php
logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutPattern.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSerialized.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSimple.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutTTCC.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutXml.php
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php
logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php
logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php
logging/log4php/trunk/src/test/php/layouts/LoggerLayoutSerializedTest.php
Modified: logging/log4php/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/changes/changes.xml?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/changes/changes.xml (original)
+++ logging/log4php/trunk/src/changes/changes.xml Mon Dec 12 15:41:19 2011
@@ -21,6 +21,7 @@
</properties>
<body>
<release version="2.2.0" date="SVN">
+ <action date="2011-12-12" type="update" issue="LOG4PHP-161" dev="Ivan Habunek">All configurable components should report errors when given invalid values</action>
<action date="2011-12-10" type="update" issue="LOG4PHP-165" dev="Ivan Habunek" due-to="Johannes Wohlgemuth" due-to-email="j dot wohlgemuth at findologic dot com">Extended LoggerLayoutXml to include MDC info</action>
<action date="2011-12-09" type="fix" issue="LOG4PHP-162" dev="Ivan Habunek">Warning for invalid appender threshold level never called.</action>
<action date="2011-12-08" type="fix" issue="LOG4PHP-114" dev="Ivan Habunek">Order of params in LoggerAppenderDailyFile configuration is significant.</action>
Modified: logging/log4php/trunk/src/main/php/Logger.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/Logger.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/Logger.php (original)
+++ logging/log4php/trunk/src/main/php/Logger.php Mon Dec 12 15:41:19 2011
@@ -52,6 +52,7 @@ class Logger {
'LoggerMDC' => '/LoggerMDC.php',
'LoggerNDC' => '/LoggerNDC.php',
'LoggerReflectionUtils' => '/LoggerReflectionUtils.php',
+ 'LoggerConfigurable' => '/LoggerConfigurable.php',
'LoggerConfigurator' => '/LoggerConfigurator.php',
'LoggerConfigurationAdapter' => '/configurators/LoggerConfigurationAdapter.php',
'LoggerConfigurationAdapterINI' => '/configurators/LoggerConfigurationAdapterINI.php',
Modified: logging/log4php/trunk/src/main/php/LoggerAppender.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerAppender.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerAppender.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerAppender.php Mon Dec 12 15:41:19 2011
@@ -24,7 +24,7 @@
* @version $Revision$
* @package log4php
*/
-abstract class LoggerAppender {
+abstract class LoggerAppender extends LoggerConfigurable {
/**
* Set to true when the appender is closed. A closed appender will not
Added: logging/log4php/trunk/src/main/php/LoggerConfigurable.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerConfigurable.php?rev=1213283&view=auto
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerConfigurable.php (added)
+++ logging/log4php/trunk/src/main/php/LoggerConfigurable.php Mon Dec 12 15:41:19 2011
@@ -0,0 +1,96 @@
+<?php
+
+/**
+ * A base class from which all classes which have configurable properties are
+ * extended. Provides a generic setter with integrated validation.
+ */
+abstract class LoggerConfigurable {
+
+ /** Setter function for boolean type. */
+ protected function setBoolean($property, $value) {
+ try {
+ $this->$property = LoggerOptionConverter::toBooleanEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected a boolean value. Property not changed.");
+ }
+ }
+
+ /** Setter function for integer type. */
+ protected function setInteger($property, $value) {
+ try {
+ $this->$property = LoggerOptionConverter::toIntegerEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected an integer. Property not changed.");
+ }
+ }
+
+ /** Setter function for LoggerLevel values. */
+ protected function setLevel($property, $value) {
+ try {
+ $this->$property = LoggerOptionConverter::toLevelEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected a level value. Property not changed.");
+ }
+ }
+
+ /** Setter function for integer type. */
+ protected function setPositiveInteger($property, $value) {
+ try {
+ $this->$property = LoggerOptionConverter::toPositiveIntegerEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected a positive integer. Property not changed.");
+ }
+ }
+
+ /** Setter for file size. */
+ protected function setFileSize($property, $value) {
+ try {
+ $this->$property = LoggerOptionConverter::toFileSizeEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected a file size value. Property not changed.");
+ }
+ }
+
+ /** Setter function for numeric type. */
+ protected function setNumeric($property, $value) {
+ try {
+ $this->$property = LoggerOptionConverter::toNumericEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected a number. Property not changed.");
+ }
+ }
+
+ /** Setter function for string type. */
+ protected function setString($property, $value, $nullable = false) {
+ if ($value === null) {
+ if($nullable) {
+ $this->$property= null;
+ } else {
+ $this->warn("Null value given for '$property' property. Expected a string. Property not changed.");
+ }
+ } else {
+ try {
+ $this->$property = LoggerOptionConverter::toStringEx($value);
+ } catch (Exception $ex) {
+ $value = var_export($value, true);
+ $this->warn("Invalid value given for '$property' property: [$value]. Expected a string. Property not changed.");
+ }
+ }
+ }
+
+ /** Triggers a warning. */
+ protected function warn($message) {
+ $class = get_class($this);
+ trigger_error("log4php: $class: $message", E_USER_WARNING);
+ }
+}
+
+
+
+?>
\ No newline at end of file
Modified: logging/log4php/trunk/src/main/php/LoggerFilter.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerFilter.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerFilter.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerFilter.php Mon Dec 12 15:41:19 2011
@@ -53,7 +53,7 @@
* @version $Revision$
* @package log4php
*/
-abstract class LoggerFilter {
+abstract class LoggerFilter extends LoggerConfigurable {
/**
* The log event must be logged immediately without consulting with
Modified: logging/log4php/trunk/src/main/php/LoggerLayout.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerLayout.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerLayout.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerLayout.php Mon Dec 12 15:41:19 2011
@@ -24,7 +24,7 @@
* @version $Revision$
* @package log4php
*/
-abstract class LoggerLayout {
+abstract class LoggerLayout extends LoggerConfigurable {
/**
* Activates options for this layout.
* Override this method if you have options to be activated.
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php Mon Dec 12 15:41:19 2011
@@ -51,7 +51,7 @@ class LoggerAppenderConsole extends Logg
* Default is STDOUT
* @var string
*/
- private $target = self::STDOUT;
+ protected $target = self::STDOUT;
/**
* @var mixed the resource used to open stdout/stderr
@@ -68,6 +68,9 @@ class LoggerAppenderConsole extends Logg
$this->target = self::STDOUT;
} elseif ($v == self::STDERR || strtoupper($v) == 'STDERR') {
$this->target = self::STDERR;
+ } else {
+ $value = var_export($value);
+ $this->warn("Invalid value given for 'target' property: [$value]. Property not set.");
}
}
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderDailyFile.php Mon Dec 12 15:41:19 2011
@@ -57,14 +57,14 @@ class LoggerAppenderDailyFile extends Lo
* It follows the {@link PHP_MANUAL#date()} formatting rules and <b>should always be set before {@link $file} param</b>.
* @var string
*/
- public $datePattern = "Ymd";
+ protected $datePattern = "Ymd";
/**
* Sets date format for the file name.
* @param string $datePattern a regular date() string format
*/
public function setDatePattern($datePattern) {
- $this->datePattern = $datePattern;
+ $this->setString('datePattern', $datePattern);
}
/**
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderEcho.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderEcho.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderEcho.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderEcho.php Mon Dec 12 15:41:19 2011
@@ -42,13 +42,13 @@
*/
class LoggerAppenderEcho extends LoggerAppender {
/** boolean used internally to mark first append */
- private $firstAppend = true;
+ protected $firstAppend = true;
/**
* If set to true, a <br /> element will be inserted before each line
* break in the logged message. Default value is false. @var boolean
*/
- private $htmlLineBreaks = false;
+ protected $htmlLineBreaks = false;
public function close() {
if($this->closed != true) {
@@ -75,7 +75,7 @@ class LoggerAppenderEcho extends LoggerA
}
public function setHtmlLineBreaks($value) {
- $this->htmlLineBreaks = LoggerOptionConverter::toBoolean($value, false);
+ $this->setBoolean('htmlLineBreaks', $value);
}
public function getHtmlLineBreaks() {
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderFile.php Mon Dec 12 15:41:19 2011
@@ -45,7 +45,7 @@ class LoggerAppenderFile extends LoggerA
/**
* @var boolean if {@link $file} exists, appends events.
*/
- private $append = true;
+ protected $append = true;
/**
* @var string the file name used to append events
@@ -114,7 +114,7 @@ class LoggerAppenderFile extends LoggerA
* @param string $file
*/
public function setFile($file) {
- $this->file = $file;
+ $this->setString('file', $file);
}
/**
@@ -131,8 +131,8 @@ class LoggerAppenderFile extends LoggerA
return $this->append;
}
- public function setAppend($flag) {
- $this->append = LoggerOptionConverter::toBoolean($flag, true);
+ public function setAppend($append) {
+ $this->setBoolean('append', $append);
}
/**
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMail.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMail.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMail.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMail.php Mon Dec 12 15:41:19 2011
@@ -55,19 +55,19 @@
class LoggerAppenderMail extends LoggerAppender {
/** @var string 'from' field */
- private $from = null;
+ protected $from = null;
/** @var string 'subject' field */
- private $subject = 'Log4php Report';
+ protected $subject = 'Log4php Report';
/** @var string 'to' field */
- private $to = null;
+ protected $to = null;
/** @var indiciates if this appender should run in dry mode */
- private $dry = false;
+ protected $dry = false;
/** @var string used to create mail body */
- private $body = '';
+ protected $body = '';
public function close() {
if($this->closed != true) {
@@ -90,19 +90,19 @@ class LoggerAppenderMail extends LoggerA
}
public function setSubject($subject) {
- $this->subject = $subject;
+ $this->setString('subject', $subject);
}
public function setTo($to) {
- $this->to = $to;
+ $this->setString('to', $to);
}
public function setFrom($from) {
- $this->from = $from;
- }
+ $this->setString('from', $from);
+ }
public function setDry($dry) {
- $this->dry = $dry;
+ $this->setBoolean('dry', $dry);
}
public function append(LoggerLoggingEvent $event) {
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMailEvent.php Mon Dec 12 15:41:19 2011
@@ -56,30 +56,30 @@ class LoggerAppenderMailEvent extends Lo
/** 'from' field (defaults to 'sendmail_from' from php.ini on win32).
* @var string
*/
- private $from = null;
+ protected $from;
/** Mailserver port (win32 only).
* @var integer
*/
- private $port = 25;
+ protected $port = 25;
/** Mailserver hostname (win32 only).
* @var string
*/
- private $smtpHost = null;
+ protected $smtpHost = null;
/**
* @var string 'subject' field
*/
- private $subject = '';
+ protected $subject = '';
/**
* @var string 'to' field
*/
- private $to = null;
+ protected $to = null;
/** @var indiciates if this appender should run in dry mode */
- private $dry = false;
+ protected $dry = false;
public function activateOptions() {
if (empty($this->layout)) {
@@ -98,27 +98,27 @@ class LoggerAppenderMailEvent extends Lo
}
public function setFrom($from) {
- $this->from = $from;
+ $this->setString('from', $from);
}
public function setPort($port) {
- $this->port = (int)$port;
+ $this->setPositiveInteger('port', $port);
}
public function setSmtpHost($smtpHost) {
- $this->smtpHost = $smtpHost;
+ $this->setString('smtpHost', $smtpHost);
}
public function setSubject($subject) {
- $this->subject = $subject;
+ $this->setString('subject', $subject);
}
public function setTo($to) {
- $this->to = $to;
+ $this->setString('to', $to);
}
public function setDry($dry) {
- $this->dry = $dry;
+ $this->setBoolean('dry', $dry);
}
public function append(LoggerLoggingEvent $event) {
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderMongoDB.php Mon Dec 12 15:41:19 2011
@@ -220,8 +220,8 @@ class LoggerAppenderMongoDB extends Logg
public function setHost($host) {
if (!preg_match('/^mongodb\:\/\//', $host)) {
$host = self::DEFAULT_MONGO_URL_PREFIX . $host;
- }
- $this->host = $host;
+ }
+ $this->host = $host;
}
/** Returns the value of {@link $host} parameter. */
@@ -231,7 +231,7 @@ class LoggerAppenderMongoDB extends Logg
/** Sets the value of {@link $port} parameter. */
public function setPort($port) {
- $this->port = $port;
+ $this->setPositiveInteger('port', $port);
}
/** Returns the value of {@link $port} parameter. */
@@ -241,7 +241,7 @@ class LoggerAppenderMongoDB extends Logg
/** Sets the value of {@link $databaseName} parameter. */
public function setDatabaseName($databaseName) {
- $this->databaseName = $databaseName;
+ $this->setString('databaseName', $databaseName);
}
/** Returns the value of {@link $databaseName} parameter. */
@@ -251,7 +251,7 @@ class LoggerAppenderMongoDB extends Logg
/** Sets the value of {@link $collectionName} parameter. */
public function setCollectionName($collectionName) {
- $this->collectionName = $collectionName;
+ $this->setString('collectionName', $collectionName);
}
/** Returns the value of {@link $collectionName} parameter. */
@@ -261,7 +261,7 @@ class LoggerAppenderMongoDB extends Logg
/** Sets the value of {@link $userName} parameter. */
public function setUserName($userName) {
- $this->userName = $userName;
+ $this->setString('userName', $userName, true);
}
/** Returns the value of {@link $userName} parameter. */
@@ -271,7 +271,7 @@ class LoggerAppenderMongoDB extends Logg
/** Sets the value of {@link $password} parameter. */
public function setPassword($password) {
- $this->password = $password;
+ $this->setString('password', $password, true);
}
/** Returns the value of {@link $password} parameter. */
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderPDO.php Mon Dec 12 15:41:19 2011
@@ -50,68 +50,68 @@ class LoggerAppenderPDO extends LoggerAp
* Create the log table if it does not exists (optional).
* @var string
*/
- private $createTable = true;
+ protected $createTable = true;
/**
* Database user name.
* @var string
*/
- private $user = '';
+ protected $user;
/**
* Database password
* @var string
*/
- private $password = '';
+ protected $password;
/**
* DSN string for enabling a connection.
* @var string
*/
- private $dsn;
+ protected $dsn;
/**
* A {@link LoggerPatternLayout} string used to format a valid insert query.
* @deprecated Use {@link $insertSql} and {@link $insertPattern} which properly handle quotes in the messages!
* @var string
*/
- private $sql;
+ protected $sql;
/**
* Can be set to a complete insert statement with ? that are replaced using {@link insertPattern}.
* @var string
*/
- private $insertSql = "INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?,?,?,?,?,?,?)";
+ protected $insertSql = "INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?,?,?,?,?,?,?)";
/**
* A comma separated list of {@link LoggerPatternLayout} format strings that replace the "?" in {@link $sql}.
* @var string
*/
- private $insertPattern = "%d,%c,%p,%m,%t,%F,%L";
+ protected $insertPattern = "%d,%c,%p,%m,%t,%F,%L";
/**
* Table name to write events. Used only for CREATE TABLE if {@link $createTable} is true.
* @var string
*/
- private $table = 'log4php_log';
+ protected $table = 'log4php_log';
/**
* The PDO instance.
* @var PDO
*/
- private $db = null;
+ protected $db = null;
/**
* Prepared statement for the INSERT INTO query.
* @var PDOStatement
*/
- private $preparedInsert;
+ protected $preparedInsert;
/**
* Set in activateOptions() and later used in append() to check if all conditions to append are true.
* @var boolean
*/
- private $canAppend = true;
+ protected $canAppend = true;
/**
* This appender does not require a layout.
@@ -224,7 +224,7 @@ class LoggerAppenderPDO extends LoggerAp
* Defaults to ''
*/
public function setUser($user) {
- $this->user = $user;
+ $this->setString('user', $user);
}
/**
@@ -232,7 +232,7 @@ class LoggerAppenderPDO extends LoggerAp
* Defaults to ''
*/
public function setPassword($password) {
- $this->password = $password;
+ $this->setString('password', $password);
}
/**
@@ -240,7 +240,7 @@ class LoggerAppenderPDO extends LoggerAp
* if its not existing.
*/
public function setCreateTable($flag) {
- $this->createTable = LoggerOptionConverter::toBoolean($flag, true);
+ $this->setBoolean('createTable', $flag);
}
/**
@@ -257,7 +257,7 @@ class LoggerAppenderPDO extends LoggerAp
* @deprecated See {@link setInsertSql} and {@link setInsertPattern}.
*/
public function setSql($sql) {
- $this->sql = $sql;
+ $this->setString('sql', $sql);
}
/**
@@ -266,7 +266,7 @@ class LoggerAppenderPDO extends LoggerAp
* @param $sql A complete INSERT INTO query with "?" that gets replaced.
*/
public function setInsertSql($sql) {
- $this->insertSql = $sql;
+ $this->setString('insertSql', $sql);
}
/**
@@ -277,7 +277,7 @@ class LoggerAppenderPDO extends LoggerAp
* @param $pattern Comma separated format strings like "%p,%m,%C"
*/
public function setInsertPattern($pattern) {
- $this->insertPattern = $pattern;
+ $this->setString('insertPattern', $pattern);
}
/**
@@ -285,7 +285,7 @@ class LoggerAppenderPDO extends LoggerAp
* Defaults to log4php_log
*/
public function setTable($table) {
- $this->table = $table;
+ $this->setString('table', $table);
}
/**
@@ -293,7 +293,7 @@ class LoggerAppenderPDO extends LoggerAp
* SQLite it could look like this: 'sqlite:appenders/pdotest.sqlite'
*/
public function setDSN($dsn) {
- $this->dsn = $dsn;
+ $this->setString('dsn', $dsn);
}
/**
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderRollingFile.php Mon Dec 12 15:41:19 2011
@@ -64,7 +64,7 @@ class LoggerAppenderRollingFile extends
*
* @var integer
*/
- private $maxFileSize = 10485760;
+ protected $maxFileSize = 10485760;
/**
* Set the maximum number of backup files to keep around.
@@ -78,7 +78,7 @@ class LoggerAppenderRollingFile extends
*
* @var integer
*/
- private $maxBackupIndex = 1;
+ protected $maxBackupIndex = 1;
/**
* @var string the filename expanded
@@ -162,9 +162,7 @@ class LoggerAppenderRollingFile extends
* @param mixed $maxBackups
*/
public function setMaxBackupIndex($maxBackups) {
- if(is_numeric($maxBackups)) {
- $this->maxBackupIndex = abs((int)$maxBackups);
- }
+ $this->setPositiveInteger('maxBackupIndex', $maxBackups);
}
/**
@@ -193,24 +191,7 @@ class LoggerAppenderRollingFile extends
* @return the actual file size set
*/
public function setMaxFileSize($value) {
- $maxFileSize = null;
- $numpart = substr($value,0, strlen($value) -2);
- $suffix = strtoupper(substr($value, -2));
-
- switch($suffix) {
- case 'KB': $maxFileSize = (int)((int)$numpart * 1024); break;
- case 'MB': $maxFileSize = (int)((int)$numpart * 1024 * 1024); break;
- case 'GB': $maxFileSize = (int)((int)$numpart * 1024 * 1024 * 1024); break;
- default:
- if(is_numeric($value)) {
- $maxFileSize = (int)$value;
- }
- }
-
- if($maxFileSize !== null) {
- $this->maxFileSize = abs($maxFileSize);
- }
- return $this->maxFileSize;
+ $this->setFileSize('maxFileSize', $value);
}
public function append(LoggerLoggingEvent $event) {
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSocket.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSocket.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSocket.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSocket.php Mon Dec 12 15:41:19 2011
@@ -40,13 +40,13 @@ class LoggerAppenderSocket extends Logge
* Target host.
* @see http://php.net/manual/en/function.fsockopen.php
*/
- private $remoteHost;
+ protected $remoteHost;
/** Target port */
- private $port = 4446;
+ protected $port = 4446;
/** Connection timeout in ms. */
- private $timeout;
+ protected $timeout;
// ******************************************
// *** Appender methods ***
@@ -92,27 +92,17 @@ class LoggerAppenderSocket extends Logge
/** Sets the target host. */
public function setRemoteHost($hostname) {
- $this->remoteHost = $hostname;
+ $this->setString('remoteHost', $hostname);
}
/** Sets the target port */
public function setPort($port) {
- try {
- $this->port = LoggerOptionConverter::toIntegerEx($port, null);
- } catch (Exception $ex) {
- $this->warn("Invalid value provided for 'port' [$port]. Expected an integer. Using default value [{$this->port}].");
- }
+ $this->setPositiveInteger('port', $port);
}
/** Sets the timeout. */
public function setTimeout($timeout) {
- try {
- $this->timeout = LoggerOptionConverter::toIntegerEx($timeout);
- } catch (Exception $ex) {
- $value = var_export($timeout);
- $default = var_export($this->timeout);
- $this->warn("Invalid value provided for 'timeout' [$value]. Expeceted an integer. Using default value [$default].");
- }
+ $this->setPositiveInteger('timeout', $timeout);
}
/** Returns the target host. */
Modified: logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSyslog.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSyslog.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSyslog.php (original)
+++ logging/log4php/trunk/src/main/php/appenders/LoggerAppenderSyslog.php Mon Dec 12 15:41:19 2011
@@ -78,7 +78,7 @@ class LoggerAppenderSyslog extends Logge
*
* @var string
*/
- private $ident = "Apache log4php";
+ protected $ident = "Apache log4php";
/**
* The syslog priority to use when overriding priority. This setting is
@@ -86,21 +86,21 @@ class LoggerAppenderSyslog extends Logge
*
* @var string
*/
- private $priority;
+ protected $priority;
/**
* The option used when opening the syslog connection.
*
* @var string
*/
- private $option = 'PID|CONS';
+ protected $option = 'PID|CONS';
/**
* The facility value indicates the source of the message.
*
* @var string
*/
- private $facility = 'USER';
+ protected $facility = 'USER';
/**
* If set to true, the message priority will always use the value defined
@@ -109,7 +109,7 @@ class LoggerAppenderSyslog extends Logge
*
* @var string
*/
- private $overridePriority = false;
+ protected $overridePriority = false;
/**
* Holds the int value of the {@link $priority}.
Modified: logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelMatch.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelMatch.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelMatch.php (original)
+++ logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelMatch.php Mon Dec 12 15:41:19 2011
@@ -51,30 +51,26 @@ class LoggerFilterLevelMatch extends Log
* Indicates if this event should be accepted or denied on match
* @var boolean
*/
- private $acceptOnMatch = true;
+ protected $acceptOnMatch = true;
/**
* The level, when to match
* @var LoggerLevel
*/
- private $levelToMatch;
+ protected $levelToMatch;
/**
* @param boolean $acceptOnMatch
*/
public function setAcceptOnMatch($acceptOnMatch) {
- $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
+ $this->setBoolean('acceptOnMatch', $acceptOnMatch);
}
/**
* @param string $l the level to match
*/
- public function setLevelToMatch($l) {
- if($l instanceof LoggerLevel) {
- $this->levelToMatch = $l;
- } else {
- $this->levelToMatch = LoggerOptionConverter::toLevel($l, null);
- }
+ public function setLevelToMatch($level) {
+ $this->setLevel('levelToMatch', $level);
}
/**
Modified: logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelRange.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelRange.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelRange.php (original)
+++ logging/log4php/trunk/src/main/php/filters/LoggerFilterLevelRange.php Mon Dec 12 15:41:19 2011
@@ -67,45 +67,37 @@ class LoggerFilterLevelRange extends Log
/**
* @var boolean
*/
- private $acceptOnMatch = true;
+ protected $acceptOnMatch = true;
/**
* @var LoggerLevel
*/
- private $levelMin;
+ protected $levelMin;
/**
* @var LoggerLevel
*/
- private $levelMax;
+ protected $levelMax;
/**
* @param boolean $acceptOnMatch
*/
public function setAcceptOnMatch($acceptOnMatch) {
- $this->acceptOnMatch = LoggerOptionConverter::toBoolean($acceptOnMatch, true);
+ $this->setBoolean('acceptOnMatch', $acceptOnMatch);
}
/**
* @param string $l the level min to match
*/
- public function setLevelMin($l) {
- if($l instanceof LoggerLevel) {
- $this->levelMin = $l;
- } else {
- $this->levelMin = LoggerOptionConverter::toLevel($l, null);
- }
+ public function setLevelMin($level) {
+ $this->setLevel('levelMin', $level);
}
/**
* @param string $l the level max to match
*/
- public function setLevelMax($l) {
- if($l instanceof LoggerLevel) {
- $this->levelMax = $l;
- } else {
- $this->levelMax = LoggerOptionConverter::toLevel($l, null);
- }
+ public function setLevelMax($level) {
+ $this->setLevel('levelMax', $level);
}
/**
Modified: logging/log4php/trunk/src/main/php/filters/LoggerFilterStringMatch.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/filters/LoggerFilterStringMatch.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/filters/LoggerFilterStringMatch.php (original)
+++ logging/log4php/trunk/src/main/php/filters/LoggerFilterStringMatch.php Mon Dec 12 15:41:19 2011
@@ -50,25 +50,25 @@ class LoggerFilterStringMatch extends Lo
/**
* @var boolean
*/
- private $acceptOnMatch = true;
+ protected $acceptOnMatch = true;
/**
* @var string
*/
- private $stringToMatch = null;
+ protected $stringToMatch;
/**
* @param mixed $acceptOnMatch a boolean or a string ('true' or 'false')
*/
public function setAcceptOnMatch($acceptOnMatch) {
- $this->acceptOnMatch = is_bool($acceptOnMatch) ? $acceptOnMatch : (bool)(strtolower($acceptOnMatch) == 'true');
+ $this->setBoolean('acceptOnMatch', $acceptOnMatch);
}
/**
* @param string $s the string to match
*/
- public function setStringToMatch($s) {
- $this->stringToMatch = $s;
+ public function setStringToMatch($string) {
+ $this->setString('stringToMatch', $string);
}
/**
Modified: logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php (original)
+++ logging/log4php/trunk/src/main/php/helpers/LoggerOptionConverter.php Mon Dec 12 15:41:19 2011
@@ -128,17 +128,35 @@ class LoggerOptionConverter {
}
- /** Converts $value to integer, or throws an exception if not possible. */
+ /**
+ * Converts $value to integer, or throws an exception if not possible.
+ * Floats cannot be converted to integer.
+ */
public static function toIntegerEx($value) {
if (is_integer($value)) {
return $value;
}
- if (is_numeric($value)) {
+ if (is_numeric($value) && ($value == (integer) $value)) {
return (integer) $value;
}
throw new LoggerException("Given value [" . var_export($value, true) . "] cannot be converted to integer.");
}
+
+ /**
+ * Converts $value to integer, or throws an exception if not possible.
+ * Floats cannot be converted to integer.
+ */
+ public static function toPositiveIntegerEx($value) {
+ if (is_integer($value) && $value > 0) {
+ return $value;
+ }
+ if (is_numeric($value) && ($value == (integer) $value) && $value > 0) {
+ return (integer) $value;
+ }
+
+ throw new LoggerException("Given value [" . var_export($value, true) . "] cannot be converted to a positive integer.");
+ }
/**
* Converts a standard or custom priority level to a Level
@@ -200,6 +218,19 @@ class LoggerOptionConverter {
}
return $result;
}
+
+
+ /** Converts the value to a level. Throws an exception if not possible. */
+ public static function toLevelEx($value) {
+ if ($value instanceof LoggerLevel) {
+ return $value;
+ }
+ $level = LoggerLevel::toLevel($value);
+ if ($level === null) {
+ throw new LoggerException("Given value [" . var_export($value, true) . "] cannot be converted to a logger level.");
+ }
+ return $level;
+ }
/**
* @param string $value
@@ -228,8 +259,80 @@ class LoggerOptionConverter {
}
return $default;
}
+
/**
+ * Converts a value to a valid file size (integer).
+ *
+ * Supports 'KB', 'MB' and 'GB' suffixes, where KB = 1024 B etc.
+ *
+ * The final value will be rounded to the nearest integer.
+ *
+ * Examples:
+ * - '100' => 100
+ * - '100.12' => 100
+ * - '100KB' => 102400
+ * - '1.5MB' => 1572864
+ *
+ * @param mixed $value File size (optionally with suffix).
+ * @return integer Parsed file size.
+ */
+ public static function toFileSizeEx($value) {
+
+ if (empty($value)) {
+ throw new LoggerException("Empty value cannot be converted to a file size.");
+ }
+
+ if (is_numeric($value)) {
+ return (integer) $value;
+ }
+
+ if (!is_string($value)) {
+ throw new LoggerException("Given value [" . var_export($value, true) . "] cannot be converted to a file size.");
+ }
+
+ $str = strtoupper(trim($value));
+ $count = preg_match('/^([0-9.]+)(KB|MB|GB)?$/', $str, $matches);
+
+ if ($count > 0) {
+ $size = $matches[1];
+ $unit = $matches[2];
+
+ switch($unit) {
+ case 'KB': $size *= pow(1024, 1); break;
+ case 'MB': $size *= pow(1024, 2); break;
+ case 'GB': $size *= pow(1024, 3); break;
+ }
+
+ return (integer) $size;
+ }
+
+ throw new LoggerException("Given value [$value] cannot be converted to a file size.");
+ }
+
+ /**
+ * Converts a value to string, or throws an exception if not possible.
+ *
+ * Objects can be converted to string if they implement the magic
+ * __toString() method.
+ *
+ */
+ public static function toStringEx($value) {
+ if (is_string($value)) {
+ return $value;
+ }
+ if (is_numeric($value)) {
+ return (string) $value;
+ }
+ if (is_object($value) && method_exists($value, '__toString')) {
+ return (string) $value;
+ }
+
+ throw new LoggerException("Given value [" . var_export($value, true) . "] cannot be converted to string.");
+ }
+
+
+ /**
* Find the value corresponding to <var>$key</var> in
* <var>$props</var>. Then perform variable substitution on the
* found value.
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php Mon Dec 12 15:41:19 2011
@@ -47,13 +47,6 @@
* @subpackage layouts
*/
class LoggerLayoutHtml extends LoggerLayout {
-
-
- public function activateOptions() {
-
-
- }
-
/**
* The <b>LocationInfo</b> option takes a boolean value. By
* default, it is set to false which means there will be no location
@@ -66,7 +59,7 @@ class LoggerLayoutHtml extends LoggerLay
* <b>LocationInfo</b> option of that appender as well.
* @var boolean
*/
- private $locationInfo = false;
+ protected $locationInfo = false;
/**
* The <b>Title</b> option takes a String value. This option sets the
@@ -74,7 +67,7 @@ class LoggerLayoutHtml extends LoggerLay
* Defaults to 'Log4php Log Messages'.
* @var string
*/
- private $title = "Log4php Log Messages";
+ protected $title = "Log4php Log Messages";
/**
* The <b>LocationInfo</b> option takes a boolean value. By
@@ -88,11 +81,7 @@ class LoggerLayoutHtml extends LoggerLay
* <b>LocationInfo</b> option of that appender as well.
*/
public function setLocationInfo($flag) {
- if (is_bool($flag)) {
- $this->locationInfo = $flag;
- } else {
- $this->locationInfo = (bool)(strtolower($flag) == 'true');
- }
+ $this->setBoolean('locationInfo', $flag);
}
/**
@@ -108,7 +97,7 @@ class LoggerLayoutHtml extends LoggerLay
* Defaults to 'Log4php Log Messages'.
*/
public function setTitle($title) {
- $this->title = $title;
+ $this->setString('title', $title);
}
/**
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutPattern.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutPattern.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutPattern.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutPattern.php Mon Dec 12 15:41:19 2011
@@ -142,28 +142,14 @@ class LoggerLayoutPattern extends Logger
/** Default conversion TTCC Pattern */
const TTCC_CONVERSION_PATTERN = '%d [%t] %p %c %x - %m%n';
- /** The pattern.
- * @var string */
- private $pattern;
+ /** The conversion pattern. */
+ protected $pattern = self::DEFAULT_CONVERSION_PATTERN;
- /** Head of a chain of Converters.
- * @var LoggerPatternConverter */
- private $head;
-
- private $timezone;
-
- /**
- * Constructs a PatternLayout using the
- * {@link DEFAULT_LAYOUT_PATTERN}.
- * The default pattern just produces the application supplied message.
+ /**
+ * Head of a chain of Converters.
+ * @var LoggerPatternConverter
*/
- public function __construct($pattern = null) {
- if ($pattern === null) {
- $this->setConversionPattern(self::DEFAULT_CONVERSION_PATTERN);
- } else {
- $this->pattern = $pattern;
- }
- }
+ private $head;
/**
* Set the <b>ConversionPattern</b> option. This is the string which
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSerialized.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSerialized.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSerialized.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSerialized.php Mon Dec 12 15:41:19 2011
@@ -33,17 +33,11 @@
class LoggerLayoutSerialized extends LoggerLayout {
/** Whether to include the event's location information (slow). */
- private $locationInfo = false;
+ protected $locationInfo = false;
/** Sets the location information flag. */
public function setLocationInfo($value) {
- try {
- $this->locationInfo = LoggerOptionConverter::toBooleanEx($value);
- } catch (Exception $ex) {
- $strVal = var_export($value, true);
- $default = var_export($this->locationInfo, true);
- $this->warn("Invalid value provided for locationInfo: [$strVal]. Expected a boolean. Using default value: [$default].");
- }
+ $this->setBoolean('locationInfo', $value);
}
/** Returns the location information flag. */
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSimple.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSimple.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSimple.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutSimple.php Mon Dec 12 15:41:19 2011
@@ -40,12 +40,6 @@
*/
class LoggerLayoutSimple extends LoggerLayout {
/**
- * Constructor
- */
- public function __construct() {
- }
-
- /**
* Returns the log statement in a format consisting of the
* <b>level</b>, followed by " - " and then the
* <b>message</b>. For example,
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutTTCC.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutTTCC.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutTTCC.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutTTCC.php Mon Dec 12 15:41:19 2011
@@ -79,9 +79,7 @@ class LoggerLayoutTTCC extends LoggerLay
* current thread is part of log output or not. This is true by default.
*/
public function setThreadPrinting($threadPrinting) {
- $this->threadPrinting = is_bool($threadPrinting) ?
- $threadPrinting :
- (bool)(strtolower($threadPrinting) == 'true');
+ $this->setBoolean('threadPrinting', $threadPrinting);
}
/**
@@ -96,7 +94,7 @@ class LoggerLayoutTTCC extends LoggerLay
* name is part of log output or not. This is true by default.
*/
public function setCategoryPrefixing($categoryPrefixing) {
- $this->categoryPrefixing = LoggerOptionConverter::toBoolean($categoryPrefixing);
+ $this->setBoolean('categoryPrefixing', $categoryPrefixing);
}
/**
@@ -112,7 +110,7 @@ class LoggerLayoutTTCC extends LoggerLay
* This is true by default.
*/
public function setContextPrinting($contextPrinting) {
- $this->contextPrinting = LoggerOptionConverter::toBoolean($contextPrinting);
+ $this->setBoolean('contextPrinting', $contextPrinting);
}
/**
@@ -128,9 +126,7 @@ class LoggerLayoutTTCC extends LoggerLay
* This is true by default.
*/
public function setMicroSecondsPrinting($microSecondsPrinting) {
- $this->microSecondsPrinting = is_bool($microSecondsPrinting) ?
- $microSecondsPrinting :
- (bool)(strtolower($microSecondsPrinting) == 'true');
+ $this->setBoolean('microSecondsPrinting', $microSecondsPrinting);
}
/**
@@ -142,7 +138,7 @@ class LoggerLayoutTTCC extends LoggerLay
public function setDateFormat($dateFormat) {
- $this->dateFormat = $dateFormat;
+ $this->setString('dateFormat', $dateFormat);
}
/**
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutXml.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutXml.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutXml.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutXml.php Mon Dec 12 15:41:19 2011
@@ -70,20 +70,20 @@ class LoggerLayoutXml extends LoggerLayo
* log statement will be output.
* @var boolean
*/
- private $locationInfo = true;
+ protected $locationInfo = true;
/**
* If set to true, log4j namespace will be used instead of the log4php
* namespace.
* @var boolean
*/
- private $log4jNamespace = false;
+ protected $log4jNamespace = false;
/** The namespace in use. */
- private $namespace = self::LOG4PHP_NS;
+ protected $namespace = self::LOG4PHP_NS;
/** The namespace prefix in use */
- private $namespacePrefix = self::LOG4PHP_NS_PREFIX;
+ protected $namespacePrefix = self::LOG4PHP_NS_PREFIX;
public function activateOptions() {
if ($this->getLog4jNamespace()) {
@@ -180,7 +180,7 @@ class LoggerLayoutXml extends LoggerLayo
* origin of the log statement will be output.
*/
public function setLocationInfo($flag) {
- $this->locationInfo = LoggerOptionConverter::toBoolean($flag, true);
+ $this->setBoolean('locationInfo', $flag);
}
/**
@@ -194,7 +194,7 @@ class LoggerLayoutXml extends LoggerLayo
* @param boolean
*/
public function setLog4jNamespace($flag) {
- $this->log4jNamespace = LoggerOptionConverter::toBoolean($flag, true);
+ $this->setBoolean('log4jNamespace', $flag);
}
/**
Modified: logging/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php (original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php Mon Dec 12 15:41:19 2011
@@ -77,7 +77,6 @@ class LoggerAppenderConsoleTest extends
public function testAppendStderr() {
$this->config['appenders']['default']['params']['target'] = 'stderr';
-
Logger::configure($this->config);
$log = Logger::getRootLogger();
$expected = LoggerAppenderConsole::STDERR;
Modified: logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php (original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMailEventTest.php Mon Dec 12 15:41:19 2011
@@ -55,13 +55,13 @@ class LoggerAppenderMailEventTest extend
$appender->close();
}
- /** Check if invalid configurations are rejected.
- * @expectedException LoggerException with empty
+ /**
+ * Check if invalid configurations are rejected.
+ * @expectedException LoggerException with empty
*/
public function testEmptyTo() {
- $appender = new LoggerAppenderMailEvent("myname ");
+ $appender = new LoggerAppenderMailEvent("myname");
$appender->setLayout(new LoggerLayoutSimple());
- $appender->setTo(null);
$appender->setFrom('info@example.com');
$appender->activateOptions();
}
Modified: logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php (original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderMongoDBTest.php Mon Dec 12 15:41:19 2011
@@ -62,96 +62,92 @@ class LoggerAppenderMongoDBTest extends
public function testSetGetHost() {
$expected = 'mongodb://localhost';
- self::$appender->setHost($expected);
+ self::$appender->setHost($expected);
$result = self::$appender->getHost();
$this->assertEquals($expected, $result, 'Host doesn\'t match expted value');
}
public function testSetGetHostMongoPrefix() {
$expected = 'mongodb://localhost';
- self::$appender->setHost('localhost');
+ self::$appender->setHost('localhost');
$result = self::$appender->getHost();
$this->assertEquals($expected, $result, 'Host doesn\'t match expted value');
}
public function testSetPort() {
$expected = 27017;
- self::$appender->setPort($expected);
+ self::$appender->setPort($expected);
$result = self::$appender->getPort();
$this->assertEquals($expected, $result, 'Port doesn\'t match expted value');
}
public function testGetPort() {
$expected = 27017;
- self::$appender->setPort($expected);
+ self::$appender->setPort($expected);
$result = self::$appender->getPort();
$this->assertEquals($expected, $result, 'Port doesn\'t match expted value');
}
public function testSetDatabaseName() {
$expected = 'log4php_mongodb';
- self::$appender->setDatabaseName($expected);
+ self::$appender->setDatabaseName($expected);
$result = self::$appender->getDatabaseName();
$this->assertEquals($expected, $result, 'Database name doesn\'t match expted value');
}
public function testGetDatabaseName() {
$expected = 'log4php_mongodb';
- self::$appender->setDatabaseName($expected);
+ self::$appender->setDatabaseName($expected);
$result = self::$appender->getDatabaseName();
$this->assertEquals($expected, $result, 'Database name doesn\'t match expted value');
}
public function testSetCollectionName() {
$expected = 'logs';
- self::$appender->setCollectionName($expected);
+ self::$appender->setCollectionName($expected);
$result = self::$appender->getCollectionName();
$this->assertEquals($expected, $result, 'Collection name doesn\'t match expted value');
}
public function testGetCollectionName() {
$expected = 'logs';
- self::$appender->setCollectionName($expected);
+ self::$appender->setCollectionName($expected);
$result = self::$appender->getCollectionName();
$this->assertEquals($expected, $result, 'Collection name doesn\'t match expted value');
}
public function testSetUserName() {
$expected = 'char0n';
- self::$appender->setUserName($expected);
+ self::$appender->setUserName($expected);
$result = self::$appender->getUserName();
$this->assertEquals($expected, $result, 'UserName doesn\'t match expted value');
}
public function testGetUserName() {
$expected = 'char0n';
- self::$appender->setUserName($expected);
+ self::$appender->setUserName($expected);
$result = self::$appender->getUserName();
$this->assertEquals($expected, $result, 'UserName doesn\'t match expted value');
}
public function testSetPassword() {
$expected = 'secret pass';
- self::$appender->setPassword($expected);
+ self::$appender->setPassword($expected);
$result = self::$appender->getPassword();
$this->assertEquals($expected, $result, 'Password doesn\'t match expted value');
}
public function testGetPassword() {
$expected = 'secret pass';
- self::$appender->setPassword($expected);
+ self::$appender->setPassword($expected);
$result = self::$appender->getPassword();
$this->assertEquals($expected, $result, 'Password doesn\'t match expted value');
}
public function testActivateOptionsNoCredentials() {
- try {
- self::$appender->setUserName(null);
- self::$appender->setPassword(null);
- self::$appender->activateOptions();
- } catch (Exception $ex) {
- $this->fail('Activating appender options was not successful');
- }
+ self::$appender->setUserName(null);
+ self::$appender->setPassword(null);
+ self::$appender->activateOptions();
}
public function testAppend() {
@@ -227,6 +223,8 @@ class LoggerAppenderMongoDBTest extends
/** Logs the event and returns the record from the database. */
private function logOne($event)
{
+ self::$appender = new LoggerAppenderMongoDB();
+ self::$appender->setHost('localhost');
self::$appender->activateOptions();
$mongo = self::$appender->getConnection();
$collection = $mongo->log4php_mongodb->logs;
Modified: logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php (original)
+++ logging/log4php/trunk/src/test/php/appenders/LoggerAppenderRollingFileTest.php Mon Dec 12 15:41:19 2011
@@ -49,35 +49,32 @@ class LoggerAppenderRollingFileTest exte
public function testMaxFileSize() {
$appender = new LoggerAppenderRollingFile("mylogger");
- $e = $appender->setMaxFileSize('1KB');
- self::assertEquals($e, '1024');
-
- $e = $appender->setMaxFileSize('2KB');
- self::assertEquals($e, '2048');
+ $appender->setMaxFileSize('1KB');
+ self::assertEquals(1024, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('1MB');
- self::assertEquals($e, '1048576');
+ $appender->setMaxFileSize('2KB');
+ self::assertEquals(2048, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('3MB');
- self::assertEquals($e, '3145728');
+ $appender->setMaxFileSize('1MB');
+ self::assertEquals(1048576, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('1GB');
- self::assertEquals($e, '1073741824');
+ $appender->setMaxFileSize('3MB');
+ self::assertEquals(3145728, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('10000');
- self::assertEquals($e, '10000');
+ $appender->setMaxFileSize('1GB');
+ self::assertEquals(1073741824, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('BLUB');
- self::assertEquals($e, '10000');
+ $appender->setMaxFileSize('10000');
+ self::assertEquals(10000, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('100.5');
- self::assertEquals($e, '100');
+ $appender->setMaxFileSize('100.5');
+ self::assertEquals(100, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('1000.6');
- self::assertEquals($e, '1000');
+ $appender->setMaxFileSize('1000.6');
+ self::assertEquals(1000, $appender->getMaxFileSize());
- $e = $appender->setMaxFileSize('1.5MB');
- self::assertEquals($e, '1048576');
+ $appender->setMaxFileSize('1.5MB');
+ self::assertEquals(1572864, $appender->getMaxFileSize());
}
public function testSetFileName() {
Modified: logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php (original)
+++ logging/log4php/trunk/src/test/php/filters/LoggerFilterStringMatchTest.php Mon Dec 12 15:41:19 2011
@@ -106,7 +106,6 @@ class LoggerFilterStringMatchTest extend
public function testDecideNullMatch() {
$filter = new LoggerFilterStringMatch();
$filter->setAcceptOnMatch("false");
- $filter->setStringToMatch(null);
$event = new LoggerLoggingEvent("LoggerAppenderEchoTest", new Logger("TEST"), LoggerLevel::getLevelError(), "testmessage");
Modified: logging/log4php/trunk/src/test/php/layouts/LoggerLayoutSerializedTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/layouts/LoggerLayoutSerializedTest.php?rev=1213283&r1=1213282&r2=1213283&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/layouts/LoggerLayoutSerializedTest.php (original)
+++ logging/log4php/trunk/src/test/php/layouts/LoggerLayoutSerializedTest.php Mon Dec 12 15:41:19 2011
@@ -39,7 +39,7 @@ class LoggerLayoutSerializedTest extends
/**
* @expectedException PHPUnit_Framework_Error
- * @expectedExceptionMessage log4php: [LoggerLayoutSerialized]: Invalid value provided for locationInfo: ['foo']. Expected a boolean. Using default value: [false].
+ * @expectedExceptionMessage Invalid value given for 'locationInfo' property: ['foo']. Expected a boolean value. Property not changed.
*/
public function testLocationInfoFail() {
$layout = new LoggerLayoutSerialized();