log.class.inc.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * File logging
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. class FileLog
  25. {
  26. protected $m_sFile = ''; // log is disabled if this is empty
  27. public function __construct($sFileName = '')
  28. {
  29. $this->m_sFile = $sFileName;
  30. }
  31. public function Error($sText)
  32. {
  33. self::Write("Error | ".$sText);
  34. }
  35. public function Warning($sText)
  36. {
  37. self::Write("Warning | ".$sText);
  38. }
  39. public function Info($sText)
  40. {
  41. self::Write("Info | ".$sText);
  42. }
  43. public function Ok($sText)
  44. {
  45. self::Write("Ok | ".$sText);
  46. }
  47. protected function Write($sText)
  48. {
  49. if (strlen($this->m_sFile) == 0) return;
  50. $hLogFile = @fopen($this->m_sFile, 'a');
  51. if ($hLogFile !== false)
  52. {
  53. $sDate = date('Y-m-d H:i:s');
  54. fwrite($hLogFile, "$sDate | $sText\n");
  55. fclose($hLogFile);
  56. }
  57. }
  58. }
  59. class SetupLog
  60. {
  61. protected static $m_oFileLog;
  62. public static function Enable($sTargetFile)
  63. {
  64. self::$m_oFileLog = new FileLog($sTargetFile);
  65. }
  66. public static function Error($sText)
  67. {
  68. self::$m_oFileLog->Error($sText);
  69. }
  70. public static function Warning($sText)
  71. {
  72. self::$m_oFileLog->Warning($sText);
  73. }
  74. public static function Info($sText)
  75. {
  76. self::$m_oFileLog->Info($sText);
  77. }
  78. public static function Ok($sText)
  79. {
  80. self::$m_oFileLog->Ok($sText);
  81. }
  82. }
  83. class IssueLog
  84. {
  85. protected static $m_oFileLog;
  86. public static function Enable($sTargetFile)
  87. {
  88. self::$m_oFileLog = new FileLog($sTargetFile);
  89. }
  90. public static function Error($sText)
  91. {
  92. self::$m_oFileLog->Error($sText);
  93. }
  94. public static function Warning($sText)
  95. {
  96. self::$m_oFileLog->Warning($sText);
  97. }
  98. public static function Info($sText)
  99. {
  100. self::$m_oFileLog->Info($sText);
  101. }
  102. public static function Ok($sText)
  103. {
  104. self::$m_oFileLog->Ok($sText);
  105. }
  106. }
  107. class ToolsLog
  108. {
  109. protected static $m_oFileLog;
  110. public static function Enable($sTargetFile)
  111. {
  112. self::$m_oFileLog = new FileLog($sTargetFile);
  113. }
  114. public static function Error($sText)
  115. {
  116. self::$m_oFileLog->Error($sText);
  117. }
  118. public static function Warning($sText)
  119. {
  120. self::$m_oFileLog->Warning($sText);
  121. }
  122. public static function Info($sText)
  123. {
  124. self::$m_oFileLog->Info($sText);
  125. }
  126. public static function Ok($sText)
  127. {
  128. self::$m_oFileLog->Ok($sText);
  129. }
  130. }
  131. ?>