3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 Marcin Haba
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.
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 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 class Logging extends TModule {
25 private $debugEnabled = false;
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';
33 public function init($config) {
34 $this->debugEnabled = $this->isDebugOn();
37 public function isDebugOn() {
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);
49 public function enableDebug($enable) {
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);
60 private function getLogCategories() {
62 self::CATEGORY_EXECUTE,
63 self::CATEGORY_EXTERNAL,
64 self::CATEGORY_APPLICATION,
65 self::CATEGORY_GENERAL,
66 self::CATEGORY_SECURITY
71 public function log($cmd, $output, $category, $file, $line) {
72 if($this->debugEnabled !== true) {
75 $this->Application->setMode('Debug');
77 if(!in_array($category, $this->getLogCategories())) {
78 $category = self::CATEGORY_SECURITY;
82 'Command=%s, Output=%s, File=%s, Line=%d',
84 print_r($output, true),
89 Prado::trace($log, $category);