123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- // Copyright (C) 2010-2012 Combodo SARL
- //
- // This file is part of iTop.
- //
- // iTop is free software; you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // iTop is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with iTop. If not, see <http://www.gnu.org/licenses/>
- /**
- * File logging
- *
- * @copyright Copyright (C) 2010-2012 Combodo SARL
- * @license http://opensource.org/licenses/AGPL-3.0
- */
- class FileLog
- {
- protected $m_sFile = ''; // log is disabled if this is empty
- public function __construct($sFileName = '')
- {
- $this->m_sFile = $sFileName;
- }
- public function Error($sText)
- {
- self::Write("Error | ".$sText);
- }
- public function Warning($sText)
- {
- self::Write("Warning | ".$sText);
- }
- public function Info($sText)
- {
- self::Write("Info | ".$sText);
- }
- public function Ok($sText)
- {
- self::Write("Ok | ".$sText);
- }
- protected function Write($sText)
- {
- if (strlen($this->m_sFile) == 0) return;
- $hLogFile = @fopen($this->m_sFile, 'a');
- if ($hLogFile !== false)
- {
- $sDate = date('Y-m-d H:i:s');
- fwrite($hLogFile, "$sDate | $sText\n");
- fclose($hLogFile);
- }
- }
- }
- class SetupLog
- {
- protected static $m_oFileLog;
- public static function Enable($sTargetFile)
- {
- self::$m_oFileLog = new FileLog($sTargetFile);
- }
- public static function Error($sText)
- {
- self::$m_oFileLog->Error($sText);
- }
- public static function Warning($sText)
- {
- self::$m_oFileLog->Warning($sText);
- }
- public static function Info($sText)
- {
- self::$m_oFileLog->Info($sText);
- }
- public static function Ok($sText)
- {
- self::$m_oFileLog->Ok($sText);
- }
- }
- class IssueLog
- {
- protected static $m_oFileLog;
- public static function Enable($sTargetFile)
- {
- self::$m_oFileLog = new FileLog($sTargetFile);
- }
- public static function Error($sText)
- {
- self::$m_oFileLog->Error($sText);
- }
- public static function Warning($sText)
- {
- self::$m_oFileLog->Warning($sText);
- }
- public static function Info($sText)
- {
- self::$m_oFileLog->Info($sText);
- }
- public static function Ok($sText)
- {
- self::$m_oFileLog->Ok($sText);
- }
- }
- class ToolsLog
- {
- protected static $m_oFileLog;
- public static function Enable($sTargetFile)
- {
- self::$m_oFileLog = new FileLog($sTargetFile);
- }
- public static function Error($sText)
- {
- self::$m_oFileLog->Error($sText);
- }
- public static function Warning($sText)
- {
- self::$m_oFileLog->Warning($sText);
- }
- public static function Info($sText)
- {
- self::$m_oFileLog->Info($sText);
- }
- public static function Ok($sText)
- {
- self::$m_oFileLog->Ok($sText);
- }
- }
- ?>
|