public function testDelayedInit() { ezcBaseInit::setCallback('ezcInitLog', 'testDelayedInitLog'); $log = ezcLog::getInstance(); $rule = new ezcLogFilterRule(new ezcLogFilter(), $writer = new ezcLogUnixFileWriter('/'), true); $expected = new ezcLogFilterSet(); $expected->appendRule($rule); $this->assertAttributeEquals($expected, 'writers', $log); }
/** * 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. * * @param ezcLogFilter $logFilter * @param string $fileName */ public function setFile(ezcLogFilter $logFilter, $fileName) { $fh = $this->openFile($fileName); $this->fileMap->appendRule(new ezcLogFilterRule($logFilter, $fh, true)); }
/** * 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 */ public function setTable(ezcLogFilter $logFilter, $tableName) { $this->map->appendRule(new ezcLogFilterRule($logFilter, $tableName, true)); }
/** * 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 */ public function log($message, $severity, array $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"]); $attributes = array_merge($this->context->getContext($severity, $source), $attributes); $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; } } } }