/[dtapublic]/to_be_filed/webprojs/php_libraries/php_library/general/log.inc
ViewVC logotype

Contents of /to_be_filed/webprojs/php_libraries/php_library/general/log.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations) (download)
Sat Oct 8 23:35:33 2016 UTC (7 years, 5 months ago) by dashley
File size: 5588 byte(s)
Initial commit.
1 <?php
2 //********************************************************************************
3 //Copyright (C)2006 David T. Ashley
4 //********************************************************************************
5 //This program or source file is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU General Public License as published by
7 //the Free Software Foundation; either version 2 of the License, or (at your
8 //option) any later version.
9 //
10 //This program or source file is distributed in the hope that it will
11 //be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 //GNU General Public License for more details.
14 //
15 //You may have received a copy of the GNU General Public License
16 //along with this program; if not, write to the Free Software
17 //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //********************************************************************************
19 //Dave Ashley, 01/06
20 //
21 //This source file is a wrapper for functions that emit information into the
22 //log files.
23 //
24 //Replaces unruly characters with the underscore.
25 //
26 function LOG_replace_unruly_chars($arg)
27 {
28 $allowed_chars = "abcdefghijklmnopqrstuvwxyz" .
29 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" .
30 "0123456789" .
31 " .,_:;-+*/";
32
33 $len = strlen($arg);
34 $rv = "";
35
36 for ($i = 0; $i < $len; $i++)
37 {
38 $c = substr($arg, $i, 1);
39
40 if (strpos($allowed_chars, $c) === FALSE)
41 {
42 //The character involved isn't in the allowed set. Replace it with an underscore.
43 $rv .= "_";
44 }
45 else
46 {
47 //The character involved is allowed. Put it directly in the result.
48 $rv .= $c;
49 }
50 }
51
52 return($rv);
53 }
54 //
55 //
56 //Writes the debug backtrace information to the log file.
57 //
58 function LOG_log_debug_backtrace($prefix)
59 {
60 //Grab backtrace.
61 $bt = debug_backtrace();
62
63 //Iterate through each element.
64 reset($bt);
65 $i=0;
66 while (list($key, $val) = each($bt))
67 {
68 //Spit the function name.
69 if (isset($val["function"]))
70 syslog(LOG_NOTICE, $prefix . "FUNCTION[" . sprintf("%02d", $i) . "]: " . $val["function"]);
71 else
72 syslog(LOG_NOTICE, $prefix . "No function name specified in traceback.");
73
74 //Spit the file name.
75 if (isset($val["file"]))
76 syslog(LOG_NOTICE, $prefix . "FILE [" . sprintf("%02d", $i) . "]: " . $val["file"]);
77 else
78 syslog(LOG_NOTICE, $prefix . "No file name specified in traceback.");
79
80 //Spit the line number.
81 if (isset($val["line"]))
82 syslog(LOG_NOTICE, $prefix . "LINE [" . sprintf("%02d", $i) . "]: " . $val["line"]);
83 else
84 syslog(LOG_NOTICE, $prefix . "No line number specified in traceback.");
85
86 $i++;
87 }
88 }
89 //
90 //
91 //Writes a horizontal line to the log file.
92 //
93 function LOG_log_hline($prefix)
94 {
95 $val = $prefix;
96
97 for ($i=0; $i<80; $i++)
98 {
99 $val .= "-";
100 }
101
102 error_log($val);
103 }
104 //
105 //Emits "hard" error messages. An "error" for these purposes is a very unexpected event,
106 //such as not being able to connect to a database, conditions that should not
107 //occur, etc. This includes a backtrace.
108 //
109 function LOG_error_hard($msgstring)
110 {
111 $prefix = "PAMC_ERROR_HARD: ";
112
113 //Sanitize the input string to allow only certain characters.
114 $msgstring = LOG_replace_unruly_chars($msgstring);
115
116 //Open with a horizontal line.
117 LOG_log_hline($prefix);
118
119 //Insert the message.
120 syslog(LOG_NOTICE, $prefix . $msgstring);
121
122 //Do the backtrace.
123 LOG_log_debug_backtrace($prefix);
124
125 //Close with a horizontal line.
126 LOG_log_hline($prefix);
127 }
128 //
129 //Emits "soft" error messages. An "error" for these purposes is a very unexpected event,
130 //such as not being able to connect to a database, conditions that should not
131 //occur, etc. This does not include a backtrace.
132 //
133 function LOG_error_soft($msgstring)
134 {
135 $prefix = "PAMC_ERROR_SOFT: ";
136
137 //Sanitize the input string to allow only certain characters.
138 $msgstring = LOG_replace_unruly_chars($msgstring);
139
140 //Insert the message.
141 syslog(LOG_NOTICE, $prefix . $msgstring);
142 }
143 //
144 //Emits security messages. An "security" message is something security-related.
145 //
146 function LOG_security($msgstring)
147 {
148 $prefix = "PAMC_SECURITY: ";
149
150 //Sanitize the input string to allow only certain characters.
151 $msgstring = LOG_replace_unruly_chars($msgstring);
152
153 //Insert the message.
154 syslog(LOG_NOTICE, $prefix . $msgstring);
155 }
156 //
157 //Emits alert messages. An "alert" message is something significant that one
158 //might want to look into.
159 //
160 function LOG_alert($msgstring)
161 {
162 $prefix = "PAMC_ALERT: ";
163
164 //Sanitize the input string to allow only certain characters.
165 $msgstring = LOG_replace_unruly_chars($msgstring);
166
167 //Insert the message.
168 syslog(LOG_NOTICE, $prefix . $msgstring);
169 }
170 //
171 //Emits informational messages. An "informational" message is just something ordinary
172 //that occurs.
173 //
174 function LOG_info($msgstring)
175 {
176 $prefix = "PAMC_INFO: ";
177
178 //Sanitize the input string to allow only certain characters.
179 $msgstring = LOG_replace_unruly_chars($msgstring);
180
181 //Insert the message.
182 syslog(LOG_NOTICE, $prefix . $msgstring);
183 }
184 ?>

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25