summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-01-08 18:13:02 +0000
committerxue <>2006-01-08 18:13:02 +0000
commit09596d92b2eea0f70c98cc5abca6f5dbd4629802 (patch)
tree3e1c656d18ee46510bd76033e7b36ca2bd4dc05d
parent4a2c7c4e9ac75c1420e95624fb9ee34ab178c52f (diff)
Completed TLogger, TLogRouter, TFileLogRoute, TEmailLogRoute
-rw-r--r--.gitattributes16
-rw-r--r--framework/Log/EventLog/context.php167
-rw-r--r--framework/Log/EventLog/exceptions/file_exception.php44
-rw-r--r--framework/Log/EventLog/exceptions/writer_exception.php30
-rw-r--r--framework/Log/EventLog/interfaces/writer.php45
-rw-r--r--framework/Log/EventLog/log.php644
-rw-r--r--framework/Log/EventLog/log_autoload.php25
-rw-r--r--framework/Log/EventLog/log_message.php169
-rw-r--r--framework/Log/EventLog/map.php386
-rw-r--r--framework/Log/EventLog/structs/log_filter.php74
-rw-r--r--framework/Log/EventLog/writers/writer_database.php216
-rw-r--r--framework/Log/EventLog/writers/writer_file.php273
-rw-r--r--framework/Log/EventLog/writers/writer_unix_file.php100
-rw-r--r--framework/Log/ILog.php76
-rw-r--r--framework/Log/TEventLog.php78
-rw-r--r--framework/Log/TLogManager.php145
-rw-r--r--framework/Log/TLogRouter.php144
-rw-r--r--framework/Log/TLogger.php57
-rw-r--r--framework/TApplication.php8
-rw-r--r--framework/Web/Services/TPageService.php8
-rw-r--r--framework/Web/THttpRequest.php2
-rw-r--r--framework/Web/THttpResponse.php12
-rw-r--r--framework/Web/UI/TAssetManager.php7
-rw-r--r--framework/Web/UI/TControl.php6
-rw-r--r--framework/Web/UI/TForm.php1
-rw-r--r--framework/Web/UI/TPage.php48
-rw-r--r--framework/Web/UI/TPageStatePersister.php4
-rw-r--r--framework/Web/UI/TTemplateControl.php4
-rw-r--r--framework/Web/UI/TTemplateManager.php4
-rw-r--r--framework/Web/UI/TThemeManager.php2
-rw-r--r--framework/core.php78
31 files changed, 226 insertions, 2647 deletions
diff --git a/.gitattributes b/.gitattributes
index 6e6aa3fb..cf7bc17b 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -416,22 +416,8 @@ framework/IO/SafeHtml/license.txt -text
framework/IO/SafeHtml/readme.txt -text
framework/IO/TSafeHtml.php -text
framework/IO/TTextWriter.php -text
-framework/Log/EventLog/context.php -text
-framework/Log/EventLog/exceptions/file_exception.php -text
-framework/Log/EventLog/exceptions/writer_exception.php -text
-framework/Log/EventLog/interfaces/writer.php -text
-framework/Log/EventLog/log.php -text
-framework/Log/EventLog/log_autoload.php -text
-framework/Log/EventLog/log_message.php -text
-framework/Log/EventLog/map.php -text
-framework/Log/EventLog/structs/log_filter.php -text
-framework/Log/EventLog/writers/writer_database.php -text
-framework/Log/EventLog/writers/writer_file.php -text
-framework/Log/EventLog/writers/writer_unix_file.php -text
-framework/Log/ILog.php -text
-framework/Log/TEventLog.php -text
-framework/Log/TLogManager.php -text
framework/Log/TLogRouter.php -text
+framework/Log/TLogger.php -text
framework/Security/TAuthManager.php -text
framework/Security/TAuthorizationRule.php -text
framework/Security/TMembershipManager.php -text
diff --git a/framework/Log/EventLog/context.php b/framework/Log/EventLog/context.php
deleted file mode 100644
index 518d411e..00000000
--- a/framework/Log/EventLog/context.php
+++ /dev/null
@@ -1,167 +0,0 @@
-<?php
-/**
- * File containing the ezcLogContext class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- * @access private
- */
-
-/**
- * Stores the contexts for the severities and sources.
- *
- * @package EventLog
- * @version //autogentag//
- * @access private
- */
-class ezcLogContext
-{
-
- /**
- * Stores the contexts for the severities.
- *
- * @var array(integer=>array)
- */
- protected $severityMap;
-
- /**
- * Stores the contexts for the sources.
- *
- * @var array(string=>array)
- */
- protected $sourceMap;
-
-
- /**
- * Resets this object to its initial state by removing all context mappings.
- *
- * @return void
- */
- public function reset()
- {
- unset( $this->severityMap );
- unset( $this->sourceMap );
- }
-
- /**
- * Set the context $context for the sevirities specified by $severityMask.
- *
- * If the severity already exist, the value will update the old value with
- * the new one.
- *
- * $context is of the format array('key'=>'value').
- *
- * @param int $severityMask
- * Bitmask that specifies all the event types that share the given
- * context.
- * @param array(string=>string) $context
- * @return void
- */
- public function setSeverityContext( $severityMask, $context )
- {
- // For all the matching bits, add the context to the array.
- $input = 1;
- while ( $input <= $severityMask )
- {
- if ( $severityMask & $input )
- {
- if ( !isset( $this->severityMap[$input] ) )
- {
- $this->severityMap[$input] = array();
- }
-
- $this->severityMap[$input] = array_merge( (array) $this->severityMap[$input], (array) $context );
- }
-
- $input <<= 1;
- }
- }
-
- /**
- * Remove the contexts for the severities given by $severityMask.
- *
- * $severityMask is a bitmask that specifies all the event types that should remove
- * their context.
- *
- * @param int $severityMask
- * @return void
- */
- public function unsetSeverityContext( $severityMask )
- {
- // For all the matching bits, remove the context.
- $input = 1;
- while ( $input <= $severityMask )
- {
- if ( $severityMask & $input )
- {
- unset( $this->severityMap[$input] );
- }
-
- $input <<= 1;
- }
- }
-
- /**
- * Set the context $context for each eventSource specified by $eventSources.
- *
- * If a certain key from the given context does already exist, the
- * new value will replace the value stored in the context itself. (Value is
- * updated).
- *
- * @param array(string) $eventSources
- * @param array(string=>string) $context
- * Specifies the keys and values that should be stored into this
- * context object.
- * @return void
- */
- public function setSourceContext($eventSources, $context )
- {
- foreach ( $eventSources as $eventSource )
- {
- if ( !isset( $this->sourceMap[$eventSource] ) )
- {
- $this->sourceMap[$eventSource] = array();
- }
-
- $this->sourceMap[$eventSource] = array_merge( (array) $this->sourceMap[$eventSource], (array) $context );
- }
- }
-
- /**
- * Remove the contexts for the given $eventSources.
- *
- * @param array(string) $eventSources
- * @return void
- */
- public function unsetSourceContext($eventSources )
- {
- foreach ( $eventSources as $eventSource )
- {
- unset( $this->sourceMap[$eventSource] );
- }
- }
-
- /**
- * Returns the complete context for the event type $eventType and event source $eventSource.
- *
- * If there is no context available this method will return an empty array.
- *
- *
- * @param int $eventType The integer that specifies the event type.
- * The range of this integer is 2^(N+):
- * ( 1, 2, 4, 8, ... )
- * @param string $eventSource
- * @return array
- */
- public function getContext( $eventType, $eventSource )
- {
- $a = isset( $this->severityMap[$eventType] ) ? $this->severityMap[$eventType] : array();
- $b = isset( $this->sourceMap[$eventSource] ) ? $this->sourceMap[$eventSource] : array();
- return array_merge( $a, $b );
- //return array_merge( (array) $this->severityMap[$eventType], (array) $this->sourceMap[$eventSource] );
- }
-
-}
-?>
diff --git a/framework/Log/EventLog/exceptions/file_exception.php b/framework/Log/EventLog/exceptions/file_exception.php
deleted file mode 100644
index 03f3ebb9..00000000
--- a/framework/Log/EventLog/exceptions/file_exception.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/**
- * File containing the ezcFileWriterException class.
- *
- * @package EventLog
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-/**
- * Exception thrown when a file error occures.
- *
- * @package EventLog
- * @version //autogen//
- */
-class ezcLogFileException extends Exception
-{
- /**
- * The file could not be found on the filesystem.
- */
- const FILE_NOT_FOUND = 1;
-
- /**
- * The file could not be read from the filesystem.
- */
- const FILE_NOT_READABLE = 2;
-
- /**
- * The file could not be written to the filesystem.
- */
- const FILE_NOT_WRITABLE = 3;
-
- /**
- * Constructs a new ezcLogFileExcpetion with the message $message and the error code $code.
- *
- * @param string $message
- * @param int $code
- */
- public function __construct( $message, $code )
- {
- parent::__construct( $message, $code );
- }
-}
-?>
diff --git a/framework/Log/EventLog/exceptions/writer_exception.php b/framework/Log/EventLog/exceptions/writer_exception.php
deleted file mode 100644
index ae82bf07..00000000
--- a/framework/Log/EventLog/exceptions/writer_exception.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/**
- * File containing the ezcLogWriterException class.
- *
- * @package EventLog
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-
-/**
- * The ezcLogWriterException will be thrown when an {@class ezcLogWriter} or
- * a subclass encounters an exceptional state.
- *
- * @package EventLog
- * @version //autogen//
- */
-class ezcLogWriterException extends Exception
-{
- /**
- * Constructs a new ezcLogWriterException with the message $message.
- *
- * @param string $message
- */
- public function __construct( $message )
- {
- parent::__construct( $message, 0 );
- }
-}
-?>
diff --git a/framework/Log/EventLog/interfaces/writer.php b/framework/Log/EventLog/interfaces/writer.php
deleted file mode 100644
index 82481e36..00000000
--- a/framework/Log/EventLog/interfaces/writer.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/**
- * File containing the ezcLogWriter interface.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-
-/**
- * ezcLogWriter defines the common interface for all classes that implement
- * their log writer.
- *
- * See the ezcLogFileWriter for an example of creating your own log writer.
- *
- * @package EventLog
- * @version //autogentag//
- */
-interface ezcLogWriter
-{
- /**
- * Writes the message $message to the log.
- *
- * The writer can use the severity, source, and category to filter the
- * incoming messages and determine the location where the messages should
- * be written.
- *
- * The array $optional contains extra information that can be added to the log. For example:
- * line numbers, file names, usernames, etc.
- *
- * @throws ezcLogWriterException when the log writer was unable to write the log message.
- *
- * @param string $message
- * @param int $severity
- * ezcLog::DEBUG, ezcLog::SUCCES_AUDIT, ezcLog::FAIL_AUDIT, ezcLog::INFO, ezcLog::NOTICE,
- * ezcLog::WARNING, ezcLog::ERROR or ezcLog::FATAL.
- * $param string $source
- * @param string $category
- * @param array(string=>string) $optional
- * @return void
- */
- public function writeLogMessage( $message, $severity, $source, $category, $optional = array() );
-}
-?>
diff --git a/framework/Log/EventLog/log.php b/framework/Log/EventLog/log.php
deleted file mode 100644
index a99569dd..00000000
--- a/framework/Log/EventLog/log.php
+++ /dev/null
@@ -1,644 +0,0 @@
-<?php
-/**
- * File containing the ezcLog class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-
-/**
- * The ezcLog class records log messages and audit trails to one or multiple
- * writers.
- *
- * Available writers are:
- * - {@link ezcLogWriterUnixFile Unix File} writer
- * - {@link ezcLogWriterDatabase Database} writer
- *
- * Extra writers can be added by implementing the the {@link ezcLogWriter} interface.
- *
- * Use the {@link map()} method to attach an additional writer to the ezcLog
- * class. This method filters incoming log messages with the {@link ezcLogFilter}.
- * Log messages that are accepted, match with the filter, are sent to the
- * {@link ezcLogWriter}.
- *
- * The following example demonstrates how all log messages, except for the
- * audit trailing and debug messages, are written to a file.
- * <code>
- * $filter = new ezcLogFilter();
- * $filter->severity = ezcLog::INFO | ezcLog::NOTICE | ezcLog::WARNING | ezcLog::ERROR | ezcLog::FATAL;
- *
- * $log = ezcLog::getInstance();
- * $log->map( $filter, new ezcLogWriterUnixFile( "/tmp/logs/", "error.log" ) );
- * </code>
- *
- * The log messages with the severity: INFO, NOTICE, WARNING, ERROR, and FATAL will
- * be written to the file: "/tmp/logs/error.log". See {@link ezcLogWriterUnixFile} for
- * the description of the file format.
- *
- * The following example will write the audit trails to the database:
- * <code>
- * $filter = new ezcLogFilter();
- * $filter->severity = ezcLog::SUCCESS_AUDIT | ezcLog::FAILED_AUDIT;
- *
- * $log = ezcLog::getInstance();
- * $log->map( $filter, new ezcLogWriterDatabase( "audits" ) );
- * </code>
- *
- * The audit trails will be stored in the table "audits". See {@link ezcLogWriterDatabase}
- * for creating the appropriate tables and setting up the database.
- *
- * It is also possible to exclude messages from going to a specific writer.
- * This is done via the {@link unmap()} method. The following example shows
- * how all messages, except for the DEBUG severity, are written to a file:
- * <code>
- * $fileWriter = ezcLogWriterUnixFile( "/tmp/logs/", "all.log" );
- * $filter = new ezcLogFilter();
- * $ezcLog::getInstance()->map( $filter, $fileWriter ); // All severities.
- *
- * $filter->severity = ezcLog::DEBUG;
- * ezcLog::getInstance()->unmap( $filter, $fileWriter ); // Remove DEBUG severity.
- * </code>
- *
- * Use the {@link log()} method to log messages at the specified writers. This
- * method expects a:
- * - Message, contains a single log message.
- * - Severity, indicates the level of importance.
- * - Extra attributes (optional).
- *
- * Although the interpretation of the severity levels are up to the programmer,
- * the most common interpretations are:
- * - DEBUG: Records information about the progress in the program and references
- * source code functions. Knowledge of the source code is needed to interpret
- * this log message.
- * - INFO: Informative logging at a detailed level. This logging method produces a
- * high level of logging, which is unmanageable on a production environment.
- * Usually INFO logging is only enabled to help by analysing a problem.
- * - NOTICE: Informative logging at a lower detail level than INFO logging.
- * Only major stages are recorded and is useful to monitor a low volume system.
- * - WARNING: Something unexpected happened, but did not cause any loss of service.
- * - ERROR: An error occured, which may cause partial loss of service. Usually the
- * system can recover.
- * - FATAL: An serious error occured and the system is unlikely to recover.
- * - SUCCESS_AUDIT: Informative logging about a successful completion of work by
- * a module completed. Useful to trace system changes directly or indirectly
- * done by a user.
- * - FAILED_AUDIT: Informative logging about an action from a module
- * with a negative result. A failed login will most likely added to this severity.
- *
- * The next example logs a fatal error and has no extra attributes:
- * <code>
- * ezcLog::getInstance()->log( "Cannot open ini file: <$file>", ezcLog::FATAL );
- * </code>
- *
- * The log message will get by default the category and source: "default". The
- * default values can be modified by changing, respectively, the properties:
- * category and source. Their use is as follows:
- * - Source, definition of the global location where the log message comes from.
- * Some examples are: module, source file, extension, etc. The source depends
- * also on the severity of the message. For DEBUG messages is the source file
- * more important whereas for a FATAL error the module is sufficient.
- * - Category, definition of the message group. Again the category is related to
- * the severity. The non audit trails can group the log messages like: Database
- * (or even the database types), Templates, etc. For audit trails it makes
- * much sense to categorize the actions. For example: security, modified content,
- * published content, shop, etc.
- *
- * An example of a Payment checker is as follows:
- * <code>
- * // The start of the Payment module.
- * $log = ezcLog::getInstance();
- * $log->source = "Payment checker"; // Change the default source.
- *
- * $log->log( "Checking the received amount", ezcLog::INFO, array( "shop" ) );
- *
- * if( !$eZPay->receivedAmount() != $requiredAmount )
- * {
- * $log->log( "Received amount: <".$eZPay->receivedAmount()."> expected: <$requiredAmount>.",
- * ezcLog::DEBUG,
- * array( "category" => "shop", "file" => __FILE__, "line" => __LINE )
- * );
- *
- * $log->log( "Insufficient amount.",
- * ezcLog::FAILED_AUDIT,
- * array( "UserName" => getCurrentUser(), category => "Payment" )
- * )
- *
- * $log->log( "Rollback amount not implemented, cannot recover, ezcLog::FATAL );
- * exit();
- * }
- * </code>
- *
- * Sometimes information repeats for specific severities or categories. For example that
- * for the audit trails an username is required. Convenience methods like:
- * {@link setSeverityAttributes()} and {@link setSourceAttributes()} exist to append
- * information automatically to the log message.
- *
- * The ezcLog class provides a {@link trigger_error()} log handler: {@link ezcLog::LogHandler()}.
- * Using the trigger_error method makes your code less Log package dependent and
- * produces less overhead when logging is disabled.
- *
- * See the {@link ezcLog::LogHandler()} method for more information about how to set up the
- * trigger_error functionality.
- *
- * See the {@link ezcDebug} package for more detailed information about writing DEBUG
- * messages.
- *
- * @package EventLog
- * @version //autogentag//
- */
-class ezcLog
-{
- /**
- * Debug severity constant.
- */
- const DEBUG = 1;
-
- /**
- * Success audit severity constant.
- */
- const SUCCESS_AUDIT = 2;
-
- /**
- * Failed audit severity constant.
- */
- const FAILED_AUDIT = 4;
-
- /**
- * Info severity constant.
- */
- const INFO = 8;
-
- /**
- * Notice severity constant.
- */
- const NOTICE = 16;
-
- /**
- * Warning severity constant.
- */
- const WARNING = 32;
-
- /**
- * Error severity constant.
- */
- const ERROR = 64;
-
- /**
- * Fatal severity constant.
- */
- const FATAL = 128;
-
- /**
- * Holds the properties of this class.
- *
- * @var array(string=>mixed)
- */
- private $properties = array();
-
- /**
- * Contains the logic of mapping an incoming log message to the writer.
- *
- * @var ezcLogMap
- */
- protected $writers;
-
- /**
- * Stores the attributes from the eventTypes and eventSources.
- *
- * $var ezcLogContext
- */
- protected $context;
-
- /**
- * Stores the instance of this class.
- *
- * @var ezcLog
- */
- private static $instance = null;
-
- /**
- * Stores the setting whether writer exceptions should be thrown.
- *
- * @var bool
- */
- private $throwWriterExceptions = true;
-
- /**
- * Constructs an empty ezcLog instance.
- *
- * This constructor is private as this class should be used as a
- * singleton. Use the getInstance() method instead to get an ezcLog instance.
- */
- private function __construct()
- {
- $this->reset();
- }
-
- /**
- * Returns the instance of the class.
- *
- * @return ezcLog
- */
- public static function getInstance()
- {
- if ( is_null( self::$instance ) )
- {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * Sets the property $name to $value.
- *
- * @throws ezcBasePropertyNotFoundException if the property does not exist.
- * @param string $name
- * @param mixed $value
- * @return void
- */
- public function __set( $name, $value )
- {
- switch ( $name )
- {
- case "source":
- case "category":
- $this->properties[$name] = $value;
- return;
- }
-
- throw new ezcBasePropertyNotFoundException( $name );
- }
-
- /**
- * Returns the property $name.
- *
- * @throws ezcBasePropertyNotFoundException if the property does not exist.
- * @param string $name
- * @return mixed
- */
- public function __get( $name )
- {
- switch ( $name )
- {
- case "source":
- case "category":
- return $this->properties[$name];
- }
-
- throw new ezcBasePropertyNotFoundException( $name );
- }
-
- /**
- * Resets the log instance to its initial state.
- *
- * All sourceAttributes, severityAttributes, and writers will be removed.
- * The default source and category are also reset.
- *
- * @return void
- */
- public function reset()
- {
- $this->writers = new ezcLogMap();
- $this->context = new ezcLogContext();
-
- $this->setDefaults();
- }
-
- /**
- * Sets the source and category defaults to "default".
- *
- * @return void
- */
- protected function setDefaults()
- {
- $this->source = "default";
- $this->category = "default";
- }
-
- /**
- * Enables or disables writer exceptions with the boolean $enable.
- *
- * Typically you want to have exceptions enabled while developing your application
- * in order to catch potential problems. A live server however, should not throw
- * a deadly exception when a relatively unimportant debug message could not be written to
- * the log file. For these setups you can disable writer exceptions.
- *
- * @param bool $enable
- * @return void
- */
- public function throwWriterExceptions( $enable )
- {
- $this->throwWriterExceptions = $enable;
- }
-
- /**
- * Write the message $message with additional information to one or multiple log writers.
- *
- * The log message $message, severity $severity, and extra attributes $attributes are sent to
- * the writers that matches with the {@link ezcLogFilter}. The following parameters are
- * taken in the comparation with the ezcLogFilter:
- * - $severity: the severity of the log message.
- * - $attributes[ "source" ]: the source from where the log message comes.
- * - $attributes[ "category" ]: the category of the log message.
- *
- * See for more information about filter matching the classes {@link ezcLog} and
- * {@link ezcLogFilter}.
- *
- * The message $message describes what happened. The severity $severity is one of the ezcLog constants:
- * - DEBUG: Records information about the progress in the program and references
- * source code functions. Knowledge of the source code is needed to interpret
- * this log message.
- * - INFO: Informative logging at a detailed level. This logging method produces a
- * high level of logging, which is unmanageable on a production environment.
- * Usually INFO logging is only enabled to help by analysing a problem.
- * - NOTICE: Informative logging at a lower detail level than INFO logging.
- * Only major stages are recorded and is useful to monitor a low volume system.
- * - WARNING: Something unexpected happened, but did not cause any loss of service.
- * - ERROR: An error occured, which may cause partial loss of service. Usually the
- * system can recover.
- * - FATAL: An serious error occured and the system is unlikely to recover.
- * - SUCCESS_AUDIT: Informative logging about a successful completion of work by
- * a module completed. Useful to trace system changes directly or indirectly
- * done by a user.
- * - FAILED_AUDIT: Informative logging about an action from a module
- * with a negative result. A failed login will most likely added to this severity.
- *
- * The attributes array $attributes can have one or multiple attributes that will
- * be added to the log. If source and category are given, they will override the default
- * source or category given as property to this object. Further more it is up to the
- * application what to include in the log. It may be useful to add the
- * file and linenumber to the attributes array. Use the magic PHP constants: {@link __FILE__}
- * and {@link __LINE__} for this purpose. The next example adds an warning to the log.
- *
- * <code>
- * ezcLog::getInstance()->source = "templateEngine"; // Set the default source.
- * ezcLog::getInstance()->log( "ezcPersistentObject <$obj> does not exist.",
- * ezcLog::WARNING,
- * array( "category" => "Database", "line" => __LINE__, "file" => __FILE__, "code" => 123 )
- * );
- * </code>
- *
- * The methods {@link setSeverityAttributes()} and {@link setSourceAttributes()} can automatically
- * add attributes to log messages based on, respectively, the severity and source.
- *
- * See also {@link LogHandler()} on how to use {@link trigger_error()} to write log messages.
- *
- * @throws ezcLogWriterException if {@link throwWriterExceptions} are enabled and a log entry
- * could not be written.
- *
- * @param string $message
- * @param int $severity One of the following severity constants:
- * DEBUG, SUCCES_AUDIT, FAIL_AUDIT, INFO, NOTICE, WARNING, ERROR, or FATAL.
- * @param array(string=>string) $attributes
- * @return void
- */
- public function log( $message, $severity, $attributes = array() )
- {
- $source = ( isset( $attributes["source"] ) ? $attributes["source"] : $this->properties["source"] );
- $category = ( isset( $attributes["category"] ) ? $attributes["category"] : $this->properties["category"] );
-
- unset( $attributes["source"] );
- unset( $attributes["category"] );
-
- $writers = $this->writers->get( $severity, $source, $category );
- foreach ( $writers as $writer )
- {
- try
- {
- $writer->writeLogMessage( $message, $severity, $source, $category, $attributes );
- }
- catch ( ezcLogWriterException $e )
- {
- if ( $this->throwWriterExceptions )
- {
- throw $e;
- }
- }
- }
- }
-
- /**
- * Attaches the writer $writer with the filter $logFilter to this ezcLog.
- *
- * The log filter $logFilter describes which severities, categories, and
- * sources are accepted by the writer $writer. Those messages that
- * match are send to the writer.
- *
- * Multiple logFilters with their writer can be attached to the ezcLog class.
- * Every log message will be sent to the writer for which the log filter matches.
- *
- * Available writers are:
- * - {@link ezcLogWriterUnixFile Unix File} writer
- * - {@link ezcLogWriterDatabase Database} writer
- *
- * Extra writers can be added by implementing the the {@link ezcLogWriter} interface.
- *
- * The following example maps the Unix file writer to all the log messages that
- * are from the category "template", source "content_module" and severities
- * WARNING, ERROR, or FATAL.
- * <code>
- * $f = new ezclogFilter();
- * $f->severity = ezcLog::WARNING | ezcLog::ERROR | ezcLog::FATAL;
- * $f->source = "template";
- * $f->category = "content_module";
- *
- * $w = new ezcLogWriterUnixFile("/tmp/logs/content_module/", "template.log" );
- *
- * $ezcLog::getInstance()->map( $f, $w );
- * </code>
- *
- * See also {@link unmap()}
- *
- * @param ezcLogFilter $logFilter
- * @param ezcLogWriter $writer
- * @return void
- */
- public function map( ezcLogFilter $logFilter, ezcLogWriter $writer )
- {
- $this->writers->map( $logFilter->severity, $logFilter->source, $logFilter->category, $writer );
- }
-
- /**
- * Detaches the writer $writer for specific log messages, specified by the log filter $logFilter.
- *
- * The log filter $logFilter describes which severities, categories, and
- * sources are no longer accepted by the writer $writer.
- *
- * See the {@link map()} method for information about attaching a filter.
- *
- * The following example shows how to log all messages, except the debug message:
- * <code>
- * $fileWriter = ezcLogWriterUnixFile( "/tmp/logs/", "all.log" );
- * $filter = new ezcLogFilter();
- * $ezcLog::getInstance()->map( $filter, $fileWriter ); // All severities.
- *
- * $filter->severity = ezcLog::DEBUG;
- * ezcLog::getInstance()->unmap( $filter, $fileWriter ); // Remove DEBUG severity.
- * </code>
- *
- * See also {@link map()}
- *
- * @param ezcLogFilter $logFilter
- * @param ezcLogWriter $writer
- * @return void
- */
- public function unmap( ezcLogFilter $logFilter, ezcLogWriter $writer )
- {
- $this->writers->unmap( $logFilter->severity, $logFilter->source, $logFilter->category, $writer );
- }
-
- /**
- * Sets the attributes $attributes for a group of severities $severityMask.
- *
- * The severities are specified with a bit mask. These attributes will be
- * added to the log message when the log severity is the same as specified
- * here.
- *
- * Example:
- * <code>
- * ezcLog::getInstance()->setSeverityAttributes(
- * ezcLog::SUCCESS_AUDIT | ezcLog::FAILED_AUDIT
- * array( "username" => "Jan K. Doodle" )
- * );
- * </code>
- *
- * Every log message that has the severity SUCCESS_AUDIT or FAILED_AUDIT
- * includes the user name: "Jan K. Doodle".
- *
- * @param integer $severityMask Multiple severities are specified with a logic-or.
- * @param array(string=>string) $attributes
- * @return void
- */
- public function setSeverityAttributes( $severityMask, $attributes )
- {
- $this->context->setSeverityContext( $severityMask, $attributes );
- }
-
- /**
- * Sets the attributes $attributes for a group of sources $sources.
- *
- * The sources are specified in an array. These attributes will be added to the
- * log message when it matches with the given $sources.
- *
- * Example:
- * <code>
- * ezcLog::getInstance()->setSourceAttributes(
- * array( "Paynet", "Bibit", "Paypal" ),
- * array( "MerchantID" => $merchantID )
- * );
- * </code>
- *
- * Every log message that comes from the payment module: Paynet, Bibit, or Paypal
- * includes the Merchant ID.
- *
- * @param array(string) $sources
- * @param array(string => string) $attributes
- * @return void
- */
- public function setSourceAttributes ( $sources, $attributes )
- {
- $this->context->setSourceContext( $sources, $attributes );
- }
-
- /**
- * This method can be set as error_handler to log using {@link trigger_error()}.
- *
- * This method can be assigned with the {@link set_error_handler()} to handle the
- * trigger_error calls. This method will get the log instance and forward the
- * message. But includes the following information:
- * - The file and linenumber are automatically added.
- * - Source and category can be 'encoded' in the message.
- *
- * The message format is as follows:
- * <pre>
- * [ source, category ] Message
- * </pre>
- *
- * When one name is given between the brackets, the category will be set and the message has a default source:
- * <pre>
- * [ category ] Message
- * </pre>
- *
- * Without any names between the brackets, the default category and source are used:
- * <pre>
- * Message
- * </pre>
- *
- * The following example creates manually an error handler and forwards the
- * ERROR, WARNING and NOTICE severities.
- * <code>
- * public function MyLogHandler($errno, $errstr, $errfile, $errline)
- * {
- * switch ($errno)
- * {
- * case E_USER_ERROR:
- * case E_USER_WARNING:
- * case E_USER_NOTICE:
- * if ( $loggingEnabled )
- * { // Forward the message to the log handler.
- * ezcLog::LogHandler( $errno, $errstr, $errfile, $errline );
- * }
- * break;
- *
- * default:
- * print( "$errstr in $errfile on line $errline\n" );
- * break;
- * }
- * }
- *
- * // Register MyLogHandler
- * set_error_handler( "MyLogHandler" );
- *
- * // Write an warning to the log.
- * trigger_error( "[paynet, transaction] Didn't get a callback from the Paynet service", E_USER_WARNING );
- *
- * // Add a notice.
- * trigger_error( "Getting paynet status information", E_USER_NOTICE );
- *
- * </code>
- *
- * Notice that the ezcLog component is not loaded at all when the logging is disabled.
- *
- * @param int $errno
- * @param int $erstr
- * @param string $errfile
- * @param int $errline
- * @return void
- */
- public static function logHandler( $errno, $errstr, $errfile, $errline )
- {
- $log = ezcLog::getInstance();
- $lm = new ezcLogMessage( $errstr, $errno, $log->source, $log->category );
- $log->log(
- $lm->message, $lm->severity,
- array( "source" => $lm->source, "category" => $lm->category, "file" => $errfile, "line" => $errline )
- );
- }
-
- /**
- * Translates the severity constant to a string and returns this.
- *
- * Null is returned when the severity constant is invalid.
- *
- * @param int $severity
- * @return string
- */
- public static function translateSeverityName( $severity )
- {
- switch ( $severity )
- {
- case self::DEBUG: return "Debug";
- case self::SUCCESS_AUDIT: return "Success audit";
- case self::FAILED_AUDIT: return "Failed audit";
- case self::INFO: return "Info";
- case self::NOTICE: return "Notice";
- case self::WARNING: return "Warning";
- case self::ERROR: return "Error";
- case self::FATAL: return "Fatal";
- default: return null;
- }
- }
-}
-?>
diff --git a/framework/Log/EventLog/log_autoload.php b/framework/Log/EventLog/log_autoload.php
deleted file mode 100644
index 06e981bc..00000000
--- a/framework/Log/EventLog/log_autoload.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * Autoloader definition for the Translation component.
- *
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- * @version //autogentag//
- * @filesource
- * @package EventLog
- */
-
-return array(
- 'ezcLog' => 'EventLog/log.php',
- 'ezcLogMap' => 'EventLog/map.php',
- 'ezcLogContext' => 'EventLog/context.php',
- 'ezcLogMessage' => 'EventLog/log_message.php',
- 'ezcLogWriter' => 'EventLog/interfaces/writer.php',
- 'ezcLogWriterFile' => 'EventLog/writers/writer_file.php',
- 'ezcLogWriterUnixFile' => 'EventLog/writers/writer_unix_file.php',
- 'ezcLogWriterDatabase' => 'EventLog/writers/writer_database.php',
- 'ezcLogFilter' => 'EventLog/structs/log_filter.php',
- 'ezcLogFileException' => 'EventLog/exceptions/file_exception.php',
- 'ezcLogWriterException'=> 'EventLog/exceptions/writer_exception.php'
-);
-?>
diff --git a/framework/Log/EventLog/log_message.php b/framework/Log/EventLog/log_message.php
deleted file mode 100644
index 4ba61e39..00000000
--- a/framework/Log/EventLog/log_message.php
+++ /dev/null
@@ -1,169 +0,0 @@
-<?php
-/**
- * File containing the ezcLogMessage class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- * @access private
- */
-
-/**
- * Holds a log message and provides convenience methods to read the information.
- *
- * The ezclogMessage class is used for subtracting the information from the message
- * parameter from {@link trigger_error()}. See the {@link ezcLog::logHandler} for
- * more information.
- *
- * The message formats that can be parsed are:
- * <pre>
- * [ source, category ] Message
- * </pre>
- *
- * When one name is given between the brackets, the category will be set and the message has a default source:
- * <pre>
- * [ category ] Message
- * </pre>
- *
- * Without any names between the brackets, the default category and source are used:
- * <pre>
- * Message
- * </pre>
- *
- * The following properties are set after construction or after calling {@link parseMessage()}:
- * - message, contains the message without extra the additional information.
- * - source, contains either the default source or the source set in the incoming message.
- * - category, contains either the default category or the category set in the incoming message.
- * - severity, severity of the error. Which is ezcLog::NOTICE, ezcLog::WARNING, or ezcLog::ERROR.
- *
- * @package EventLog
- * @version //autogentag//
- * @access private
- */
-class ezcLogMessage
-{
- /**
- * Holds the properties of this class.
- *
- * @var array(string=>mixed)
- */
- protected $properties = array( "message" => "", "source" => "", "category" => "", "severity" => "" );
-
-
- /**
- * Sets the property $name to $value.
- *
- * @throws ezcBasePropertyNotFoundException if the property does not exist.
- * @param string $name
- * @param mixed $value
- * @return void
- */
- public function __set( $name, $value )
- {
- switch ( $name )
- {
- case 'message':
- $this->properties['message'] = $value;
- break;
- case 'source':
- $this->properties['source'] = $value;
- break;
- case 'category':
- $this->properties['category'] = $value;
- break;
- case 'severity':
- $this->properties['severity'] = $value;
- break;
-
- default:
- throw new ezcBasePropertyNotFoundException( $name );
- }
-
- }
-
- /**
- * Returns the property $name.
- *
- * @throws ezcBasePropertyNotFoundException if the property does not exist.
- * @param string $name
- * @return mixed
- */
- public function __get( $name )
- {
- switch ( $name )
- {
- case 'message':
- return $this->properties['message'];
- break;
- case 'source':
- return $this->properties['source'];
- break;
- case 'category':
- return $this->properties['category'];
- break;
- case 'severity':
- return $this->properties['severity'];
- break;
- }
-
- throw new ezcBasePropertyNotFoundException( $name );
- }
-
- /**
- * Constructs the ezcLogMessage from the $message, $severity, $defaultSource and $defaultCategory.
- *
- * $message is parsed by parseMessage() and properties are set.
- *
- * @param string $message
- * @param int $severity
- * @param string $defaultSource Use this source when not given in the message itself.
- * @param string $defaultCategory Use this category when not give in the message itself.
- */
- public function __construct( $message, $severity, $defaultSource, $defaultCategory )
- {
- $this->parseMessage( $message, $severity, $defaultSource, $defaultCategory );
- }
-
- /**
- * Parses the message $message and sets the properties.
- *
- * See the general class documentation for message format.
- * The severity $severity is a E_USER_* PHP constant. The values will be translated accordingly:
- * - E_USER_NOTICE -> ezcLog::NOTICE
- * - E_USER_WARNING -> ezcLog::WARNING
- * - E_USER_ERROR -> ezcLog::ERROR
- *
- * @param string $message
- * @param int $severity
- * @param string $defaultSource
- * @param string $defaultCategory
- * @return void
- */
- public function parseMessage( $message, $severity, $defaultSource, $defaultCategory )
- {
- preg_match( "/^\s*(?:\[([^,\]]*)(?:,\s(.*))?\])?\s*(.*)$/", $message, $matches );
-
- $this->message = ( strcmp( $matches[3], "" ) == 0 ? false : $matches[3] );
-
- if ( strlen( $matches[2] ) == 0 )
- {
- $this->category = ( strcmp( $matches[1], "" ) == 0 ? $defaultCategory : $matches[1] );
- $this->source = $defaultSource;
- }
- else
- {
- $this->category = $matches[2];
- $this->source = $matches[1];
- }
-
- switch ( $severity )
- {
- case E_USER_NOTICE: $this->severity = ezcLog::NOTICE; break;
- case E_USER_WARNING: $this->severity = ezcLog::WARNING; break;
- case E_USER_ERROR: $this->severity = ezcLog::ERROR; break;
- default: $this->severity = false;
- }
- }
-}
-?>
diff --git a/framework/Log/EventLog/map.php b/framework/Log/EventLog/map.php
deleted file mode 100644
index 2c4f72f7..00000000
--- a/framework/Log/EventLog/map.php
+++ /dev/null
@@ -1,386 +0,0 @@
-<?php
-/**
- * File containing the ezcLogMap class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- * @access private
- */
-
-/**
- * Fast mapping of a mixed variable to an eventType, eventSource and eventCategory.
- *
- * This class is used in ezcLog to map writers to the log messages they
- * are supposed to write. It is important that the get() method is extremely
- * fast since it will be called for each log message.
- *
- * If every combination of eventTypes, eventSources, and eventCategories are
- * combined (product) and placed in one hash-table. The table grows too fast.
- * Imagine: 7 types * 10 sources * 10 categories = 700 entries in the hash.
- *
- * Our solution:
- * Most probably the amount of writers will be limited. So every writer
- * (result) is one bit (of an integer).
- *
- * The hashes: Type, Source, and Category map the input strings to an integer.
- * These integers are AND with each other, and the result is again stored in a
- * hash.
- *
- *
- * @package EventLog
- * @version //autogentag//
- * @access private
- */
-class ezcLogMap
-{
- /**
- * Hashtable that binds a single eventType to a bitmask. The possible
- * key-values are: 1, 2, 4, 8, ...
- *
- * @var array(integer=>bitmask)
- */
- protected $structure;
-
-
- public function __construct()
- {
- $this->result = array();
- }
-
- /**
- * Map the object $object to the given $eventTypeMask, $eventSources and $eventCategories.
- *
- * Example:
- * <code>
- * [ eventType x eventSource x eventCategory ] |-> [ object ]
- * </code>
- *
- * @param int $eventTypeMask
- * @param array(string) $eventSources
- * @param array(string) $eventCategories
- * @param object $object
- *
- * @return void
- */
- public function map( $eventTypeMask, $eventSources, $eventCategories, $object )
- {
- $eventTypes = $this->getMaskArray( $eventTypeMask );
- $result = array( $object );
-
- if ( count( $eventTypes ) == 0 )
- {
- $eventTypes = array( "*" );
- }
- if ( count( $eventSources ) == 0 )
- {
- $eventSources = array( "*" );
- }
- if ( count( $eventCategories ) == 0)
- {
- $eventCategories = array( "*" );
- }
- $c = $this->createMinimumHash( $eventCategories, $result );
- $s = $this->createMinimumHash( $eventSources, $c );
- $new = $this->createMinimumHash( $eventTypes, $s );
-
- $this->mergeHash( $new, $this->structure, $history );
- }
-
- /**
- * Unmap the object $object to the given $eventTypeMask, $eventSources and $eventCategories.
- *
- * @param int $eventTypeMask
- * @param array(string) $eventSources
- * @param array(string) $eventCategories
- * @param object $object
- *
- * @return void
- */
- public function unmap( $eventTypeMask, $eventSources, $eventCategories, $object)
- {
- $eventTypes = $this->getMaskArray( $eventTypeMask );
-
- $result = array( $object );
-
- if ( count( $eventTypes ) == 0 )
- {
- $eventTypes = array( "*" );
- }
- if ( count( $eventSources ) == 0 )
- {
- $eventSources = array( "*" );
- }
- if ( count( $eventCategories ) == 0)
- {
- $eventCategories = array( "*" );
- }
-
- $c = $this->createMinimumHash( $eventCategories, $result );
- $s = $this->createMinimumHash( $eventSources, $c );
- $new = $this->createMinimumHash( $eventTypes, $s );
-
- $this->unmergeHash( $this->structure, $new, $history );
- }
-
-
- /**
- * Fills the array $out with the keys $inKeys and the value $inValue.
- *
- * @param array inKeys
- * @param mixed $inValue
- * @param array &$out
- * @return array
- */
- protected function createMinimumHash($inKeys, $inValue )
- {
- foreach ( $inKeys as $key )
- {
- $out[$key] = $inValue;
- }
- return $out;
- }
-
- /**
- *
- *
- * @return void
- **/
- protected function mergeSingle( &$in, &$history )
- {
- $extra = $this->get( $history[0], $history[1], $history[2] );
- $extra = array_merge( $in, $extra );
-
- $tmp =& $this->structure[$history[0]];
- $tmp =& $tmp[$history[1]];
- $tmp =& $tmp[$history[2]];
-
- foreach ( $extra as $inKey => $inVal )
- {
- if ( !isset( $tmp ) || !in_array( $inVal, $tmp ) )
- {
- if ( is_numeric( $inKey ) )
- {
- $tmp[] = $inVal;
- }
- else
- {
- $tmp[$inKey] =& $inVal;
- }
- }
- }
- }
-
-
- // XXX should change out.. the way it is now.
- protected function mergeHash( &$in, $out, &$history )
- {
- $depth = count( $history );
-
- if ( $depth == 3 )
- {
- $this->mergeSingle( $in, $history );
- }
-
- $i = 0;
- foreach ( $in as $inKey => $inVal )
- {
- $history[$depth] = $inKey;
-
- if ( strcmp( $inKey, "*" ) == 0)
- {
- if ( is_array( $out ) )
- {
- foreach ( $out as $outKey => $outVal )
- {
- $history[$depth] = $outKey;
- $this->mergeHash( $in[$inKey], $out[$outKey], $history );
- }
- }
- }
-
- $history[$depth] = $inKey;
- if ( is_array( $inVal ) )
- {
- if ( is_numeric( $inKey ) )
- {
- // FIXME
- $this->mergeHash( $in[$inKey], $out, $history );
- }
- else
- {
- //$this->mergeHash( $in[$inKey], $out[$inKey], $history );
- $this->mergeHash( $in[$inKey], $out, $history );
- }
- }
-
- }
- array_pop( $history );
- }
-
-
- // XXX: ugly, should get a rewrite.
- protected function unmergeHash( &$out, &$in, &$history )
- {
- $depth = count( $history );
-
- if ( $depth == 3 )
- {
- foreach ( $in as $inKey => $inVal )
- {
- if ( !isset( $out ) || in_array( $inVal, $out ) )
- {
- if ( is_array( $out ) )
- {
- foreach ( $out as $outKey => $outVal )
- {
- if ( $outVal === $inVal )
- {
- unset( $out[$outKey] );
- $result = true;
- }
- }
- }
- }
- }
- }
-
- foreach ( $in as $inKey => $inVal )
- {
- $history[$depth] = $inKey;
-
- if ( strcmp( $inKey, "*" ) == 0)
- {
- if ( is_array( $out ) )
- {
- foreach ( $out as $outKey => $outVal )
- {
- $this->unmergeHash( $out[$outKey], $in[$inKey], $history );
- }
- }
- }
-
- if ( is_array( $inVal ) )
- {
- $this->unmergeHash( $out[$inKey], $in[$inKey], $history );
- }
- }
- array_pop( $history );
- }
-
-
- /**
- * Returns the bits set in $mask as separate values in an array.
- *
- * @return array(int)
- */
- protected function getMaskArray( $mask )
- {
- $result = array();
-
- $input = 1;
- while ( $input <= $mask )
- {
- if ( $mask & $input )
- {
- $result[] = $input;
- }
- $input <<= 1;
- }
-
- return $result;
- }
-
- /**
- * Returns an array with objects are mapped to the key generated by $eventType, $eventSource and $eventCategory.
- *
- * The eventType is an integer from in the range: 2^x with x -> N+.
- * (1, 2, 4, 8, 16, ... )
- *
- * @param int $eventType
- * @param string $eventSource
- * @param string $eventCategory
- * @return array(object).
- */
- public function get( $eventType, $eventSource, $eventCategory)
- {
- $tmp = $this->structure;
-
-
- if ( isset( $tmp[$eventType] ) )
- {
- $tmp = $tmp[$eventType];
- }
- else if ( isset( $tmp [ "*" ] ) )
- {
- $tmp = $tmp["*"];
- }
- else
- {
- return array();
- }
-
- if ( isset( $tmp[$eventSource] ) )
- {
- $tmp = $tmp[$eventSource];
- }
- else if ( isset( $tmp [ "*" ] ) )
- {
- $tmp = $tmp["*"];
- }
- else
- {
- return array();
- }
-
- if ( isset( $tmp[$eventCategory] ) )
- {
- $tmp = $tmp[$eventCategory];
- }
- else if ( isset( $tmp [ "*" ] ) )
- {
- $tmp = $tmp["*"];
- }
- else
- {
- return array();
- }
-
- return $tmp;
- }
-
-
- public function printStructure()
- {
- $this->printStructureRecursive( $this->structure, $history = array() );
- }
-
- protected function printStructureRecursive( $structure, &$history )
- {
- $depth = count( $history );
- if ( $depth == 3 )
- {
- $tmp =& $this->structure[$history[0]];
- $tmp =& $tmp[$history[1]];
- $tmp =& $tmp[$history[2]];
-
- if ( isset( $tmp ) )
- {
- foreach ( $tmp as $key => $val )
- {
- echo $history[0] . " " . $history[1] . " " . $history[2] . " [ $key => $val ]\n";
- }
- }
-
- return;
- }
-
- foreach ( $structure as $key => $val )
- {
- $history[$depth] = $key;
- $this->printStructureRecursive( $structure, $history );
- }
- }
-}
-?>
diff --git a/framework/Log/EventLog/structs/log_filter.php b/framework/Log/EventLog/structs/log_filter.php
deleted file mode 100644
index 451b0c65..00000000
--- a/framework/Log/EventLog/structs/log_filter.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-/**
- * File containing the ezcLogFilter class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license BSD {@link http://ez.no/licenses/bsd}
- */
-
-/**
- * The ezcLogFilter class provides a structure to set a log filter.
- *
- * ezcLogFilter has three public member variables:
- * - severity, contains the severity of the log message.
- * - source, contain the source of the log message.
- * - category, contains the category of the log message.
- *
- * Severity is an integer mask that expects one more multiple ezcLog severity constants.
- * Multiple values can be assigned by using a logical-or on the values. The value zero
- * represents all possible severities.
- *
- * Source and category are an array. An empty array reprseents all possible sources
- * and categories.
- *
- * The ezclogFilter class is mainly used by the {@link ezcLog::attach()} and {@link ezcLog::detach()}
- * methods.
- *
- * @package EventLog
- * @version //autogentag//
- */
-class ezcLogFilter
-{
- /**
- * The severities that are accepted by the ezcLogFilter.
- *
- * The default value zero specifies that all severities are accepted.
- *
- * @var int
- */
- public $severity = 0;
-
-
- /**
- * The source of the log message.
- *
- * The default empty array specifies that all sources are accepted by this filter.
- *
- * @var array(string)
- */
- public $source = array();
-
- /**
- * The category of the log message.
- *
- * The default empty array specifies that all categories are accepted by this filter.
- *
- * @var array(string)
- */
- public $category = array();
-
-
- /**
- * Empty constructor
- */
- public function __construct()
- {
- }
-}
-
-
-
-?>
diff --git a/framework/Log/EventLog/writers/writer_database.php b/framework/Log/EventLog/writers/writer_database.php
deleted file mode 100644
index 6908a770..00000000
--- a/framework/Log/EventLog/writers/writer_database.php
+++ /dev/null
@@ -1,216 +0,0 @@
-<?php
-/**
- * File containing the ezcLogWriterDatabase class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-
-/**
- * Writes log messages to the database.
- *
- * @package EventLog
- * @version //autogentag//
- */
-class ezcLogWriterDatabase implements ezcLogWriter
-{
- private $db = null;
-
- private $properties = array();
- private $defaultColumns = array();
- private $additionalColumns = array();
-
- private $map;
- private $defaultTable = false;
-
- /**
- * Construct a new database log-writer.
- *
- * You can set the default table to write to with the $defaultTable parameter.
- * If $databaseInstance is given, that instance will be used for writing. If it
- * is ommitted the default database instance will be retrieved.
- *
- * This constructor is a tie-in.
- *
- * @param string $defaultTable
- * @param ezcDbHandler $databaseInstance
- *
- */
- public function __construct( ezcDbHandler $databaseInstance, $defaultTable = false )
- {
- $this->db = $databaseInstance;
-
- $this->map = new ezcLogMap();
- $this->defaultTable = $defaultTable;
-
- $this->message = "message";
- $this->datetime = "time";
- $this->severity = "severity";
- $this->source = "source";
- $this->category = "category";
- }
-
- /**
- * Sets the property $name to $value.
- *
- * @throws ezcBasePropertyNotFoundException if the property does not exist.
- * @param string $name
- * @param mixed $value
- * @return void
- */
- public function __set( $name, $value )
- {
- switch ( $name )
- {
- case 'table': $this->properties['table'] = $value; break;
- case 'message':
- case 'datetime':
- case 'severity':
- case 'source':
- case 'category': $this->defaultColumns[ $name ] = $value; break;
- default: $this->additionalColumns[ $name ] = $value; break;
- }
- }
-
- /**
- * Returns the property $name.
- *
- * @throws ezcBasePropertyNotFoundException if the property does not exist.
- * @param string $name
- * @return mixed
- */
- public function __get( $name )
- {
- switch ( $name )
- {
- case 'table': return $this->properties['table']; break;
- case 'message':
- case 'datetime':
- case 'severity':
- case 'source':
- case 'category': return $this->defaultColumns[ $name ]; break;
-
- default: return $this->additionalColumns[ $name ]; break;
- }
- }
-
- /**
- * Writes the message $message to the log.
- *
- * The writer can use the severity, source, and category to filter the
- * incoming messages and determine the location where the messages should
- * be written.
- *
- * $optional may contain extra information that can be added to the log. For example:
- * line numbers, file names, usernames, etc.
- *
- * @throws ezcLogWriterException when the log writer was unable to write
- * the log message.
- * @param string $message
- * @param int $severity
- * ezcLog:: DEBUG, SUCCES_AUDIT, FAILED_AUDIT, INFO, NOTICE, WARNING, ERROR or FATAL.
- *
- * $param string $source
- * @param string $category
- * @param array(string=>string) $optional
- * @return void
- */
- public function writeLogMessage( $message, $severity, $source, $category, $optional = array() )
- {
- $severityName = ezcLog::translateSeverityName( $severity );
-
- $colStr = "";
- $valStr = "";
-
- if ( is_array( $optional ) )
- {
- foreach ( $optional as $key => $val )
- {
- $colStr .= ", " . ( isset( $this->additionalColumns[$key] ) ? $this->additionalColumns[$key] : $key );
- $valStr .= ", " . $this->db->quote( $val );
- }
- }
-
- $tables = $this->map->get( $severity, $source, $category );
-
- $query = $this->db->createSelectQuery();
- if ( count( $tables ) > 0)
- {
- foreach ( $tables as $t )
- {
- try
- {
- $this->db->exec( "INSERT INTO `{$t}` ( {$this->message}, {$this->severity}, {$this->source}, {$this->category}, {$this->datetime} $colStr ) ".
- "VALUES( ".$this->db->quote( $message ).", ".$this->db->quote( $severityName ).", ".$this->db->quote( $source ).", ".
- $this->db->quote( $category ).", ".$query->expr->now()." $valStr )" );
- }
- catch ( PDOException $e )
- {
- throw new ezcLogWriterException( "SQL query failed in ezcLogWriterDatabase.\n". $e->getMessage() );
- }
- }
- }
- else
- {
- if ( $this->defaultTable !== false )
- {
- try
- {
- $this->db->exec( "INSERT INTO `{$this->defaultTable}` ( {$this->message}, {$this->severity}, {$this->source}, {$this->category}, {$this->datetime} $colStr ) ".
- "VALUES( ".$this->db->quote( $message ).", ".$this->db->quote( $severityName ).", ".$this->db->quote( $source ).", ".
- $this->db->quote( $category ).", ".$query->expr->now()." $valStr )" );
- }
- catch ( PDOException $e )
- {
- throw new ezcLogWriterException( "SQL query failed in ezcLogWriterDatabase.\n". $e->getMessage() );
- }
- }
- }
- }
-
- /**
- * Returns an array that describes the coupling between the logMessage
- * information and the columns in the database.
- *
- * @return array(string=>string)
- */
- public function getColumnTranslations()
- {
- return array_merge( $this->defaultColumns, $this->additionalColumns );
- }
-
-
- /**
- * Maps the table $tableName to the messages specified by the {@link ezcLogFilter} $logFilter.
- *
- * Log messages that matches with the filter are written to the table $tableName.
- * This method works the same as {@link ezclog::map()}.
- *
- * @param ezcLogFilter $logFilter
- * @param string $tableName
- * @return void
- */
- public function map( ezcLogFilter $logFilter, $tableName )
- {
- $this->map->map( $logFilter->severity, $logFilter->source, $logFilter->category, $tableName );
- }
-
- /**
- * Unmaps the table $tableName from the messages specified by the {@link ezcLogFilter} $logFilter.
- *
- * Log messages that matches with the filter are no longer written to the table $tableName.
- * This method works the same as {@link ezclog::unmap()}.
- *
- * @param ezcLogFilter $logFilter
- * @param string $fileName
- * @return void
- */
- public function unmap( ezcLogFilter $logFilter, $tableName )
- {
- $this->map->unmap( $logFilter->severity, $logFilter->source, $logFilter->category, $tableName );
- }
-}
-
-?>
diff --git a/framework/Log/EventLog/writers/writer_file.php b/framework/Log/EventLog/writers/writer_file.php
deleted file mode 100644
index 46ecf13e..00000000
--- a/framework/Log/EventLog/writers/writer_file.php
+++ /dev/null
@@ -1,273 +0,0 @@
-<?php
-/**
- * File containing the ezcLogWriterFile class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-
-/**
- * The ezcLogWriterFile class provides functionality to write log files to the file
- * system.
- *
- * The main purpose is to keep track of the various log files and support
- * log rotation. The file format of the log should be implemented in a subclass.
- *
- * The following example implements a new log writer that writes the output in ({@link print_r()} format)
- * to a file:
- * <code>
- * class MyLogWriter extends ezcLogWriterFile
- * {
- * // Call parent constructor. (In this case, it possible to omit the constructor.)
- * public function __construct($dir, $file = null, $maxSize = 204800, $maxFiles = 3 )
- * {
- * parent::__construct($dir, $file, $maxSize, $maxFiles);
- * }
- *
- * // Implement the ezcLogWriter interface:
- * public function writeLogMessage( $message, $type, $source, $category, $extraInfo = array() )
- * {
- * // Create a message
- * $res = print_r( array( "message" => $message, "type" => $type, "source" => $source, "category" => $category ), true );
- *
- * // And call the parent class
- * $this->write( $type, $source, $category, $res );
- * }
- *}
- * </code>
- *
- * @package EventLog
- * @version //autogentag//
- */
-abstract class ezcLogWriterFile implements ezcLogWriter
-{
- /**
- * Contains all the open files. The first file in the
- * array is always the default file.
- *
- * @var array(resource)
- */
- protected $openFiles = array();
-
-
- /**
- * Keeps track of which group of messages should be stored
- * in what file.
- *
- * @var ezcLogMap
- */
- protected $fileMap;
-
- /**
- * Directory where the log files should be placed.
- *
- * @var string
- */
- protected $logDirectory;
-
- /**
- * Maximum file size before rotation.
- *
- * @var int
- */
- protected $maxSize;
-
- /**
- * Maximum log rotation files with the same name.
- *
- * When rotating and the max limit is reached, the oldest log
- * is discarded.
- *
- * @var int
- */
- protected $maxFiles;
-
-
- /**
- * Constructs an ezcLogFileWriter.
- *
- * The log files will be placed in the directory $logDirectory.
- *
- * If the file $defaultFile is not null, log messages that are not {@link map() mapped}
- * to any file are written to this $defaultFile. If $defaultFile is null, then
- * log messages are discarded.
-
- *
- * Set $maxLogRotationSize to specify the maximum size of a logfile. When the
- * maximum size is reached, the log will be rotated. $maxLogFiles sets the maximum
- * number of rotated log files. The oldest rotated log will be removed when the
- * maxLogFiles exceeds.
- *
- * @param string $logDirectory
- * @param string $defaultFile
- * @param string $maxLogRotationSize
- * @param string $maxLogFiles
- */
- public function __construct( $logDirectory, $defaultFile = null, $maxLogRotationSize = 204800, $maxLogFiles = 3 )
- {
- $this->maxSize = $maxLogRotationSize;
- $this->maxFiles = $maxLogFiles;
- $this->logDirectory = $logDirectory;
- $this->defaultFile = $defaultFile;
-
- if ( !is_null( $defaultFile ) )
- {
- $this->openFile( $defaultFile );
- }
-
- $this->fileMap = new ezcLogMap();
- }
-
- /**
- * Destructs the object and closes all open file handles.
- */
- public function __destruct()
- {
- foreach ( $this->openFiles as $fh )
- {
- fclose( $fh );
- }
- }
-
-
- /**
- * This method writes the $string to a file.
- *
- * The file to which the string will be written depends on the $eventType, $eventSource, and
- * $eventCategory.
- *
- * @throws ezcLogWriterException if it was not possible to write to the log file.
- * @param int $eventType
- * @param string $eventSource
- * @param string $eventCategory
- * @param string $string
- * @return void
- */
- protected function write( $eventType, $eventSource, $eventCategory, $string )
- {
- $fileHandles = $this->fileMap->get( $eventType, $eventSource, $eventCategory );
-
- if ( count( $fileHandles ) > 0 )
- {
- foreach ( $fileHandles as $fh )
- {
- if ( fwrite( $fh, $string ) === false)
- {
- throw ezcLogWriterException( "Cannot write to the attached log file.", ezcLogWriterException::FILE_NOT_WRITABLE );
- }
- }
- }
- else
- {
- if ( !is_null( $this->defaultFile ) )
- {
- if ( fwrite( $this->openFiles[$this->defaultFile], $string ) === false )
- {
- throw ezcLogWriterException( "Cannot write to the default log file.", ezcLogWriterException::FILE_NOT_WRITABLE );
- }
- }
- }
- }
-
- /**
- * Returns the filehandle of the $fileName.
- *
- * If the maximum file size is exceeded, the file will be rotated before opening.
- *
- * @return resource
- */
- protected function openFile( $fileName )
- {
- if ( isset( $this->openFiles[$fileName] ) )
- {
- return $this->openFiles[$fileName];
- }
-
- clearstatcache();
- if ( file_exists( $this->logDirectory . "/". $fileName ) &&
- ( filesize( $this->logDirectory . "/". $fileName ) >= $this->maxSize ) )
- {
- $this->rotateLog( $fileName );
- }
-
- $fh = @fopen( $this->logDirectory ."/". $fileName, "w" );
- if ( $fh === false )
- {
- // throw exception.
- throw new ezcLogFileException( "Cannot open the file <{$fileName}> for writing", ezcLogFileException::FILE_NOT_FOUND );
- }
-
- $this->openFiles[$fileName] = $fh;
- return $fh;
- }
-
- /**
- * Rotates a log and returns true upon success.
- *
- * @return bool
- */
- protected function rotateLog( $fileName )
- {
- $file = $this->logDirectory . "/" . $fileName;
-
- for ( $i = $this->maxFiles; $i > 0; --$i )
- {
- $logRotateName = $file. '.' . $i;
- if ( file_exists( $logRotateName ) )
- {
- if ( $i == $this->maxFiles )
- {
- unlink( $logRotateName );
- }
- else
- {
- $newLogRotateName = $file . '.' . ( $i + 1 );
- rename( $logRotateName, $newLogRotateName );
- }
- }
- }
- if ( file_exists( $file ) )
- {
- $newLogRotateName = $file . '.' . 1;
- rename( $file, $newLogRotateName );
- return true;
- }
- return false;
- }
-
-
- /**
- * Maps the filename $fileName to the messages specified by the {@link ezcLogFilter} $logFilter.
- *
- * Log messages that matches with the filter are written to the file $fileName.
- * This method works the same as {@link ezclog::map()}.
- *
- * @param ezcLogFilter $logFilter
- * @param string $fileName
- * @return void
- */
- public function map( ezcLogFilter $logFilter, $fileName )
- {
- $fh = $this->openFile( $fileName );
- $this->fileMap->map( $logFilter->severity, $logFilter->source, $logFilter->category, $fh );
- }
-
- /**
- * Unmaps the filename $fileName from the messages specified by the {@link ezcLogFilter} $logFilter.
- *
- * Log messages that matches with the filter are no longer written to the file $fileName.
- * This method works the same as {@link ezclog::unmap()}.
- *
- * @param ezcLogFilter $logFilter
- * @param string $fileName
- * @return void
- */
- public function unmap( $logFilter, $fileName )
- {
- $this->fileMap->unmap( $logFilter->severity, $logFilter->source, $logFilter->category, $this->openFiles[ $fileName ] );
- }
-
-}
-?>
diff --git a/framework/Log/EventLog/writers/writer_unix_file.php b/framework/Log/EventLog/writers/writer_unix_file.php
deleted file mode 100644
index a2045217..00000000
--- a/framework/Log/EventLog/writers/writer_unix_file.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * File containing the ezcLogWriterUnix class.
- *
- * @package EventLog
- * @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-
-/**
- * Writes the log messages to a file in a format that is frequently used on the Unix operating system.
- *
- * @package EventLog
- * @version //autogentag//
- */
-class ezcLogWriterUnixFile extends ezcLogWriterFile
-{
- /**
- * Write the logEntries to a file.
- *
- * Each line in the log file represents a log message. The log
- * messages have the following style:
- * <pre>
- * MMM dd HH:mm:ss [Severity] [Source] [Category] Message (ExtraInfo)
- * </pre>
- *
- * With:
- * - MMM: The 3 letter abbreviation of the month.
- * - dd: The day of the month.
- * - HH: The hour.
- * - mm: The minutes.
- * - ss: The seconds.
- *
- * Example:
- * <pre>
- * Jan 24 15:32:56 [Debug] [Paynet] [Shop] Connecting to the paynet server (file: paynet_server.php, line: 224).
- * Jan 24 15:33:01 [Debug] [Paynet] [Shop] Connected with the server (file: paynet_server.php, line: 710).
- * </pre>
- *
- * This method will be called by the {@link ezcLog} class. The $eventSource and $eventCategory are either given
- * in the {@link ezcLog::log()} method or are the defaults from the {@link ezcLog} class.
- *
- * @param string $message
- * @param int $eventType
- * @param string $eventType
- * @param string $eventCategory
- * @param array(string=>string) $extraInfo
- */
- public function writeLogMessage( $message, $eventType, $eventSource, $eventCategory, $extraInfo = array() )
- {
- $extra = $this->implodeWithKey( ", ", ": ", $extraInfo );
-
- if ( $eventCategory == false )
- {
- $eventCategory = "";
- }
- $logMsg = @date( "M d H:i:s" ) .
- " [".ezcLog::translateSeverityName( $eventType ) .
- "] [$eventSource] [$eventCategory] $message ($extra)\n";
-
- $this->write( $eventType, $eventSource, $eventCategory, $logMsg );
- }
-
- /**
- * Returns a string from the hash $data.
- *
- * The string $splitEntry specifies the string that will be inserted between the pairs.
- * The string $splitKeyVal specifies the string that will be inserted in each pair.
- *
- * Example:
- * <code>
- * $this->implodeWithKey( ", ", ": ", array( "Car" => "red", "Curtains" => "blue" );
- * </code>
- *
- * Will create the following string:
- * <pre>
- * Car: red, Curtains: blue
- * </pre>
- *
- * @param string $splitEntry
- * @param string $splitKeyVal
- * @param array(mixed=>mixed) $data
- * @return string
- */
- protected function implodeWithKey( $splitEntry, $splitKeyVal, $data)
- {
- $total = "";
- if ( is_array( $data ) )
- {
- foreach ( $data as $key => $val )
- {
- $total .= $splitEntry . $key . $splitKeyVal . $val;
- }
- }
-
- return substr( $total, strlen( $splitEntry ) );
- }
-}
-?>
diff --git a/framework/Log/ILog.php b/framework/Log/ILog.php
deleted file mode 100644
index 90239e97..00000000
--- a/framework/Log/ILog.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-interface ILog
-{
- public function info($msg, $source='Prado', $category='core');
- public function debug($msg, $source='Prado', $category='core');
- public function notice($msg, $source='Prado', $category='core');
- public function warn($msg, $source='Prado', $category='core');
- public function error($msg, $source='Prado', $category='core');
- public function fatal($msg, $source='Prado', $category='core');
-}
-
-require_once(PRADO_DIR.'/Log/EventLog/log.php');
-require_once(PRADO_DIR.'/Log/EventLog/exceptions/writer_exception.php');
-require_once(PRADO_DIR.'/Log/EventLog/exceptions/file_exception.php');
-
-/**
- * ${classname}
- *
- * ${description}
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package ${package}
- */
-class TInternalLogger
-{
- public $entries = array();
-
- public function info($msg, $source='Prado', $category='core')
- {
- $this->log($msg, ezcLog::INFO,
- array('source'=>$source, 'category'=>$category));
- }
- public function debug($msg, $source='Prado', $category='core')
- {
- $this->log($msg, ezcLog::DEBUG,
- array('source'=>$source, 'category'=>$category));
- }
- public function notice($msg, $source='Prado', $category='core')
- {
- $this->log($msg, ezcLog::NOTICE,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function warn($msg, $source='Prado', $category='core')
- {
- $this->log($msg, ezcLog::WARNING,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function error($msg, $source='Prado', $category='core')
- {
- $this->log($msg, ezcLog::ERROR,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function fatal($msg, $source='Prado', $category='core')
- {
- $this->log($msg, ezcLog::FATAL,
- array('source'=>$source, 'category'=>$category));
- }
-
- protected function log($msg, $type, $info)
- {
- if($info['category']=='core')
- {
- $trace = debug_backtrace();
- $info['category'] = $trace[3]['class'];
- }
- $info['time'] = microtime(true);
- $this->entries[] = array($msg, $type, $info);
- }
-}
-
-?> \ No newline at end of file
diff --git a/framework/Log/TEventLog.php b/framework/Log/TEventLog.php
deleted file mode 100644
index 8fb56618..00000000
--- a/framework/Log/TEventLog.php
+++ /dev/null
@@ -1,78 +0,0 @@
-<?php
-
-Prado::using('System.Log.ILog');
-Prado::using('System.Log.TLogManager');
-
-/**
- * ${classname}
- *
- * ${description}
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package ${package}
- */
-class TEventLog extends TLogManager implements ILog
-{
- public function init($config)
- {
- parent::init($config);
- $this->collectInternalLog();
- }
-
- public function __destruct()
- {
- $this->collectInternalLog();
- }
-
- protected function collectInternalLog()
- {
- foreach(Prado::coreLog()->entries as $entry)
- $this->log($entry[0], $entry[1], $entry[2]);
- Prado::coreLog()->entries = array();
- }
-
- public function info($msg, $source='Prado', $category='main')
- {
- $this->log($msg, ezcLog::INFO,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function debug($msg, $source='Prado', $category='main')
- {
- $this->log($msg, ezcLog::DEBUG,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function notice($msg, $source='Prado', $category='main')
- {
- $this->log($msg, ezcLog::NOTICE,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function warn($msg, $source='Prado', $category='main')
- {
- $this->log($msg, ezcLog::WARNING,
- array('source'=>$source, 'category'=>$category));
- }
-
- public function error($msg, $source='Prado', $category='main')
- {
- $this->log($msg, ezcLog::NOTICE,
- array('source'=>$source, 'category'=>$category));
-
- }
-
- public function fatal($msg, $source='Prado', $category='main')
- {
- $this->log($msg, ezcLog::NOTICE,
- array('source'=>$source, 'category'=>$category));
- }
-
- protected function log($msg, $code, $info)
- {
- ezcLog::getInstance()->log($msg, $code, $info);
- }
-}
-
-?> \ No newline at end of file
diff --git a/framework/Log/TLogManager.php b/framework/Log/TLogManager.php
deleted file mode 100644
index dd926bc7..00000000
--- a/framework/Log/TLogManager.php
+++ /dev/null
@@ -1,145 +0,0 @@
-<?php
-
-abstract class TLogManager extends TModule
-{
- protected $defaultSeverity = 'INFO | DEBUG | NOTICE | WARNING | ERROR | FATAL';
-
- protected $config;
-
- public function init($xml)
- {
- if(!is_null($this->config))
- $this->initLogger($this->loadConfigFromFile($this->config));
- else
- $this->initLogger($xml);
- }
-
- protected function loadConfigFromFile($file)
- {
- $xml = new TXmlDocument();
- $xml->loadFromFile($file);
- return $xml->getElementByTagName('loggers');
- }
-
- protected function initLogger($xml)
- {
- TEzcLoggerLoader::using('ezcLog');
- TEzcLoggerLoader::using('ezcLogMap');
- TEzcLoggerLoader::using('ezcLogContext');
- TEzcLoggerLoader::using('ezcLogFilter');
-
- $log = ezcLog::getInstance();
- foreach($xml->getElementsByTagName('logger') as $logger)
- {
- $logWriter = $this->getLogWriter($logger);
- $filters = $logger->getElementsByTagName('filter');
- foreach($filters as $filter)
- {
- $logFilter = new ezcLogFilter();
- $Severity = $filter->getAttribute('severity');
- $logFilter->severity = $this->getFilterSeverity($Severity);
- $map = $filter->getAttribute('disabled') ? 'unmap' : 'map';
- $log->$map($logFilter, $logWriter);
- }
-
- if($filters->getCount() < 1)
- {
- $logFilter = new ezcLogFilter();
- $logFilter->severity = $this->getFilterSeverity();
- $log->map($logFilter, $logWriter);
- }
- }
- }
-
- protected function getLogWriter($xml)
- {
- switch($xml->getAttribute('destination'))
- {
- case 'file' :
- return TEzcLoggerUnixFileWriterFactory::create($xml);
- default :
- throw new TException('invalid_log_destination');
- }
- }
-
- protected function getFilterSeverity($string='')
- {
- if(empty($string))
- $string = $this->defaultSeverity;
- $serverities = explode("|", $string);
- $mask = 0;
- foreach($serverities as $Severity)
- $mask = $mask | $this->getSeverity($Severity);
- return $mask;
- }
-
- private function getSeverity($string)
- {
- switch(strtolower(trim($string)))
- {
- case 'debug': return ezcLog::DEBUG;
- case 'success audit' : return ezcLog::SUCCESS_AUDIT;
- case 'failed audit' : return ezcLog::FAILED_AUDIT;
- case 'info' : return ezcLog::INFO;
- case 'notice' : return ezcLog::NOTICE;
- case 'warn' : return ezcLog::WARNING;
- case 'error' : return ezcLog::ERROR;
- case 'fatal' : return ezcLog::FATAL;
- }
- return 0;
- }
-}
-
-
-/**
- * ${classname}
- *
- * ${description}
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package ${package}
- */
-class TEzcLoggerUnixFileWriterFactory
-{
- public static function create($xml)
- {
- TEzcLoggerLoader::using('ezcLogWriter');
- TEzcLoggerLoader::using('ezcLogWriterFile');
- TEzcLoggerLoader::using('ezcLogWriterUnixFile');
-
- $path = $xml->getAttribute('directory');
- $dir = Prado::getPathOfNamespace($path);
- if(!is_dir($dir))
- throw new TException("missing_logging_directory $dir");
- if(!is_writable($dir))
- throw new TException("unable_to_writer_to $dir");
- $file = $xml->getAttribute('filename');
- if(empty($file)) $file = 'prado.log';
- return new ezcLogWriterUnixFile($dir, $file);
- }
-}
-
-/**
- * ${classname}
- *
- * ${description}
- *
- * @author Wei Zhuo<weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.66 $ $Date: ${DATE} ${TIME} $
- * @package ${package}
- */
-class TEzcLoggerLoader
-{
- public static function using($class)
- {
- if(class_exists($class, false)) return;
- static $classes;
- $base = dirname(__FILE__);
- if(is_null($classes))
- $classes = include($base.'/EventLog/log_autoload.php');
- require_once($base.'/'.$classes[$class]);
- }
-}
-
-?> \ No newline at end of file
diff --git a/framework/Log/TLogRouter.php b/framework/Log/TLogRouter.php
index 5a3a59dc..98bded1c 100644
--- a/framework/Log/TLogRouter.php
+++ b/framework/Log/TLogRouter.php
@@ -1,9 +1,5 @@
<?php
-/*
-<module id="log" class="System.Log.LogRouter">
- <route class="TFileLogRoute" LogPath="xxx.yyy.zzz" MaxLogFiles="5" MaxFileSize="1024" Categories="System.Web" Levels="Error" />
-</module>
-*/
+
class TLogRouter extends TModule
{
const CONFIG_FILE_EXT='.xml';
@@ -23,7 +19,7 @@ class TLogRouter extends TModule
else
throw new TConfigurationException('logrouter_configfile_invalid',$this->_configFile);
}
- $this->loadConfig($xml);
+ $this->loadConfig($config);
$this->getApplication()->attachEventHandler('EndRequest',array($this,'collectLogs'));
}
@@ -65,7 +61,17 @@ class TLogRouter extends TModule
abstract class TLogRoute extends TComponent
{
- private static $_levelMap=array(
+ private static $_levelNames=array(
+ TLogger::ERROR=>'Error',
+ TLogger::DEBUG=>'Debug',
+ TLogger::INFO=>'Info',
+ TLogger::NOTICE=>'Notice',
+ TLogger::WARNING=>'Warning',
+ TLogger::ERROR=>'Error',
+ TLogger::ALERT=>'Alert',
+ TLogger::FATAL=>'Fatal'
+ );
+ private static $_levelValues=array(
'error'=>TLogger::ERROR,
'debug'=>TLogger::DEBUG,
'info'=>TLogger::INFO,
@@ -94,10 +100,9 @@ abstract class TLogRoute extends TComponent
foreach(explode(',',$levels) as $level)
{
$level=trim($level);
- if(isset(self::$_levelMap[$level]))
- $this->_levels|=self::$_levelMap[$level];
+ if(isset(self::$_levelValues[$level]))
+ $this->_levels|=self::$_levelValues[$level];
}
- $this->_levels=$levels;
}
public function getCategories()
@@ -115,36 +120,36 @@ abstract class TLogRoute extends TComponent
}
}
+ protected function getLevelName($level)
+ {
+ return isset(self::$_levelNames[$level])?self::$_levelNames[$level]:'Unknown';
+ }
+
+ protected function formatLogMessage($message,$level,$category,$time)
+ {
+ return @date('M d H:i:s',$time).' ['.$this->getLevelName($level).'] ['.$category.'] '.$message."\n";
+ }
+
public function collectLogs()
{
$logs=Prado::getLogger()->getLogs($this->getLevels(),$this->getCategories());
$this->processLogs($logs);
}
- protected function processLogs($logs);
+ abstract protected function processLogs($logs);
}
class TFileLogRoute extends TLogRoute
{
private $_maxFileSize=1024; // in KB
- private $_maxLogFiles=5;
+ private $_maxLogFiles=2;
private $_logPath=null;
- private $_fileName='prado.log';
- private $_levelMap=array(
- TLogger::ERROR=>'Error',
- TLogger::DEBUG=>'Debug',
- TLogger::INFO=>'Info',
- TLogger::NOTICE=>'Notice',
- TLogger::WARNING=>'Warning',
- TLogger::ERROR=>'Error',
- TLogger::ALERT=>'Alert',
- TLogger::FATAL=>'Fatal'
- );
+ private $_logFile='prado.log';
- public function init()
+ public function init($config)
{
if($this->_logPath===null)
- throw new TConfigurationException('filelogroute_logfile_required');
+ $this->_logPath=$this->getApplication()->getRuntimePath();
}
public function getLogPath()
@@ -158,14 +163,14 @@ class TFileLogRoute extends TLogRoute
throw new TConfigurationException('filelogroute_logpath_invalid',$value);
}
- public function getFileName()
+ public function getLogFile()
{
- return $this->_fileName;
+ return $this->_logFile;
}
- public function setFileName($value)
+ public function setLogFile($value)
{
- $this->_fileName=$value;
+ $this->_logFile=$value;
}
public function getMaxFileSize()
@@ -194,30 +199,16 @@ class TFileLogRoute extends TLogRoute
protected function processLogs($logs)
{
- $str='';
- foreach($logs as $log)
- $str.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
- $logFile=$this->_logPath.'/'.$this->_fileName;
+ $logFile=$this->_logPath.'/'.$this->_logFile;
if(@filesize($logFile)>$this->_maxFileSize*1024)
$this->rotateFiles();
- $fw=fopen($logFile,'a');
- fwrite($fw,$str);
- fclose($fw);
- }
-
- protected function formatLogMessage($message,$level,$category,$time)
- {
- return @date('M d H:i:s',$time).' ['.$this->getLevelName($level).'] ['.$category.'] '.$message."\n";
- }
-
- protected function getLevelName($level)
- {
- return isset(self::$_levelMap[$level])?self::$_levelMap[$level]:'Unknown';
+ foreach($logs as $log)
+ error_log($this->formatLogMessage($log[0],$log[1],$log[2],$log[3]),3,$logFile);
}
- private function rotateFiles()
+ protected function rotateFiles()
{
- $file=$this->_logPath.'/'.$this->_fileName;
+ $file=$this->_logPath.'/'.$this->_logFile;
for($i=$this->_maxLogFiles;$i>0;--$i)
{
$rotateFile=$file.'.'.$i;
@@ -234,5 +225,62 @@ class TFileLogRoute extends TLogRoute
}
}
+class TEmailLogRoute extends TLogRoute
+{
+ const EMAIL_PATTERN='/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/';
+ const DEFAULT_SUBJECT='Prado Application Log';
+ private $_emails=array();
+ private $_subject='';
+ private $_from='';
+
+ protected function processLogs($logs)
+ {
+ $message='';
+ $headers=($this->_from==='') ? '' : "From:{$this->_from}\r\n";
+ $subject=$this->_subject===''?self::DEFAULT_SUBJECT:$this->_subject;
+ foreach($logs as $log)
+ $message.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
+ $message=wordwrap($message,70);
+ foreach($this->_emails as $email)
+ mail($email,$subject,$message,$headers);
+
+ }
+
+ public function getEmails()
+ {
+ return $this->_emails;
+ }
+
+ public function setEmails($emails)
+ {
+ $this->_emails=array();
+ foreach(explode(',',$emails) as $email)
+ {
+ $email=trim($email);
+ if(preg_match(self::EMAIL_PATTERN,$email))
+ $this->_emails[]=$email;
+ }
+ }
+
+ public function getSubject()
+ {
+ return $this->_subject;
+ }
+
+ public function setSubject($value)
+ {
+ $this->_subject=$value;
+ }
+
+ public function getFrom()
+ {
+ return $this->_from;
+ }
+
+ public function setFrom($value)
+ {
+ $this->_from=$value;
+ }
+}
?> \ No newline at end of file
diff --git a/framework/Log/TLogger.php b/framework/Log/TLogger.php
new file mode 100644
index 00000000..f9b9b47a
--- /dev/null
+++ b/framework/Log/TLogger.php
@@ -0,0 +1,57 @@
+<?php
+
+class TLogger extends TComponent
+{
+ const DEBUG=0x01;
+ const INFO=0x02;
+ const NOTICE=0x04;
+ const WARNING=0x08;
+ const ERROR=0x10;
+ const ALERT=0x20;
+ const FATAL=0x40;
+ private $_logs=array();
+ private $_levels;
+ private $_categories;
+
+ public function log($message,$level,$category='Uncategorized')
+ {
+ $this->_logs[]=array($message,$level,$category,time());
+ }
+
+ public function getLogs($levels=null,$categories=null)
+ {
+ $this->_levels=$levels;
+ $this->_categories=$categories;
+ if(empty($levels) && empty($categories))
+ return $this->_logs;
+ else if(empty($levels))
+ return array_values(array_filter(array_filter($this->_logs,array($this,'filterByCategories'))));
+ else if(empty($categories))
+ return array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
+ else
+ {
+ $ret=array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
+ return array_values(array_filter(array_filter($ret,array($this,'filterByCategories'))));
+ }
+ }
+
+ private function filterByCategories($value)
+ {
+ foreach($this->_categories as $category)
+ {
+ if(strpos($value[2],$category)===0)
+ return $value;
+ }
+ return false;
+ }
+
+ private function filterByLevels($value)
+ {
+ if($value[1] & $this->_levels)
+ return $value;
+ else
+ return false;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 4d773d7b..d8214f09 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -308,7 +308,7 @@ class TApplication extends TComponent
if($this->_mode===self::STATE_OFF)
throw new THttpException(503,'application_service_unavailable');
$method='on'.self::$_steps[$this->_step];
- Prado::coreLog("Executing $method");
+ Prado::trace("Executing $method",'System.TApplication');
$this->$method($this);
if($this->_requestCompleted && $this->_step<$n-1)
$this->_step=$n-1;
@@ -699,7 +699,8 @@ class TApplication extends TComponent
*/
protected function initApplication()
{
- Prado::coreLog("Initializing application");
+ Prado::trace('Initializing application','System.TApplication');
+
Prado::setPathOfAlias('Application',$this->_basePath);
if($this->_configFile===null)
@@ -758,7 +759,8 @@ class TApplication extends TComponent
$this->_modules=array();
foreach($config->getModules() as $id=>$moduleConfig)
{
- Prado::coreLog("Creating module $id");
+ Prado::trace("Loading module $id ({$moduleConfig[0]})",'System.TApplication');
+
$module=Prado::createComponent($moduleConfig[0]);
$this->_modules[$id]=$module;
foreach($moduleConfig[1] as $name=>$value)
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 8f12c650..65549159 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -146,7 +146,7 @@ class TPageService extends TService
*/
public function init($config)
{
- Prado::coreLog("Initializing TPageService");
+ Prado::trace("Initializing TPageService",'System.Web.Services.TPageService');
$application=$this->getApplication();
$application->setPageService($this);
@@ -251,7 +251,7 @@ class TPageService extends TService
// load modules specified in page directory config
foreach($pageConfig->getModules() as $id=>$moduleConfig)
{
- Prado::coreLog("Loading module $id");
+ Prado::trace("Loading module $id ({$moduleConfig[0]})",'System.Web.Services.TPageService');
$module=Prado::createComponent($moduleConfig[0]);
$application->setModule($id,$module);
foreach($moduleConfig[1] as $name=>$value)
@@ -427,7 +427,7 @@ class TPageService extends TService
*/
public function run()
{
- Prado::coreLog("Running page service");
+ Prado::trace("Running page service",'System.Web.Services.TPageService');
$page=null;
$path=$this->_basePath.'/'.strtr($this->_pagePath,'.','/');
if(is_file($path.self::PAGE_FILE_EXT))
@@ -614,7 +614,7 @@ class TPageConfiguration extends TComponent
*/
private function loadFromFile($fname,$page)
{
- Prado::coreLog("Loading $page with file $fname");
+ Prado::trace("Loading $page with file $fname",'System.Web.Services.TPageService');
if(empty($fname) || !is_file($fname))
return;
$dom=new TXmlDocument;
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index bb2eb7b4..9e8b7a04 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -363,6 +363,7 @@ class THttpRequest extends TModule
*/
protected function resolveRequest()
{
+ Prado::trace("Resolving request from ".$_SERVER['REMOTE_ADDR'],'System.Web.THttpRequest');
$this->_requestResolved=true;
foreach($this->_services as $id)
{
@@ -373,7 +374,6 @@ class THttpRequest extends TModule
break;
}
}
- Prado::coreLog("Resolving request {$this->_serviceID}={$this->_serviceParam}");
}
/**
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index cf44d19d..ea41ab16 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -32,9 +32,9 @@
* where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl}
* and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse.
*
- * When sending headers the Charset set in {@link TGlobalization::getCharset()}
+ * When sending headers the Charset set in {@link TGlobalization::getCharset()}
* is use when Charset is null or empty in THttpResponse.
- *
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web
@@ -145,7 +145,7 @@ class THttpResponse extends TModule implements ITextWriter
{
return $this->_contentType;
}
-
+
/**
* @return string output charset.
*/
@@ -278,7 +278,7 @@ class THttpResponse extends TModule implements ITextWriter
$this->appendHeader($header);
if($this->_bufferOutput)
ob_flush();
- Prado::coreLog("Flushing output $header");
+ Prado::trace("Flushing output $header",'System.Web.THttpResponse');
}
/**
@@ -286,7 +286,7 @@ class THttpResponse extends TModule implements ITextWriter
*/
protected function getContentTypeHeader()
{
- $app = $this->getApplication()->getGlobalization();
+ $app = $this->getApplication()->getGlobalization();
$charset = $this->getCharset();
if(empty($charset))
$charset = !is_null($app) ? $app->getCharset() : 'UTF-8';
@@ -301,7 +301,7 @@ class THttpResponse extends TModule implements ITextWriter
{
if($this->_bufferOutput)
ob_clean();
- Prado::coreLog("Clearing output");
+ Prado::trace("Clearing output",'System.Web.THttpResponse');
}
/**
diff --git a/framework/Web/UI/TAssetManager.php b/framework/Web/UI/TAssetManager.php
index 1ff0f47a..94b1bc55 100644
--- a/framework/Web/UI/TAssetManager.php
+++ b/framework/Web/UI/TAssetManager.php
@@ -141,7 +141,6 @@ class TAssetManager extends TModule
*/
public function publishFilePath($path,$checkTimestamp=false)
{
- Prado::coreLog("Publishing file $path");
if(isset($this->_published[$path]))
return $this->_published[$path];
else if(($fullpath=realpath($path))===false)
@@ -155,7 +154,10 @@ class TAssetManager extends TModule
if(!is_dir($this->_basePath.'/'.$dir))
@mkdir($this->_basePath.'/'.$dir);
if(!is_file($file) || @filemtime($file)<@filemtime($fullpath))
+ {
+ Prado::trace("Publishing file $fullpath",'System.Web.UI.TAssetManager');
@copy($fullpath,$file);
+ }
}
$this->_published[$path]=$this->_baseUrl.'/'.$dir.'/'.basename($fullpath);
return $this->_published[$path];
@@ -164,7 +166,10 @@ class TAssetManager extends TModule
{
$dir=$this->hash($fullpath);
if(!is_dir($this->_basePath.'/'.$dir) || $checkTimestamp || $this->getApplication()->getMode()!==TApplication::STATE_PERFORMANCE)
+ {
+ Prado::trace("Publishing directory $fullpath",'System.Web.UI.TAssetManager');
$this->copyDirectory($fullpath,$this->_basePath.'/'.$dir);
+ }
$this->_published[$path]=$this->_baseUrl.'/'.$dir;
return $this->_published[$path];
}
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 3ba79478..225b6b32 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -683,11 +683,11 @@ class TControl extends TComponent
*/
public function dataBind()
{
- Prado::coreLog("Data bind properties");
+ Prado::trace("Data bind properties",'System.Web.UI.TControl');
$this->dataBindProperties();
- Prado::coreLog("onDataBinding()");
+ Prado::trace("onDataBinding()",'System.Web.UI.TControl');
$this->onDataBinding(null);
- Prado::coreLog("dataBindChildren()");
+ Prado::trace("dataBindChildren()",'System.Web.UI.TControl');
$this->dataBindChildren();
}
diff --git a/framework/Web/UI/TForm.php b/framework/Web/UI/TForm.php
index 28c6c3aa..4cb97911 100644
--- a/framework/Web/UI/TForm.php
+++ b/framework/Web/UI/TForm.php
@@ -53,7 +53,6 @@ class TForm extends TControl
*/
protected function render($writer)
{
- Prado::coreLog("Rendering form ".$this->getName());
$this->addAttributesToRender($writer);
$writer->renderBeginTag('form');
$page=$this->getPage();
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 2269079b..9808e143 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -117,9 +117,11 @@ class TPage extends TTemplateControl
*/
public function __construct($initProperties=null)
{
+ Prado::trace('Constructing page','System.Web.UI.TPage');
$this->setPage($this);
if(is_array($initProperties))
{
+ Prado::trace('Initializing page properties specified in configurations','System.Web.UI.TPage');
foreach($initProperties as $name=>$value)
$this->setSubProperty($name,$value);
}
@@ -133,59 +135,59 @@ class TPage extends TTemplateControl
*/
public function run($writer)
{
- Prado::coreLog("Running page life cycles");
+ Prado::trace("Running page life cycles",'System.Web.UI.TPage');
$this->determinePostBackMode();
-
- Prado::coreLog("Page onPreInit()");
+
+ Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
$this->onPreInit(null);
- Prado::coreLog("Page initRecursive()");
+ Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
$this->initRecursive();
- Prado::coreLog("Page onInitComplete()");
+ Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
$this->onInitComplete(null);
if($this->getIsPostBack())
{
$this->_restPostData=new TMap;
- Prado::coreLog("Page loadPageState()");
+ Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
$this->loadPageState();
- Prado::coreLog("Page processPostData()");
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
$this->processPostData($this->_postData,true);
- Prado::coreLog("Page onPreLoad()");
+ Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
$this->onPreLoad(null);
- Prado::coreLog("Page loadRecursive()");
+ Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
$this->loadRecursive();
- Prado::coreLog("Page processPostData()");
+ Prado::trace("Page processPostData()",'System.Web.UI.TPage');
$this->processPostData($this->_restPostData,false);
- Prado::coreLog("Page raiseChangedEvents()");
+ Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage');
$this->raiseChangedEvents();
- Prado::coreLog("Page raisePostBackEvent()");
+ Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
$this->raisePostBackEvent();
- Prado::coreLog("Page onLoadComplete()");
+ Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
$this->onLoadComplete(null);
}
else
{
- Prado::coreLog("Page onPreLoad()");
+ Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
$this->onPreLoad(null);
- Prado::coreLog("Page loadRecursive()");
+ Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
$this->loadRecursive();
- Prado::coreLog("Page onLoadComplete()");
+ Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
$this->onLoadComplete(null);
}
- Prado::coreLog("Page preRenderRecursive()");
+ Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
$this->preRenderRecursive();
- Prado::coreLog("Page onPreRenderComplete()");
+ Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
$this->onPreRenderComplete(null);
- Prado::coreLog("Page savePageState()");
+ Prado::trace("Page savePageState()",'System.Web.UI.TPage');
$this->savePageState();
- Prado::coreLog("Page onSaveStateComplete()");
+ Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
$this->onSaveStateComplete(null);
- Prado::coreLog("Page renderControl()");
+ Prado::trace("Page renderControl()",'System.Web.UI.TPage');
$this->renderControl($writer);
- Prado::coreLog("Page unloadRecursive()");
+ Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage');
$this->unloadRecursive();
}
@@ -284,7 +286,7 @@ class TPage extends TTemplateControl
$this->_validated=true;
if($this->_validators && $this->_validators->getCount())
{
- Prado::coreLog("Page validate");
+ Prado::trace("Page validate",'System.Web.UI.TPage');
if($validationGroup==='')
{
foreach($this->_validators as $validator)
diff --git a/framework/Web/UI/TPageStatePersister.php b/framework/Web/UI/TPageStatePersister.php
index 2711041a..bc65f74a 100644
--- a/framework/Web/UI/TPageStatePersister.php
+++ b/framework/Web/UI/TPageStatePersister.php
@@ -52,7 +52,7 @@ class TPageStatePersister extends TModule implements IStatePersister
*/
public function save($state)
{
- Prado::coreLog("Saving state");
+ Prado::trace("Saving state",'System.Web.UI.TPageStatePersister');
$data=Prado::serialize($state);
$hmac=$this->computeHMAC($data,$this->getPrivateKey());
if(extension_loaded('zlib'))
@@ -69,7 +69,7 @@ class TPageStatePersister extends TModule implements IStatePersister
*/
public function load()
{
- Prado::coreLog("Loading state");
+ Prado::trace("Loading state",'System.Web.UI.TPageStatePersister');
$str=base64_decode($this->getApplication()->getRequest()->getItems()->itemAt(TPage::FIELD_PAGESTATE));
if($str==='')
return null;
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php
index a25a2e41..93951718 100644
--- a/framework/Web/UI/TTemplateControl.php
+++ b/framework/Web/UI/TTemplateControl.php
@@ -101,9 +101,9 @@ class TTemplateControl extends TControl implements INamingContainer
*/
protected function loadTemplate()
{
- Prado::coreLog("Loading template ".get_class($this));
+ Prado::trace("Loading template ".get_class($this),'System.Web.UI.TTemplateControl');
$template=$this->getService()->getTemplateManager()->getTemplateByClassName(get_class($this));
- self::$_template[get_class($this)]=$template;
+ self::$_template[get_class($this)]=$template;
return $template;
}
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php
index df708e50..d03a15d6 100644
--- a/framework/Web/UI/TTemplateManager.php
+++ b/framework/Web/UI/TTemplateManager.php
@@ -60,7 +60,7 @@ class TTemplateManager extends TModule
public function getTemplateByClassName($className)
{
$class=new ReflectionClass($className);
- $tplFile=dirname($class->getFileName()).'/'.$className.self::TEMPLATE_FILE_EXT;
+ $tplFile=dirname($class->getFileName()).'/'.$className.self::TEMPLATE_FILE_EXT;
return $this->getTemplateByFileName($tplFile);
}
@@ -72,7 +72,7 @@ class TTemplateManager extends TModule
{
if(!is_null($fileName=$this->getLocalizedTemplate($fileName)))
{
- Prado::coreLog("Loading template $fileName");
+ Prado::trace("Loading template $fileName",'System.Web.UI.TTemplateManager');
if(($cache=$this->getApplication()->getCache())===null)
return new TTemplate(file_get_contents($fileName),dirname($fileName),$fileName);
else
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index 73745254..0c61321d 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -313,7 +313,7 @@ class TTheme extends TComponent
{
foreach($this->_skins[$type][$id] as $name=>$value)
{
- Prado::coreLog("Applying skin $name to $type");
+ Prado::trace("Applying skin $name to $type",'System.Web.UI.TThemeManager');
if(is_array($value))
{
if($value[0]===TTemplate::CONFIG_EXPRESSION)
diff --git a/framework/core.php b/framework/core.php
index 19f396a3..4c72fca6 100644
--- a/framework/core.php
+++ b/framework/core.php
@@ -45,8 +45,10 @@ require_once(PRADO_DIR.'/Web/THttpUtility.php');
* Includes TCache definition
*/
require_once(PRADO_DIR.'/Data/TCache.php');
-
-require_once(PRADO_DIR.'/Log/ILog.php');
+/**
+ * Includes TLogger definition
+ */
+require_once(PRADO_DIR.'/Log/TLogger.php');
/**
* IModule interface.
@@ -713,14 +715,18 @@ class PradoBase
return $language;
}
- public static function coreLog($msg=null)
+ public static function trace($msg,$category='Uncategorized')
{
- static $logger;
- if(is_null($logger))
- $logger = new TInternalLogger();
- if(!empty($msg))
- $logger->info($msg);
- return $logger;
+ if(!self::$_application || self::$_application->getMode()==='Debug')
+ {
+ $trace=debug_backtrace();
+ if(isset($trace[0]['file']) && isset($trace[0]['line']))
+ $msg.=" (line {$trace[0]['line']}, {$trace[0]['file']})";
+ $level=TLogger::DEBUG;
+ }
+ else
+ $level=TLogger::INFO;
+ self::log($msg,$level,$category);
}
public static function log($msg,$level=TLogger::INFO,$category='Uncategorized')
@@ -738,58 +744,4 @@ class PradoBase
}
}
-class TLogger extends TComponent
-{
- const DEBUG=0x01;
- const INFO=0x02;
- const NOTICE=0x04;
- const WARNING=0x08;
- const ERROR=0x10;
- const ALERT=0x20;
- const FATAL=0x40;
- private $_logs=array();
- private $_levels;
- private $_categories;
-
- public function log($message,$level,$category='Uncategorized')
- {
- $this->_logs[]=array($message,$level,$category,microtime());
- }
-
- public function getLogs($levels=null,$categories=null)
- {
- $this->_levels=$levels;
- $this->_categories=$categories;
- if(empty($levels) && empty($categories))
- return $this->_logs;
- else if(empty($levels))
- return array_values(array_filter(array_filter($this->_logs,array($this,'filterByCategories'))));
- else if(empty($categories))
- return array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
- else
- {
- $ret=array_values(array_filter(array_filter($this->_logs,array($this,'filterByLevels'))));
- return array_values(array_filter(array_filter($ret,array($this,'filterByCategories'))));
- }
- }
-
- private function filterByCategories($value)
- {
- foreach($this->_categories as $category)
- {
- if(strpos($value[2],$category)===0)
- return $value;
- }
- return false;
- }
-
- private function filterByLevels($value)
- {
- if($level & $this->_levels)
- return $value;
- else
- return false;
- }
-}
-
?> \ No newline at end of file