Source for file Message.class.php
Documentation is available at Message.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
* A Log Message contains information that should be logged into the Log file.
* A Message can contain a single line of information, or span multiple lines. It
* depends on the type of Message. Every line is separated into sections, each
* section contain an actual piece of data. The information is written to the
* Message file, either directly or through a Log class. The file is appended,
* placing the formatted message at the end of the file.
* The Abstract Message contains a standard formatting implementation. This will
* format a string based on the contents of the Message. The format method will
* loop through each line, appending a string variable with the details. The
* line is formatted started with the 'Left Delimeter'. Each line is parsed into
* sections, each section appended to the string, separated by the 'Separator'
* character string. The line ends by placing the 'Right Delimeter' before the
* 'Line End' string. Once all lines have been formatted, the 'Message' text
* To add Lines to a message, call the addLine() method with arguments that represent
* the sections of the line. For example, if producing a Log Message with the
* following format: 'date|id|name', simply call addLine() as:
* $mess->addLine ($date, $id, $name);
* Log Files will contain different formats. In order to format a Log File to
* a specific format, simply extend the Abstract Message class, writing the rules
* and defaults in the Constructor (see Gumbo_Log_Message_Generic). If special
* formatting is required, simply write a custom 'format' implementation. If the
* default values should not be changed, simply 'lock' the message. (This does
* not apply to adding lines).
* It is important to define the Log File inside the Message class. An Email Log
* Message should write to an 'email.log' file, while an Access Log Message should write
* to an 'access.log' file. This allows the program to simply create a new Log Message
* without having to define the file to write to. By creating multiple Log Messages
* with specific formatting rules, the program would only need to instantiate the
* Log Message class, add the necessary details and send to the Log class.
* @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
* @desc Abstract Log Message
gumbo_load ("Interface_Lockable");
/** @var string $_type log message type */
/** @var array $_lines a single message line */
/** @var string $_file log file name (absolute path) */
/** @var string $_message formatted log message */
/** @var string $_separator element separator */
/** @var string $_line_end end of line string */
/** @var string $_left_delimeter line begin delimeter */
/** @var string $_right_delimeter line end delimeter */
/** @var bool $_formatted if the message has been formatted */
/** @var bool $_locked if the settings are locked */
* Formats the Log message
* @precondition !isFormatted()
* @postcondition isFormatted()
* @postcondition isset($_message)
protected function format () {
foreach ($val as $element) {
if ($x ==
$num) { $txt .= (string)
$element; break; }
$txt .= (string)
$element;
* Adds a line to the log message
* The arguments supplied will be the data that is represented in the printed
* string in the message. Each argument will be a different piece of data, which
* will be separated by the Separator character string when the message is
* @postcondition !isFormatted()
* Resets the message lines
public function reset () {
$this->_file =
"default.log";
* @postcondition isLocked()
public function lock () {
* @precondition !isLocked()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Sets the message string
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Sets if the message has been formatted
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* @precondition !isLocked()
* @param string $file file name (absolute path)
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Sets the line end string
* @precondition !isLocked()
* @postcondition !isFormatted()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Sets the separator between elements
* @precondition !isLocked()
* @postcondition !isFormatted()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Sets the left delimeter
* @precondition !isLocked()
* @postcondition !isFormatted()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Sets the right delimeter
* @precondition !isLocked()
* @postcondition !isFormatted()
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Returns the message type
* Returns all the message lines
* Returns the line ending string
* Returns the element separator
* Returns the left delimeter
* Returns the right delimeter
* Returns if the message has been formatted
* Returns if the object is currently locked