/** * Constructor initialize logger * * @access public * * @param IContainer $container * @param array $params configuration params * * @result void * @throws \Micro\base\Exception */ public function __construct(IContainer $container, array $params = []) { parent::__construct($container, $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 IContainer $container Container * @param array $params configuration params * * @result void * @throws Exception */ public function __construct(IContainer $container, array $params = []) { parent::__construct($container, $params); $this->tableName = !empty($params['table']) ? $params['table'] : 'logs'; if (!$this->container->db->tableExists($this->tableName)) { $this->container->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 IContainer $container * @param array $params configuration params * * @result void * @throws Exception */ public function __construct(IContainer $container, array $params = []) { parent::__construct($container, $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'); } }