[44] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * $Header: /repository/pear/Log/Log/null.php,v 1.5 2006/06/29 07:09:21 jon Exp $
|
---|
| 4 | *
|
---|
| 5 | * @version $Revision: 1.5 $
|
---|
| 6 | * @package Log
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * The Log_null class is a concrete implementation of the Log:: abstract
|
---|
| 11 | * class. It simply consumes log events.
|
---|
| 12 | *
|
---|
| 13 | * @author Jon Parise <jon@php.net>
|
---|
| 14 | * @since Log 1.8.2
|
---|
| 15 | * @package Log
|
---|
| 16 | *
|
---|
| 17 | * @example null.php Using the null handler.
|
---|
| 18 | */
|
---|
| 19 | class Log_null extends Log
|
---|
| 20 | {
|
---|
| 21 | /**
|
---|
| 22 | * Constructs a new Log_null object.
|
---|
| 23 | *
|
---|
| 24 | * @param string $name Ignored.
|
---|
| 25 | * @param string $ident The identity string.
|
---|
| 26 | * @param array $conf The configuration array.
|
---|
| 27 | * @param int $level Log messages up to and including this level.
|
---|
| 28 | * @access public
|
---|
| 29 | */
|
---|
| 30 | function Log_null($name, $ident = '', $conf = array(),
|
---|
| 31 | $level = PEAR_LOG_DEBUG)
|
---|
| 32 | {
|
---|
| 33 | $this->_id = md5(microtime());
|
---|
| 34 | $this->_ident = $ident;
|
---|
| 35 | $this->_mask = Log::UPTO($level);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Opens the handler.
|
---|
| 40 | *
|
---|
| 41 | * @access public
|
---|
| 42 | * @since Log 1.9.6
|
---|
| 43 | */
|
---|
| 44 | function open()
|
---|
| 45 | {
|
---|
| 46 | $this->_opened = true;
|
---|
| 47 | return true;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * Closes the handler.
|
---|
| 52 | *
|
---|
| 53 | * @access public
|
---|
| 54 | * @since Log 1.9.6
|
---|
| 55 | */
|
---|
| 56 | function close()
|
---|
| 57 | {
|
---|
| 58 | $this->_opened = false;
|
---|
| 59 | return true;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Simply consumes the log event. The message will still be passed
|
---|
| 64 | * along to any Log_observer instances that are observing this Log.
|
---|
| 65 | *
|
---|
| 66 | * @param mixed $message String or object containing the message to log.
|
---|
| 67 | * @param string $priority The priority of the message. Valid
|
---|
| 68 | * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
|
---|
| 69 | * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
|
---|
| 70 | * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
|
---|
| 71 | * @return boolean True on success or false on failure.
|
---|
| 72 | * @access public
|
---|
| 73 | */
|
---|
| 74 | function log($message, $priority = null)
|
---|
| 75 | {
|
---|
| 76 | /* If a priority hasn't been specified, use the default value. */
|
---|
| 77 | if ($priority === null) {
|
---|
| 78 | $priority = $this->_priority;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /* Abort early if the priority is above the maximum logging level. */
|
---|
| 82 | if (!$this->_isMasked($priority)) {
|
---|
| 83 | return false;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | $this->_announce(array('priority' => $priority, 'message' => $message));
|
---|
| 87 |
|
---|
| 88 | return true;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | }
|
---|