public function __construct($dsn = false, $username = "", $password = "", $attributes = [], $pdo = false) { if (!$dsn && !$pdo) { throw new \Exception("You must provide a DSN or PDO object"); } if ($dsn) { $pdo = new \PDO($dsn, $username, $password, $attributes); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } $this->pdo = $pdo; $this->insert = $pdo->prepare("INSERT INTO logging (level, message, pid) VALUES (:level, :message, :pid)"); parent::__construct(); }
public function __construct($logPath = false, $append = self::TRUNCATE) { if (!$logPath) { $this->logPath = self::DEFAULT_LOG_PATH; } else { $this->logPath = $logPath; } $openMode = 'a'; if (!$append) { $this->rotateLog(); $openMode = 'w'; } $handle = @fopen($this->logPath, $openMode); if (!$handle) { throw new Exception("Unable to open log path for writing: {$this->logPath}"); } $this->logHandle = $handle; parent::__construct(); }