/** * Constructor is a initialize logger * * @access public * * @param array $params configuration params * * @throws \Micro\Base\Exception * @result void */ public function __construct(array $params = []) { parent::__construct($params); $this->from = !empty($params['from']) ? $params['from'] : getenv('SERVER_ADMIN'); $this->to = !empty($params['to']) ? $params['to'] : $this->from; $this->subject = $params['subject'] ?: getenv('SERVER_NAME') . ' log message'; }
/** * Constructor prepare DB * * @access public * * @param array $params configuration params * * @result void * @throws Exception */ public function __construct(array $params = []) { parent::__construct($params); $this->tableName = !empty($params['table']) ? $params['table'] : 'logs'; $this->db = (new Injector())->getDriver(); if (!$this->db->tableExists($this->tableName)) { $this->db->createTable($this->tableName, array('`id` INT AUTO_INCREMENT', '`level` VARCHAR(20) NOT NULL', '`message` TEXT NOT NULL', '`date_create` INT NOT NULL', 'PRIMARY KEY(id)'), 'ENGINE=InnoDB DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci'); } }
/** * Open file for write messages * * @access public * * @param array $params configuration params * * @result void * @throws Exception */ public function __construct(array $params = []) { parent::__construct($params); if (is_writable($params['filename']) || is_writable(dirname($params['filename']))) { $this->connect = fopen($params['filename'], 'a+'); } else { throw new Exception('Directory or file "' . $params['filename'] . '" is read-only'); } }