Created
March 31, 2014 07:11
-
-
Save GeeH/9886906 to your computer and use it in GitHub Desktop.
Logger functions not playing together??? ZF2 core functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Global Configuration Override | |
* | |
* You can use this file for overriding configuration values from modules, etc. | |
* You would place values in here that are agnostic to the environment and not | |
* sensitive to security. | |
* | |
* @NOTE: In practice, this file will typically be INCLUDED in your source | |
* control, so do not include passwords or other sensitive information in this | |
* file. | |
*/ | |
return array( | |
'service_manager' => array( | |
'abstract_factories' => array( | |
'Zend\Log\LoggerAbstractServiceFactory' | |
) | |
), | |
'log' => array( | |
'App\\Log' => array( | |
'writers' => array( | |
array( | |
'name' => 'stream', | |
'options' => array( | |
'stream' => 'log/' . date('dmY') . '.log', | |
'filters' => array( | |
'priority' => array( | |
'name' => 'priority', | |
'options' => array( | |
'priority' => Zend\Log\Logger::CRIT | |
) | |
), | |
), | |
), | |
), | |
), | |
), | |
), | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Controller; | |
use Zend\Log\LoggerAwareInterface; | |
use Zend\Log\LoggerAwareTrait; | |
use Zend\Mvc\Controller\AbstractActionController; | |
// Logger Aware Interface applies initialiser that injects logger automagically | |
class IndexController extends AbstractActionController implements LoggerAwareInterface | |
{ | |
// Loger Aware Trait provides the properties and methods to automagically support the Aware Interface | |
use LoggerAwareTrait; | |
public function indexAction() | |
{ | |
// ERROR - logger is null at this point, the initialiser doesn't know what to look for in SM (or my key is wrong) | |
$this->logger->info('hello world'); | |
// WORKS - App\\Log _is_ a well formed instance of Zend\Log\Logger - how do I get the initialiser to use this key? | |
$this->getServiceLocator()->get('App\\Log')->info('hello world'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment