From 474cfb28535ebcf1b7d16da46e3dad48ed23a2e7 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sat, 14 Aug 2010 18:24:15 +0100 Subject: [PATCH] Updated logging to support multiple tables --- lib/HandBrakeCluster/Log.class.php | 6 ++++-- lib/HandBrakeCluster/Main.class.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/HandBrakeCluster/Log.class.php b/lib/HandBrakeCluster/Log.class.php index 12a59ae..378fe32 100644 --- a/lib/HandBrakeCluster/Log.class.php +++ b/lib/HandBrakeCluster/Log.class.php @@ -6,15 +6,17 @@ class HandBrakeCluster_Log { private $database; private $config; + private $table; - public function __construct(HandBrakeCluster_Database $database, HandBrakeCluster_Config $config) { + public function __construct(HandBrakeCluster_Database $database, HandBrakeCluster_Config $config, $table) { $this->database = $database; $this->config = $config; + $this->table = $table; } public function log($severity, $message, $job_id = 0) { - $this->database->insert('INSERT INTO client_log (job_id,level,ctime,pid,hostname,progname,line,message) VALUES(:job_id, :level, :ctime, :pid, :hostname, :progname, :line, :message)', + $this->database->insert("INSERT INTO {$this->table} (job_id,level,ctime,pid,hostname,progname,line,message) VALUES(:job_id, :level, :ctime, :pid, :hostname, :progname, :line, :message)", array( array('name' => 'job_id', 'value' => $job_id, 'type' => PDO::PARAM_INT), array('name' => 'level', 'value' => $severity, 'type' => PDO::PARAM_STR), diff --git a/lib/HandBrakeCluster/Main.class.php b/lib/HandBrakeCluster/Main.class.php index e4c7146..9fff224 100644 --- a/lib/HandBrakeCluster/Main.class.php +++ b/lib/HandBrakeCluster/Main.class.php @@ -17,12 +17,23 @@ class HandBrakeCluster_Main { private function __construct() { $request_string = isset($_GET['l']) ? $_GET['l'] : ''; + + $log_table = null; + switch(HBC_File) { + case 'index': { + $log_table = 'client_log'; + } break; + + case 'worker': { + $log_table = 'worker_log'; + } + } $this->config = new HandBrakeCluster_Config(HandBrakeCluster_DBConfig); $this->database = new HandBrakeCluster_Database($this->config); $this->config->setDatabase($this->database); - $this->log = new HandBrakeCluster_Log($this->database, $this->config); + $this->log = new HandBrakeCluster_Log($this->database, $this->config, $log_table); $this->request = new HandBrakeCluster_RequestParser($request_string); $this->cache = new HandBrakeCluster_Cache($this->config);