Log.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Lychee\Modules;
  3. final class Log {
  4. /**
  5. * @return boolean Returns true when successful.
  6. */
  7. public static function notice($connection, $function, $line, $text = '') {
  8. return Log::text($connection, 'notice', $function, $line, $text);
  9. }
  10. /**
  11. * @return boolean Returns true when successful.
  12. */
  13. public static function error($connection, $function, $line, $text = '') {
  14. return Log::text($connection, 'error', $function, $line, $text);
  15. }
  16. /**
  17. * @return boolean Returns true when successful.
  18. */
  19. private static function text($connection, $type, $function, $line, $text = '') {
  20. // Check dependencies
  21. Validator::required(isset($connection, $type, $function, $line, $text), __METHOD__);
  22. // Get time
  23. $sysstamp = time();
  24. // Save in database
  25. $query = Database::prepare($connection, "INSERT INTO ? (time, type, function, line, text) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_LOG, $sysstamp, $type, $function, $line, $text));
  26. $result = Database::execute($connection, $query, null, null);
  27. if ($result===false) return false;
  28. return true;
  29. }
  30. }
  31. ?>