<?php
class Logger {
    private $conn;

    public function __construct($db_conn) {
        $this->conn = $db_conn;
    }

    public function log($level, $message, $source = '', $additional_info = null) {
        $stmt = $this->conn->prepare("INSERT INTO logs (level, message, source, additional_info)
                                    VALUES (:level, :message, :source, :additional_info)");

        return $stmt->execute([
            ':level' => $level,
            ':message' => $message,
            ':source' => $source,
            ':additional_info' => $additional_info ? json_encode($additional_info) : null
        ]);
    }
}
?>
