1: <?php
2: namespace Genetsis\core;
3:
4: use Exception;
5:
6: 7: 8: 9: 10: 11: 12: 13:
14: class LogConfig implements \LoggerConfigurator
15: {
16:
17: 18:
19: protected $threshold = 'OFF';
20:
21: protected $log_path = '';
22:
23: 24: 25: 26: 27: 28:
29: public function __construct($levelInfo, $logPath)
30: {
31: if (!is_null($levelInfo)) {
32: $this->threshold = $levelInfo;
33: }
34: $this->log_path = dirname(__FILE__) . '/' . $logPath;
35:
36: if (!is_dir($this->log_path) || !is_writable($this->log_path)) {
37: $auto_create = mkdir($this->log_path, 0777, true);
38: if ($auto_create === false) {
39: throw new Exception("Failed creating Log directory [$this->log_path].");
40: }
41: }
42: }
43:
44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
54: public function configure(\LoggerHierarchy $hierarchy, $input = null)
55: {
56:
57: $layout = new \LoggerLayoutPattern();
58: $layout->setConversionPattern("%d{Y-m-d H:i:s}[%r] %-5level %C.%M[%L] %msg%n");
59: $layout->activateOptions();
60:
61:
62: $appLog = new \LoggerAppenderRollingFile('main');
63: $appLog->setFile($this->log_path . 'gid-all-requests.log');
64: $appLog->setAppend(true);
65: $appLog->setMaxFileSize('2MB');
66: $appLog->setMaxBackupIndex(5);
67: $appLog->setThreshold($this->threshold);
68: $appLog->setLayout($layout);
69: $appLog->activateOptions();
70:
71:
72: $appConsole = new \LoggerAppenderFile('console');
73: $appConsole->setFile($this->log_path . 'gid-last-request.log');
74: $appConsole->setAppend(false);
75: $appConsole->setThreshold($this->threshold);
76: $appConsole->setLayout($layout);
77: $appConsole->activateOptions();
78:
79:
80: $root = $hierarchy->getRootLogger();
81: $root->addAppender($appLog);
82: $root->addAppender($appConsole);
83: }
84: }