550 public function persisted(PersistenceEvent $event) {
551 // do something on any create/update/delete
556 @note To prevent memory leaks the
557 \link wcmf::lib::core::EventManager::removeListener `EventManager::removeListener`\endlink
558 method __must__ be called, if the event listener is destroyed.
560 To send a persistence event, the following code is used:
563 $eventListener = ObjectFactory::getInstance('eventManager');
564 $eventListener->dispatch(PersistenceEvent::NAME,
565 new PersistenceEvent($object, PersistenceAction::UPDATE));
568 ### Implicit listener installation ### {#pres_listeners}
570 In some cases you may want to install event listeners without explicitely
571 instantiating them, because there is no appropriate place for that. For these
572 cases the \link wcmf::lib::presentation::Application `Application`\endlink class
573 reads the `listeners` value of the `Application` configuration section and
574 initializes all instances listed there.
576 The \ref app "default application" defines two listeners as shown in the following
581 listeners = {Search, EventListener}
584 Each entry in the `listeners` array is supposed to refer to an instance
585 configuration (see \ref conf_di).
587 ## Logging ## {#pres_log}
589 wCMF integrates the logging frameworks [log4php](http://logging.apache.org/log4php/)
590 and [Monolog](https://github.com/Seldaek/monolog). To abstract from these libraries
591 wCMF defines the \link wcmf::lib::core::Logger `Logger`\endlink interface and
592 implementations for each framework. The decision, which framework to use is made
593 by instantiating the appropriate \link wcmf::lib::core::Logger `Logger`\endlink
594 instance and passing it to the
595 \link wcmf::lib::core::LogManager::configure `LogManager::configure`\endlink
596 method as shown for _Monolog_ in the following example:
599 $logger = new MonologFileLogger('main', WCMF_BASE.'app/config/log.ini');
600 LogManager::configure($logger);
603 Afterwards \link wcmf::lib::core::Logger `Logger`\endlink instances can be retrieved
604 using the following code:
607 $logger = LogManager::getLogger(__CLASS__);
610 The parameter used in the
611 \link wcmf::lib::core::LogManager::getLogger `LogManager::getLogger`\endlink method
612 is the _logger name_. It's a good practice to use the `__CLASS__` constant as logger
613 name, since this allows to enable/disable loggers by class names in the configuration
614 (see \ref conf_logging).
616 The following example shows how to log an error message with a stack trace
618 \link wcmf::lib::core::ErrorHandler::getStackTrace `ErrorHandler::getStackTrace`\endlink):
621 $logger->error("An error occured.\n".ErrorHandler::getStackTrace());