Skip to content
barryo edited this page Mar 25, 2013 · 2 revisions

OSS_Logger is a load on demand resource as opposed to Zend's logger resource which is always loaded whether used or now.

It is configured almost identically to the Zend_Logger resource. Here's a real example:

ondemand_resources.logger.enabled = 1
ondemand_resources.logger.writers.email.from = [email protected]
ondemand_resources.logger.writers.email.to = [email protected]
ondemand_resources.logger.writers.email.prefix = 'APP_Error'
ondemand_resources.logger.writers.email.level = 3
ondemand_resources.logger.writers.stream.level = 7
ondemand_resources.logger.writers.stream.path = APPLICATION_PATH "/../var/log"
ondemand_resources.logger.writers.stream.owner = www-data
ondemand_resources.logger.writers.stream.group = www-data

You then use the following trait:

use OSS_Controller_Action_Trait_Logger;

where after, any time that is required in your application controllers, you can create a log message using any of:

$this->getLogger()->emerg( 'log message' );
$this->getLogger()->alert( 'log message' );
$this->getLogger()->crit( 'log message' );
$this->getLogger()->err( 'log message' );
$this->getLogger()->warn( 'log message' );
$this->getLogger()->notice( 'log message' );
$this->getLogger()->info( 'log message' );
$this->getLogger()->debug( 'log message' );

When getLogger() is called, the logger is only then instantiated if not already done.

You can also log via:

$this->getLogger()->log( 'log message', OSS_Logger::EMERG|ALERT|CRIT|ERR|WARN|NOTICE|INFO|DEBUG );

Stream Directories and Files

By default, the OSS_Logger will layout the log structure as YYYY/MM/YYYYMMDD.log and it will try and create these directories under ondemand_resources.logger.writers.stream.path.

You can have it write to a named file instead via:

ondemand_resources.logger.writers.stream.mode    = single
ondemand_resources.logger.writers.stream.logname = appname.log

This is more useful when, for example, using fail2ban but should be integrated with logrotate.

Clone this wiki locally