3 * Bacula® - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2014 Marcin Haba
8 * The main author of Baculum is Marcin Haba.
9 * The main author of Bacula is Kern Sibbald, with contributions from many
10 * others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * Bacula® is a registered trademark of Kern Sibbald.
20 class Logging extends TModule {
22 private $debugEnabled = false;
24 const CATEGORY_EXECUTE = 'Execute';
25 const CATEGORY_EXTERNAL = 'External';
26 const CATEGORY_APPLICATION = 'Application';
27 const CATEGORY_GENERAL = 'General';
28 const CATEGORY_SECURITY = 'Security';
30 public function init($config) {
31 $this->debugEnabled = $this->isDebugOn();
34 public function isDebugOn() {
36 $cfgModule = $this->Application->getModule('configuration');
37 if($cfgModule->isApplicationConfig() === true) {
38 $config = $cfgModule->getApplicationConfig();
39 $isDebug = (isset($config['baculum']['debug']) && intval($config['baculum']['debug']) === 1);
46 public function enableDebug($enable) {
48 $cfgModule = $this->Application->getModule('configuration');
49 if($cfgModule->isApplicationConfig() === true) {
50 $config = $cfgModule->getApplicationConfig();
51 $config['baculum']['debug'] = ($enable === true) ? "1" : "0";
52 $result = $cfgModule->setApplicationConfig($config);
57 private function getLogCategories() {
59 self::CATEGORY_EXECUTE,
60 self::CATEGORY_EXTERNAL,
61 self::CATEGORY_APPLICATION,
62 self::CATEGORY_GENERAL,
63 self::CATEGORY_SECURITY
68 public function log($cmd, $output, $category, $file, $line) {
69 if($this->debugEnabled !== true) {
73 if(!in_array($category, $this->getLogCategories())) {
74 $category = self::CATEGORY_SECURITY;
78 'Command=%s, Output=%s, File=%s, Line=%d',
80 print_r($output, true),
85 Prado::trace($log, $category);