Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Zend Framework 101: Zend_Log

Recording Events

As we briefly saw in the previous section, you can record a message to the log using the log() method. The first argument is the message you want to log while the second argument is the priority level of the message.

By default, the priorities are as follows:

  • Zend_Log::EMERG: Emergency: system is unusable
  • Zend_Log::ALERT: Alert: action must be taken immediately
  • Zend_Log::CRIT: Critical: critical conditions
  • Zend_Log::ERR: Error: error conditions
  • Zend_Log::WARN: Warning: warning conditions
  • Zend_Log::NOTICE: Notice: normal but significant condition
  • Zend_Log::INFO: Informational: informational messages
  • Zend_Log::DEBUG: Debug: debug messages

You can pass any of these constants as the second argument to log(), or you can use one of the helper methods provided by Zend_Log. Previously we used $logger->log('message', Zend_Logger::INFO), but Zend_Log also allows us to use the shorthand method of $logger->info('message').

Messages for other priorities can also be recorded in this manner. For instance, $logger->warn('Some Warning') instead of $logger->log('Some Warning', Zend_Log::WARN).

Tip: You can also add your own priorities using the addPriority() method.

In This Article