]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Class/Logging.php
Update ReleaseNotes + ChangeLog
[bacula/bacula] / gui / baculum / protected / Class / Logging.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2016 Kern Sibbald
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The original author of Bacula is Kern Sibbald, with contributions
10  * from many others, a complete list can be found in the file AUTHORS.
11  *
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.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 class Logging extends TModule {
24
25         private $debugEnabled = false;
26
27         const CATEGORY_EXECUTE = 'Execute';
28         const CATEGORY_EXTERNAL = 'External';
29         const CATEGORY_APPLICATION = 'Application';
30         const CATEGORY_GENERAL = 'General';
31         const CATEGORY_SECURITY = 'Security';
32
33         public function init($config) {
34                 $this->debugEnabled = $this->isDebugOn();
35         }
36
37         public function isDebugOn() {
38                 $isDebug = false;
39                 $cfgModule = $this->Application->getModule('configuration');
40                 if($cfgModule->isApplicationConfig() === true) {
41                         $config = $cfgModule->getApplicationConfig();
42                         $isDebug = (isset($config['baculum']['debug']) && intval($config['baculum']['debug']) === 1);
43                 } else {
44                         $isDebug = true;
45                 }
46                 return $isDebug;
47         }
48
49         public function enableDebug($enable) {
50                 $result = false;
51                 $cfgModule = $this->Application->getModule('configuration');
52                 if($cfgModule->isApplicationConfig() === true) {
53                         $config = $cfgModule->getApplicationConfig();
54                         $config['baculum']['debug'] = ($enable === true) ? "1" : "0";
55                         $result = $cfgModule->setApplicationConfig($config);
56                 }
57                 return $result;
58         }
59
60         private function getLogCategories() {
61                 $categories = array(
62                         self::CATEGORY_EXECUTE,
63                         self::CATEGORY_EXTERNAL,
64                         self::CATEGORY_APPLICATION,
65                         self::CATEGORY_GENERAL,
66                         self::CATEGORY_SECURITY
67                 );
68                 return $categories;
69         }
70
71         public function log($cmd, $output, $category, $file, $line) {
72                 if($this->debugEnabled !== true) {
73                         return;
74                 }
75                 $this->Application->setMode('Debug');
76
77                 if(!in_array($category, $this->getLogCategories())) {
78                         $category = self::CATEGORY_SECURITY;
79                 }
80
81                 $log = sprintf(
82                         'Command=%s, Output=%s, File=%s, Line=%d',
83                         $cmd,
84                         print_r($output, true),
85                         $file,
86                         intval($line)
87                 );
88
89                 Prado::trace($log, $category);
90         }
91 }
92
93 ?>