PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/gallery/helpers/log.php

http://github.com/gallery/gallery3
PHP | 108 lines | 43 code | 10 blank | 55 comment | 0 complexity | 320c7621993bb3efe0949f3882e2aaa4 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php defined("SYSPATH") or die("No direct script access.");
  2. /**
  3. * Gallery - a web based photo album viewer and editor
  4. * Copyright (C) 2000-2013 Bharat Mediratta
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. class log_Core {
  21. const SUCCESS = 1;
  22. const INFO = 2;
  23. const WARNING = 3;
  24. const ERROR = 4;
  25. /**
  26. * Report a successful event.
  27. * @param string $category an arbitrary category we can use to filter log messages
  28. * @param string $message a detailed log message
  29. * @param string $html an html snippet presented alongside the log message to aid the admin
  30. */
  31. static function success($category, $message, $html="") {
  32. self::_add($category, $message, $html, log::SUCCESS);
  33. }
  34. /**
  35. * Report an informational event.
  36. * @param string $category an arbitrary category we can use to filter log messages
  37. * @param string $message a detailed log message
  38. * @param string $html an html snippet presented alongside the log message to aid the admin
  39. */
  40. static function info($category, $message, $html="") {
  41. self::_add($category, $message, $html, log::INFO);
  42. }
  43. /**
  44. * Report that something went wrong, not fatal, but worth investigation.
  45. * @param string $category an arbitrary category we can use to filter log messages
  46. * @param string $message a detailed log message
  47. * @param string $html an html snippet presented alongside the log message to aid the admin
  48. */
  49. static function warning($category, $message, $html="") {
  50. self::_add($category, $message, $html, log::WARNING);
  51. }
  52. /**
  53. * Report that something went wrong that should be fixed.
  54. * @param string $category an arbitrary category we can use to filter log messages
  55. * @param string $message a detailed log message
  56. * @param string $html an html snippet presented alongside the log message to aid the admin
  57. */
  58. static function error($category, $message, $html="") {
  59. self::_add($category, $message, $html, log::ERROR);
  60. }
  61. /**
  62. * Add a log entry.
  63. *
  64. * @param string $category an arbitrary category we can use to filter log messages
  65. * @param string $message a detailed log message
  66. * @param integer $severity INFO, WARNING or ERROR
  67. * @param string $html an html snippet presented alongside the log message to aid the admin
  68. */
  69. private static function _add($category, $message, $html, $severity) {
  70. $log = ORM::factory("log");
  71. $log->category = $category;
  72. $log->message = $message;
  73. $log->severity = $severity;
  74. $log->html = $html;
  75. $log->url = substr(url::abs_current(true), 0, 255);
  76. $log->referer = request::referrer(null);
  77. $log->timestamp = time();
  78. $log->user_id = identity::active_user()->id;
  79. $log->save();
  80. }
  81. /**
  82. * Convert a message severity to a CSS class
  83. * @param integer $severity
  84. * @return string
  85. */
  86. static function severity_class($severity) {
  87. switch($severity) {
  88. case log::SUCCESS:
  89. return "g-success";
  90. case log::INFO:
  91. return "g-info";
  92. case log::WARNING:
  93. return "g-warning";
  94. case log::ERROR:
  95. return "g-error";
  96. }
  97. }
  98. }