/** * Write to the log * * @param array $logEntry * @return Db */ public function writeLog(array $logEntry) { $columns = []; $params = []; $i = 1; foreach ($logEntry as $column => $value) { $placeholder = $this->sql->getPlaceholder(); if ($placeholder == ':') { $placeholder .= $column; } else { if ($placeholder == '$') { $placeholder .= $i; } } $columns[$column] = $placeholder; $params[$column] = $value; $i++; } $this->sql->insert($columns); $this->sql->db()->prepare((string) $this->sql)->bindParams($params)->execute(); return $this; }
/** * Write to a custom log * * @param string $content * @return Db */ public function writeCustomLog($content) { $fields = ['timestamp' => date('Y-m-d H:i:s'), 'level' => -1, 'name' => 'CUSTOM', 'message' => $content, 'context' => '']; $columns = []; $params = []; $i = 1; foreach ($fields as $column => $value) { $placeholder = $this->sql->getPlaceholder(); if ($placeholder == ':') { $placeholder .= $column; } else { if ($placeholder == '$') { $placeholder .= $i; } } $columns[$column] = $placeholder; $params[$column] = $value; $i++; } $this->sql->insert($columns); $this->sql->db()->prepare((string) $this->sql)->bindParams($params)->execute(); return $this; }