Source for file Log.class.php
Documentation is available at Log.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* The Log class receives all Log_Message objects from the program. The Message
* must be an active type (or ignore types on). When the program is ready, simply
* call the 'write' method to save all the Message into a file. Once written,
* the messages are removed.
* The class implements the Lockable Interface. This lock only applies to Message
* Types. Once set, it cannot be unlocked from outside the class. This helps to
* ensure that additional Log Types are not added in other locations of the program.
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
gumbo_load ("Interface_Singleton");
gumbo_load ("Interface_Lockable");
gumbo_load ("Interface_Log");
gumbo_load ("Log_Message");
class Gumbo_Log implements Gumbo_Interface_Singleton, Gumbo_Interface_Log, Gumbo_Interface_Lockable {
/** @var Gumbo_Interface_Singleton $_instance */
private static $_instance =
null;
/** @var Gumbo_Log_Message[] $_messages list of Log_Messages */
/** @var bool $_status Logging turned on or off */
/** @var array $_types type of Log messages to allow */
/** @var bool $_ignore ignores Type restrictions */
/** @var bool $_locked if Log Message Types are locked */
* @return Gumbo_Interface_Log
if (self::$_instance ==
null) {
self::$_instance =
new Gumbo_Log ();
* Writes the messages to the corresponding Log file
* @throws Gumbo_Exception
public function write () {
// check if Logging is turned on
foreach ($this->getAll () as $mess) {
if ($fp =
@fopen ($mess->getFile (), "a+")) {
fwrite ($fp, $mess->getMessage ());
throw
new Gumbo_Exception ("Unable to Append Log File: {$mess->getFile ()}");
$e->setFunction (__METHOD__
);
* Adds a log message to the list
* @param Gumbo_Interface_Log_Message $mess
public function add (Gumbo_Log_Message $mess) {
* Clears the log messages in the system
public function clear () {
* Adds an active Log Message Type
* @precondition !isLocked()
* @precondition Type is not set
$e->setFunction (__METHOD__
);
* Removes an active Log Message Type
* @precondition !isLocked()
foreach ($this->getTypes () as $key=>
$val) {
$e->setFunction (__METHOD__
);
* @precondition !isLocked()
* @postcondition !getTypes()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* @postcondition isLocked()
public function lock () {
* Returns all the log messages
* Returns all the registered message types
* Returns if Logging is on
public function isOn () {
* Returns if the message type is registered
* @throws Gumbo_Exception
public function isType ($type) {
$e->setFunction (__METHOD__
);
* Returns if to ignore Types (or set to ignore Types)
* @precondition !isLocked()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Returns if the object is currently locked