fork download
  1. public function write_log($level = 'error', $msg, $php_error = FALSE)
  2. {
  3. // Start the session if not already started
  4. if (session_status() == PHP_SESSION_NONE) {
  5. session_start();
  6. }
  7.  
  8. // Write data to the session
  9. $_SESSION['last_log_time'] = date($this->_date_fmt);
  10. $_SESSION['last_log_message'] = $msg;
  11.  
  12. // Check if logging is enabled
  13. if ($this->_enabled === FALSE) {
  14. echo "Logging is disabled.\n";
  15. return FALSE;
  16. }
  17.  
  18. $level = strtoupper($level);
  19.  
  20. // Validate the log level
  21. if (!isset($this->_levels[$level]) || ($this->_levels[$level] > $this->_threshold)) {
  22. return FALSE;
  23. }
  24.  
  25. $filepath = $this->_log_path . 'log-' . date('Y-m-d') . '.php';
  26. $message = '';
  27.  
  28. // Add a PHP header to the log file if it doesn't exist
  29. if (!file_exists($filepath)) {
  30. $message .= "<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>\n\n";
  31. }
  32.  
  33. // Try to open the log file
  34. if (!$fp = @fopen($filepath, 'a')) { // Use 'a' for append mode
  35. return FALSE;
  36. }
  37.  
  38. // Append the log message
  39. $message .= $level . ' ' . (($level === 'INFO') ? ' -' : '-') . ' ' . date($this->_date_fmt) . ' --> ' . $msg . "\n";
  40.  
  41. // Lock file, write the message, and unlock
  42. flock($fp, LOCK_EX);
  43. fwrite($fp, $message);
  44. flock($fp, LOCK_UN);
  45. fclose($fp);
  46.  
  47. // Set file permissions
  48. @chmod($filepath, 0644); // Use an octal value for permissions
  49.  
  50. // Print session data to the output
  51. echo "Session Data:\n";
  52. echo "Last Log Time: " . $_SESSION['last_log_time'] . "\n";
  53. echo "Last Log Message: " . $_SESSION['last_log_message'] . "\n";
  54.  
  55. return TRUE;
  56. }
  57.  
Success #stdin #stdout 0.03s 25620KB
stdin
Standard input is empty
stdout
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
    // Start the session if not already started
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }

    // Write data to the session
    $_SESSION['last_log_time'] = date($this->_date_fmt);
    $_SESSION['last_log_message'] = $msg;

    // Check if logging is enabled
    if ($this->_enabled === FALSE) {
        echo "Logging is disabled.\n";
        return FALSE;
    }

    $level = strtoupper($level);

    // Validate the log level
    if (!isset($this->_levels[$level]) || ($this->_levels[$level] > $this->_threshold)) {
        return FALSE;
    }

    $filepath = $this->_log_path . 'log-' . date('Y-m-d') . '.php';
    $message = '';

    // Add a PHP header to the log file if it doesn't exist
    if (!file_exists($filepath)) {
        $message .= "No direct script access allowed