-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMY_Log.php
More file actions
131 lines (107 loc) · 3.75 KB
/
Copy pathMY_Log.php
File metadata and controls
131 lines (107 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/**
* Vpx Log
*
* Extends core Log Class
*
* @author Liaan vd Merwe <info@vpx.co.za>
* @version 1.0
*
*/
class MY_log extends CI_Log {
function __construct()
{
parent::__construct();
}
/**
* Write Log File
*
* Generally this function will be called using the global log_message() function
*
* @param string $level The error level: 'error', 'debug' or 'info'
* @param string $msg The error message
* @return bool
*/
public function write_log($level, $msg)
{
if ($this->_enabled === FALSE)
{
return FALSE;
}
$level = strtoupper($level);
if ((!isset($this->_levels[$level]) OR ( $this->_levels[$level] > $this->_threshold)) && !isset($this->_threshold_array[$this->_levels[$level]]))
{
return FALSE;
}
$filepath = $this->_log_path . 'log-' . date('Y-m-d') . '.' . $this->_file_ext;
$message = '';
if (!file_exists($filepath))
{
$newfile = TRUE;
// Only add protection to php files
if ($this->_file_ext === 'php')
{
$message .= "<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>\n\n";
}
}
if (!$fp = @fopen($filepath, 'ab'))
{
return FALSE;
}
flock($fp, LOCK_EX);
// Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format
if (strpos($this->_date_fmt, 'u') !== FALSE)
{
$microtime_full = microtime(TRUE);
$microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000);
$date = new DateTime(date('Y-m-d H:i:s.' . $microtime_short, $microtime_full));
$date = $date->format($this->_date_fmt);
} else
{
$date = date($this->_date_fmt);
}
$message .= $this->_format_line($level, $date, $msg);
for ($written = 0, $length = self::strlen($message); $written < $length; $written += $result)
{
if (($result = fwrite($fp, self::substr($message, $written))) === FALSE)
{
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
if (isset($newfile) && $newfile === TRUE)
{
chmod($filepath, $this->_file_permissions);
}
if (function_exists('mail'))
{
##Email mesasge as well, will slow down server if lots of debugging is happening so make sure to enable emails only on production
$config = & get_config();
if (isset($config['log_email']) and $config['log_email'])
{
if (!isset($config['log_email_to_address']))
{
show_error('To email not set for email logs');
}
if (!isset($config['log_email_from_address']))
{
show_error('From email not set for email logs');
}
if (!isset($config['log_email_subject']))
{
show_error('Email subject not set');
}
$headers = 'From: ' . $config['log_email_from_name'] . ' <' . $config['log_email_from_address'] . ">\r\n";
$message .= "\r\n". print_r($_SERVER,true);
//$mail = new PHPMailer(true);
mail($config['log_email_to_address'], "Codeigniter Error", $message, $headers);
}
}
return is_int($result);
}
}
/* End of file Vpx_Output.php */
/* Location: ./application/models/Vpx_Output.php */