1 | <?php namespace Comodojo\Foundation\Logging; |
||
23 | class Manager { |
||
24 | |||
25 | const DEFAULT_LOGGER_NAME = 'comodojo'; |
||
26 | |||
27 | private $logger; |
||
28 | |||
29 | private $base_path; |
||
30 | |||
31 | 1 | public function __construct($name = null) { |
|
36 | |||
37 | 1 | public function setBasePath($path) { |
|
42 | |||
43 | public function getBasePath() { |
||
48 | |||
49 | 2 | public function getLogger() { |
|
54 | |||
55 | 1 | public function init($enable = true, $providers = array()) { |
|
56 | |||
57 | 1 | if ( !$enable ) { |
|
58 | |||
59 | $this->logger->pushHandler( ProviderBuilder::NullHandler() ); |
||
60 | |||
61 | return $this; |
||
62 | |||
63 | } |
||
64 | |||
65 | 1 | if ( empty($providers) ) return $this; |
|
66 | |||
67 | 1 | foreach ($providers as $provider => $parameters) { |
|
68 | |||
69 | 1 | $handler = $this->createProvider($provider, $parameters); |
|
70 | |||
71 | 1 | if ( $handler instanceof HandlerInterface ) $this->logger->pushHandler($handler); |
|
72 | |||
73 | 1 | } |
|
74 | |||
75 | 1 | return $this; |
|
76 | |||
77 | } |
||
78 | |||
79 | 1 | public static function createFromConfiguration(Configuration $configuration, $stanza = null) { |
|
80 | |||
81 | 1 | $base_path = $configuration->get('base-path'); |
|
82 | |||
83 | 1 | $log = null; |
|
84 | |||
85 | 1 | if ( $stanza !== null ) { |
|
86 | $log = $configuration->get($stanza); |
||
87 | } |
||
88 | |||
89 | 1 | if ( $log === null ) { |
|
90 | 1 | $log = $configuration->get('log'); |
|
91 | 1 | } |
|
92 | |||
93 | 1 | $name = empty($log['name']) ? null : $log['name']; |
|
94 | |||
95 | 1 | $enable = (empty($log['enable']) || $log['enable'] !== false) ? true : false; |
|
96 | |||
97 | 1 | $providers = empty($log['providers']) ? [] : $log['providers']; |
|
98 | |||
99 | 1 | $manager = new Manager($name); |
|
100 | |||
101 | 1 | $manager->setBasePath($base_path); |
|
102 | |||
103 | 1 | return $manager->init($enable, $providers); |
|
104 | |||
105 | } |
||
106 | |||
107 | public static function create($name = null, $enable = true, $providers = array()) { |
||
114 | |||
115 | 1 | private function createProvider($provider, $parameters) { |
|
116 | |||
146 | |||
147 | } |
||
148 |