feat(tw): Used RELATED-TO iCal prop as depends prop feat(tw): Used DESCRIPTION iCal prop as annotations refactor(tw): Changed project_tag_prefix to project_category_prefix chore(tw): Added documentation on configs
		
			
				
	
	
		
			79 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace Aerex\BaikalStorage;
 | |
| use Monolog\Logger as Monolog;
 | |
| use Monolog\Handler\StreamHandler;
 | |
| 
 | |
| class Logger {
 | |
| 
 | |
|   private $configs = ['enabled' => false];
 | |
| 
 | |
|   function __construct($configs, $tag) {
 | |
|     if (isset($configs['general']) && isset($configs['general']['logger'])) {
 | |
|       $this->configs = $configs['general']['logger'];
 | |
|     }
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->createLoggerFile();
 | |
|       $this->logger = new Monolog($tag);
 | |
|       $logLevel = Monolog::getLevels()[$this->configs['level']];
 | |
|       $this->logger->pushHandler(new StreamHandler($this->configs['file'], $logLevel));
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   public function createLoggerFile() {
 | |
|     if (!file_exists($this->configs['file'])) {
 | |
|       if (!fopen($this->configs['file'], 'w')) {
 | |
|         throw new \Exception(sprintf('Could not create logger file %s', $this->configs['file']));
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   public function debug($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->debug($message);
 | |
|     }
 | |
|   } 
 | |
| 
 | |
|   public function info($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->info($message);
 | |
|     }
 | |
|   } 
 | |
| 
 | |
|   public function notice($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->notice($message);
 | |
|     }
 | |
|   } 
 | |
| 
 | |
|   public function error($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->error($message);
 | |
|     }
 | |
|   } 
 | |
| 
 | |
|   public function critical($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->critical($message);
 | |
|     }
 | |
|   } 
 | |
|   public function alert($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->alert($message);
 | |
|     }
 | |
|   } 
 | |
| 
 | |
|   public function emergency($message) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->emergency($message);
 | |
|     }
 | |
|   } 
 | |
| 
 | |
|   public function setLevel($level) {
 | |
|     if ($this->configs['enabled']) {
 | |
|       $this->logger->setLevel($level);
 | |
|     }
 | |
|   }
 | |
| 
 | |
| }
 |