OverviewZend_Log is a component for general purpose logging. It supports multiple log backends, formatting messages sent to the log, and filtering messages from being logged. These functions are divided into the following objects:
Creating a LogTo get started logging, instantiate a Writer and then pass it to a Log instance:
Alternatively, you can pass a Writer directly to constructor of Log as a shortcut:
Logging MessagesTo log a message, call the log() method of a Log instance and pass it the message with a corresponding priority:
message and the second parameter is an integer priority . The
priority must be one of the priorities recognized by the Log instance. This is explained
in the next section.
A shortcut is also available. Instead of calling the log() method, you can call a method by the same name as the priority:
Destroying a LogIf the Log object is no longer needed, set the variable containing it to NULL to destroy it. This will automatically call the shutdown() instance method of each attached Writer before the Log object is destroyed:
Using Built-in PrioritiesThe Zend_Log class defines the following priorities:
The priorities are not arbitrary. They come from the BSD Priority numbers descend in order of importance. EMERG (0) is the most important priority. DEBUG (7) is the least important priority of the built-in priorities. You may define priorities of lower importance than DEBUG. When selecting the priority for your log message, be aware of this priority hierarchy and choose appropriately. Adding User-defined PrioritiesUser-defined priorities can be added at runtime using the Log's addPriority() method:
8 . The new priority is then available for logging:
Understanding Log Events
When you call the log() method or one of its shortcuts, a
log event is created. This is simply an associative array with data
describing the event that is passed to the writers. The following keys
are always created in this array:
The creation of the To add a new item to every future event, call the setEventItem() method giving a key and a value: pid and populates
it with the PID of the current process. Once a new item has been
set, it is available automatically to all writers along with all of the
other data event data during logging. An item can be overwritten at any
time by calling the setEventItem() method again.
Setting a new event item with setEventItem() causes the new item to be sent to all writers of the logger. However, this does not guarantee that the writers actually record the item. This is because the writers won't know what to do with it unless a formatter object is informed of the new item. Please see the section on Formatters to learn more.
|