PageRenderTime 72ms CodeModel.GetById 16ms RepoModel.GetById 12ms app.codeStats 0ms

/application/classes/Dlog.php

https://bitbucket.org/chrispiechowicz/zepto
PHP | 120 lines | 72 code | 13 blank | 35 comment | 5 complexity | 5922e649fabc1a163f46a94ef0965b72 MD5 | raw file
Possible License(s): LGPL-2.1, MIT, BSD-3-Clause
  1. <?php
  2. /**
  3. * Database logger
  4. *
  5. * @package zeptocms
  6. * @version 2012/11/13
  7. * @author Chris Piechowicz <info@zeptocms.com>
  8. */
  9. class Dlog
  10. {
  11. const TABLE = "logs";
  12. // log levels
  13. const SUCCESS = 1;
  14. const NOTICE = 2;
  15. const WARNING = 3;
  16. const ERROR = 4;
  17. // database instance
  18. protected static $db = FALSE;
  19. // current app area
  20. protected static $area = "site";
  21. /**
  22. * Add log item
  23. *
  24. * @param string $type log type (success, error, etc.)
  25. * @param string $title message title
  26. * @param string $description message description
  27. * @param string $debug additional information for developer
  28. */
  29. public static function add($type, $title, $description = NULL, $debug = NULL)
  30. {
  31. // check if logging enabled
  32. if (!Config::sys("log/enable") || $type > Config::sys("log/level"))
  33. return FALSE;
  34. if (!self::$db)
  35. self::$db = new Model_Db;
  36. $row = array(
  37. "adddate" => Date::now(),
  38. "type" => $type,
  39. "area" => Dlog::area(),
  40. "title" => $title,
  41. "description" => $description,
  42. "debug" => $debug
  43. );
  44. self::$db->addRow(self::TABLE, $row);
  45. }
  46. /**
  47. * Get current area
  48. *
  49. * @return string
  50. */
  51. public static function area()
  52. {
  53. return self::$area;
  54. }
  55. /**
  56. * Set current area
  57. *
  58. * @param string $area
  59. */
  60. public static function setCurrentArea($area)
  61. {
  62. self::$area = $area;
  63. }
  64. /**
  65. * Get log level name
  66. *
  67. * @param int $level level name
  68. * @return string
  69. */
  70. public static function getLevelName($level)
  71. {
  72. switch ($level)
  73. {
  74. case 1:
  75. return "success";
  76. break;
  77. case 2:
  78. return "notice";
  79. break;
  80. case 3:
  81. return "warning";
  82. break;
  83. case 4:
  84. return "error";
  85. break;
  86. }
  87. }
  88. public static function getLevelIcon($level)
  89. {
  90. switch ($level)
  91. {
  92. case 1:
  93. return HTML::image("res/img/admin/log/success.png", array("alt" => "success"));
  94. break;
  95. case 2:
  96. return HTML::image("res/img/admin/log/notice.png", array("alt" => "notice"));
  97. break;
  98. case 3:
  99. return HTML::image("res/img/admin/log/warning.png", array("alt" => "warning"));
  100. break;
  101. case 4:
  102. return HTML::image("res/img/admin/log/error.png", array("alt" => "error"));
  103. break;
  104. }
  105. }
  106. }
  107. ?>