fork download
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3.  * CodeIgniter
  4.  *
  5.  * An open source application development framework for PHP 5.1.6 or newer
  6.  *
  7.  * @package CodeIgniter
  8.  * @author ExpressionEngine Dev Team
  9.  * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10.  * @license http://c...content-available-to-author-only...r.com/user_guide/license.html
  11.  * @link http://c...content-available-to-author-only...r.com
  12.  * @since Version 1.0
  13.  * @filesource
  14.  */
  15.  
  16. // ------------------------------------------------------------------------
  17.  
  18. /**
  19.  * Logging Class
  20.  *
  21.  * @package CodeIgniter
  22.  * @subpackage Libraries
  23.  * @category Logging
  24.  * @author ExpressionEngine Dev Team
  25.  * @link http://c...content-available-to-author-only...r.com/user_guide/general/errors.html
  26.  */
  27. class CI_Log {
  28.  
  29. protected $_log_path;
  30. protected $_threshold = 1;
  31. protected $_date_fmt = 'Y-m-d H:i:s';
  32. protected $_enabled = TRUE;
  33. protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4');
  34.  
  35. /**
  36. * Constructor
  37. */
  38. public function __construct()
  39. {
  40. $config =& get_config();
  41.  
  42. $this->session->set('username','Raja');
  43.  
  44. echo $this->session->get('username');
  45.  
  46. $this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
  47.  
  48. if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
  49. {
  50. $this->_enabled = FALSE;
  51. }
  52.  
  53. if (is_numeric($config['log_threshold']))
  54. {
  55. $this->_threshold = $config['log_threshold'];
  56. }
  57.  
  58. if ($config['log_date_format'] != '')
  59. {
  60. $this->_date_fmt = $config['log_date_format'];
  61. }
  62. }
  63.  
  64. // --------------------------------------------------------------------
  65.  
  66. /**
  67. * Write Log File
  68. *
  69. * Generally this function will be called using the global log_message() function
  70. *
  71. * @param string the error level
  72. * @param string the error message
  73. * @param bool whether the error is a native PHP error
  74. * @return bool
  75. */
  76. public function write_log($level = 'error', $msg, $php_error = FALSE)
  77. {
  78. if ($this->_enabled === FALSE)
  79. {
  80. return FALSE;
  81. }
  82.  
  83. $level = strtoupper($level);
  84.  
  85. if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
  86. {
  87. return FALSE;
  88. }
  89.  
  90. $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
  91. $message = '';
  92.  
  93. if ( ! file_exists($filepath))
  94. {
  95. $message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
  96. }
  97.  
  98. if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
  99. {
  100. return FALSE;
  101. }
  102.  
  103. $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
  104.  
  105. flock($fp, LOCK_EX);
  106. fwrite($fp, $message);
  107. flock($fp, LOCK_UN);
  108. fclose($fp);
  109.  
  110. @chmod($filepath, FILE_WRITE_MODE);
  111. return TRUE;
  112. }
  113.  
  114. }
  115. // END Log Class
  116.  
  117. /* End of file Log.php */
  118. /* Location: ./system/libraries/Log.php */
Success #stdin #stdout 0.02s 25836KB
stdin
Standard input is empty
stdout
No direct script access allowed