Gumbo_Log_Message



Abstract Log Message

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 is set.

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.

Author(s): Michael Luster <mluster79@yahoo.com>
License:New BSD License
Copyright:Copyright (c) 2007, iBayou, Michael Luster
Link:http://sourceforge.net/projects/phpgumbo
Version:0.0.1

Implements interfaces:

Child classes:

Class Variables

string $_file =  "gumbo.log" [line 80]
bool $_formatted =  false [line 95]
string $_left_delimeter [line 90]
array $_lines = array () [line 78]
string $_line_end =  "\n" [line 87]
bool $_locked =  false [line 98]
string $_message [line 82]
string $_right_delimeter [line 92]
string $_separator =  "|" [line 84]
string $_type =  "default" [line 75]

Class Methods

public void addLine ( ) [line 153]

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 formatted.

  • postcondition:  !isFormatted()

[ Top ]
protected void format ( ) [line 109]

Formats the Log message

  • postcondition:  isFormatted()
  • postcondition:  isset($_message)
  • precondition:  !isFormatted()

[ Top ]
public string getFile ( ) [line 404]

Returns the log file


[ Top ]
public string getLeftDelimeter ( ) [line 436]

Returns the left delimeter


[ Top ]
public string getLineEnd ( ) [line 420]

Returns the line ending string


[ Top ]
public array getLines ( ) [line 412]

Returns all the message lines


[ Top ]
public string getMessage ( ) [line 395]

Returns the message


[ Top ]
public string getRightDelimeter ( ) [line 444]

Returns the right delimeter


[ Top ]
public string getSeparator ( ) [line 428]

Returns the element separator


[ Top ]
public string getType ( ) [line 387]

Returns the message type


[ Top ]
public bool isFormatted ( ) [line 452]

Returns if the message has been formatted


[ Top ]
public bool isLocked ( ) [line 460]

Returns if the object is currently locked


[ Top ]
public void lock ( ) [line 188]

Locks an object

  • postcondition:  isLocked()

[ Top ]
public void reset ( ) [line 171]

Resets the message lines


[ Top ]
public void setFile ( string $file ) [line 262]

Sets the log file

Parameter(s):

  • (string) $file :: file name (absolute path)
  • precondition:  !isLocked()
  • throws:  Gumbo_Exception

[ Top ]
protected void setFormatted ( bool $val ) [line 242]

Sets if the message has been formatted

Parameter(s):

  • (bool) $val
  • throws:  Gumbo_Exception

[ Top ]
public void setLeftDelimeter ( string $del ) [line 336]

Sets the left delimeter

Parameter(s):

  • (string) $del
  • throws:  Gumbo_Exception
  • postcondition:  !isFormatted()
  • precondition:  !isLocked()

[ Top ]
public void setLineEnd ( string $end ) [line 286]

Sets the line end string

Parameter(s):

  • (string) $end
  • throws:  Gumbo_Exception
  • postcondition:  !isFormatted()
  • precondition:  !isLocked()

[ Top ]
protected void setMessage ( string $mess ) [line 223]

Sets the message string

Parameter(s):

  • (string) $mess
  • throws:  Gumbo_Exception

[ Top ]
public void setRightDelimeter ( string $del ) [line 361]

Sets the right delimeter

Parameter(s):

  • (string) $del
  • throws:  Gumbo_Exception
  • postcondition:  !isFormatted()
  • precondition:  !isLocked()

[ Top ]
public void setSeparator ( string $sep ) [line 311]

Sets the separator between elements

Parameter(s):

  • (string) $sep
  • throws:  Gumbo_Exception
  • postcondition:  !isFormatted()
  • precondition:  !isLocked()

[ Top ]
public void setType ( string $type ) [line 201]

Sets the message type

Parameter(s):

  • (string) $type
  • precondition:  !isLocked()
  • throws:  Gumbo_Exception

[ Top ]