Improved database abstraction class to support insert and select queries in various forms. Added classes for pulling log entries back out of the database. Updated Job class to describe a known job in the database, and added JobStatus to track status updates on jobs. Updated Config class to connect to the database, and load all settings on startup. Improved the class autoloader to support Exceptions in a single file as a special case, and added this file.
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
class HandBrakeCluster_Log {
|
|
|
|
private static $hostname = '';
|
|
|
|
private $database;
|
|
private $config;
|
|
|
|
public function __construct(HandBrakeCluster_Database $database, HandBrakeCluster_Config $config) {
|
|
$this->database = $database;
|
|
$this->config = $config;
|
|
|
|
}
|
|
|
|
public function log($severity, $message, $job_id = 0) {
|
|
$result = $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)',
|
|
array(
|
|
array('name' => 'job_id', 'value' => $job_id, 'type' => PDO::PARAM_INT),
|
|
array('name' => 'level', 'value' => $severity, 'type' => PDO::PARAM_STR),
|
|
array('name' => 'ctime', 'value' => time(), 'type' => PDO::PARAM_INT),
|
|
array('name' => 'pid', 'value' => 0, 'type' => PDO::PARAM_INT),
|
|
array('name' => 'hostname', 'value' => self::$hostname, 'type' => PDO::PARAM_STR),
|
|
array('name' => 'progname', 'value' => 'webui', 'type' => PDO::PARAM_STR),
|
|
array('name' => 'line', 'value' => 0, 'type' => PDO::PARAM_INT),
|
|
array('name' => 'message', 'value' => $message, 'type' => PDO::PARAM_STR)
|
|
)
|
|
);
|
|
|
|
if (!$result) {
|
|
var_dump($this->database->errorInfo());
|
|
}
|
|
}
|
|
|
|
public function debug($message, $job_id = 0) {
|
|
return $this->log('DEBUG', $message, $job_id);
|
|
}
|
|
|
|
public function info($messgae, $job_id = 0) {
|
|
return $this->log('INFO', $message, $job_id);
|
|
}
|
|
|
|
public function warning($message, $job_id = 0) {
|
|
return $this->log('WARNING', $message, $job_id);
|
|
}
|
|
|
|
public function error($message, $job_id = 0) {
|
|
return $this->log('ERROR', $message, $job_id);
|
|
}
|
|
|
|
public static function initialise() {
|
|
self::$hostname = trim(`hostname`);
|
|
}
|
|
|
|
}
|
|
|
|
HandBrakeCluster_Log::initialise();
|
|
|
|
?>
|