pcltrace.lib.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <?
  2. // --------------------------------------------------------------------------------
  3. // PhpConcept Library (PCL) Trace 1.0
  4. // --------------------------------------------------------------------------------
  5. // License GNU/GPL - Vincent Blavet - Janvier 2001
  6. // http://www.phpconcept.net & http://phpconcept.free.fr
  7. // --------------------------------------------------------------------------------
  8. // Français :
  9. // La description de l'usage de la librairie PCL Trace 1.0 n'est pas encore
  10. // disponible. Celle-ci n'est pour le moment distribuée qu'avec l'application
  11. // et la librairie PhpZip.
  12. // Une version indépendante sera bientot disponible sur http://www.phpconcept.net
  13. //
  14. // English :
  15. // The PCL Trace 1.0 library description is not available yet. This library is
  16. // released only with PhpZip application and library.
  17. // An independant release will be soon available on http://www.phpconcept.net
  18. //
  19. // --------------------------------------------------------------------------------
  20. //
  21. // * Avertissement :
  22. //
  23. // Cette librairie a été créée de façon non professionnelle.
  24. // Son usage est au risque et péril de celui qui l'utilise, en aucun cas l'auteur
  25. // de ce code ne pourra être tenu pour responsable des éventuels dégats qu'il pourrait
  26. // engendrer.
  27. // Il est entendu cependant que l'auteur a réalisé ce code par plaisir et n'y a
  28. // caché aucun virus, ni malveillance.
  29. // Cette libairie est distribuée sous la license GNU/GPL (http://www.gnu.org)
  30. //
  31. // * Auteur :
  32. //
  33. // Ce code a été écrit par Vincent Blavet (vincent@blavet.net) sur son temps
  34. // de loisir.
  35. //
  36. // --------------------------------------------------------------------------------
  37. // ----- Look for double include
  38. if (!defined("PCLTRACE_LIB"))
  39. {
  40. define( "PCLTRACE_LIB", 1 );
  41. // ----- Version
  42. $g_pcl_trace_version = "1.0";
  43. // ----- Internal variables
  44. // These values must be change by PclTrace library functions
  45. $g_pcl_trace_mode = "memory";
  46. $g_pcl_trace_filename = "trace.txt";
  47. $g_pcl_trace_name = array();
  48. $g_pcl_trace_index = 0;
  49. $g_pcl_trace_level = 0;
  50. //$g_pcl_trace_entries = array();
  51. // --------------------------------------------------------------------------------
  52. // Function : TrOn($p_level, $p_mode, $p_filename)
  53. // Description :
  54. // Parameters :
  55. // $p_level : Trace level
  56. // $p_mode : Mode of trace displaying :
  57. // 'normal' : messages are displayed at function call
  58. // 'memory' : messages are memorized in a table and can be display by
  59. // TrDisplay() function. (default)
  60. // 'log' : messages are writed in the file $p_filename
  61. // --------------------------------------------------------------------------------
  62. function TrOn($p_level=1, $p_mode="memory", $p_filename="trace.txt")
  63. {
  64. global $g_pcl_trace_level;
  65. global $g_pcl_trace_mode;
  66. global $g_pcl_trace_filename;
  67. global $g_pcl_trace_name;
  68. global $g_pcl_trace_index;
  69. global $g_pcl_trace_entries;
  70. // ----- Enable trace mode
  71. $g_pcl_trace_level = $p_level;
  72. // ----- Memorize mode and filename
  73. switch ($p_mode) {
  74. case "normal" :
  75. case "memory" :
  76. case "log" :
  77. $g_pcl_trace_mode = $p_mode;
  78. break;
  79. default :
  80. $g_pcl_trace_mode = "logged";
  81. }
  82. // ----- Memorize filename
  83. $g_pcl_trace_filename = $p_filename;
  84. }
  85. // --------------------------------------------------------------------------------
  86. // --------------------------------------------------------------------------------
  87. // Function : IsTrOn()
  88. // Description :
  89. // Return value :
  90. // The trace level (0 for disable).
  91. // --------------------------------------------------------------------------------
  92. function IsTrOn()
  93. {
  94. global $g_pcl_trace_level;
  95. return($g_pcl_trace_level);
  96. }
  97. // --------------------------------------------------------------------------------
  98. // --------------------------------------------------------------------------------
  99. // Function : TrOff()
  100. // Description :
  101. // Parameters :
  102. // --------------------------------------------------------------------------------
  103. function TrOff()
  104. {
  105. global $g_pcl_trace_level;
  106. global $g_pcl_trace_mode;
  107. global $g_pcl_trace_filename;
  108. global $g_pcl_trace_name;
  109. global $g_pcl_trace_index;
  110. // ----- Clean
  111. $g_pcl_trace_mode = "memory";
  112. unset($g_pcl_trace_entries);
  113. unset($g_pcl_trace_name);
  114. unset($g_pcl_trace_index);
  115. // ----- Switch off trace
  116. $g_pcl_trace_level = 0;
  117. }
  118. // --------------------------------------------------------------------------------
  119. // --------------------------------------------------------------------------------
  120. // Function : TrFctStart()
  121. // Description :
  122. // Just a trace function for debbugging purpose before I use a better tool !!!!
  123. // Start and stop of this function is by $g_pcl_trace_level global variable.
  124. // Parameters :
  125. // $p_level : Level of trace required.
  126. // --------------------------------------------------------------------------------
  127. function TrFctStart($p_file, $p_line, $p_name, $p_param="", $p_message="")
  128. {
  129. global $g_pcl_trace_level;
  130. global $g_pcl_trace_mode;
  131. global $g_pcl_trace_filename;
  132. global $g_pcl_trace_name;
  133. global $g_pcl_trace_index;
  134. global $g_pcl_trace_entries;
  135. // ----- Look for disabled trace
  136. if ($g_pcl_trace_level < 1)
  137. return;
  138. // ----- Add the function name in the list
  139. if (!isset($g_pcl_trace_name))
  140. $g_pcl_trace_name = $p_name;
  141. else
  142. $g_pcl_trace_name .= ",".$p_name;
  143. // ----- Update the function entry
  144. $i = sizeof($g_pcl_trace_entries);
  145. $g_pcl_trace_entries[$i][name] = $p_name;
  146. $g_pcl_trace_entries[$i][param] = $p_param;
  147. $g_pcl_trace_entries[$i][message] = "";
  148. $g_pcl_trace_entries[$i][file] = $p_file;
  149. $g_pcl_trace_entries[$i][line] = $p_line;
  150. $g_pcl_trace_entries[$i][index] = $g_pcl_trace_index;
  151. $g_pcl_trace_entries[$i][type] = "1"; // means start of function
  152. // ----- Update the message entry
  153. if ($p_message != "")
  154. {
  155. $i = sizeof($g_pcl_trace_entries);
  156. $g_pcl_trace_entries[$i][name] = "";
  157. $g_pcl_trace_entries[$i][param] = "";
  158. $g_pcl_trace_entries[$i][message] = $p_message;
  159. $g_pcl_trace_entries[$i][file] = $p_file;
  160. $g_pcl_trace_entries[$i][line] = $p_line;
  161. $g_pcl_trace_entries[$i][index] = $g_pcl_trace_index;
  162. $g_pcl_trace_entries[$i][type] = "3"; // means message
  163. }
  164. // ----- Action depending on mode
  165. PclTraceAction($g_pcl_trace_entries[$i]);
  166. // ----- Increment the index
  167. $g_pcl_trace_index++;
  168. }
  169. // --------------------------------------------------------------------------------
  170. // --------------------------------------------------------------------------------
  171. // Function : TrFctEnd()
  172. // Description :
  173. // Just a trace function for debbugging purpose before I use a better tool !!!!
  174. // Start and stop of this function is by $g_pcl_trace_level global variable.
  175. // Parameters :
  176. // $p_level : Level of trace required.
  177. // --------------------------------------------------------------------------------
  178. function TrFctEnd($p_file, $p_line, $p_return=1, $p_message="")
  179. {
  180. global $g_pcl_trace_level;
  181. global $g_pcl_trace_mode;
  182. global $g_pcl_trace_filename;
  183. global $g_pcl_trace_name;
  184. global $g_pcl_trace_index;
  185. global $g_pcl_trace_entries;
  186. // ----- Look for disabled trace
  187. if ($g_pcl_trace_level < 1)
  188. return;
  189. // ----- Extract the function name in the list
  190. // ----- Remove the function name in the list
  191. if (!($v_name = strrchr($g_pcl_trace_name, ",")))
  192. {
  193. $v_name = $g_pcl_trace_name;
  194. $g_pcl_trace_name = "";
  195. }
  196. else
  197. {
  198. $g_pcl_trace_name = substr($g_pcl_trace_name, 0, strlen($g_pcl_trace_name)-strlen($v_name));
  199. $v_name = substr($v_name, -strlen($v_name)+1);
  200. }
  201. // ----- Decrement the index
  202. $g_pcl_trace_index--;
  203. // ----- Update the message entry
  204. if ($p_message != "")
  205. {
  206. $i = sizeof($g_pcl_trace_entries);
  207. $g_pcl_trace_entries[$i][name] = "";
  208. $g_pcl_trace_entries[$i][param] = "";
  209. $g_pcl_trace_entries[$i][message] = $p_message;
  210. $g_pcl_trace_entries[$i][file] = $p_file;
  211. $g_pcl_trace_entries[$i][line] = $p_line;
  212. $g_pcl_trace_entries[$i][index] = $g_pcl_trace_index;
  213. $g_pcl_trace_entries[$i][type] = "3"; // means message
  214. }
  215. // ----- Update the function entry
  216. $i = sizeof($g_pcl_trace_entries);
  217. $g_pcl_trace_entries[$i][name] = $v_name;
  218. $g_pcl_trace_entries[$i][param] = $p_return;
  219. $g_pcl_trace_entries[$i][message] = "";
  220. $g_pcl_trace_entries[$i][file] = $p_file;
  221. $g_pcl_trace_entries[$i][line] = $p_line;
  222. $g_pcl_trace_entries[$i][index] = $g_pcl_trace_index;
  223. $g_pcl_trace_entries[$i][type] = "2"; // means end of function
  224. // ----- Action depending on mode
  225. PclTraceAction($g_pcl_trace_entries[$i]);
  226. }
  227. // --------------------------------------------------------------------------------
  228. // --------------------------------------------------------------------------------
  229. // Function : TrFctMessage()
  230. // Description :
  231. // Parameters :
  232. // --------------------------------------------------------------------------------
  233. function TrFctMessage($p_file, $p_line, $p_level, $p_message="")
  234. {
  235. global $g_pcl_trace_level;
  236. global $g_pcl_trace_mode;
  237. global $g_pcl_trace_filename;
  238. global $g_pcl_trace_name;
  239. global $g_pcl_trace_index;
  240. global $g_pcl_trace_entries;
  241. // ----- Look for disabled trace
  242. if ($g_pcl_trace_level < $p_level)
  243. return;
  244. // ----- Update the entry
  245. $i = sizeof($g_pcl_trace_entries);
  246. $g_pcl_trace_entries[$i][name] = "";
  247. $g_pcl_trace_entries[$i][param] = "";
  248. $g_pcl_trace_entries[$i][message] = $p_message;
  249. $g_pcl_trace_entries[$i][file] = $p_file;
  250. $g_pcl_trace_entries[$i][line] = $p_line;
  251. $g_pcl_trace_entries[$i][index] = $g_pcl_trace_index;
  252. $g_pcl_trace_entries[$i][type] = "3"; // means message of function
  253. // ----- Action depending on mode
  254. PclTraceAction($g_pcl_trace_entries[$i]);
  255. }
  256. // --------------------------------------------------------------------------------
  257. // --------------------------------------------------------------------------------
  258. // Function : TrMessage()
  259. // Description :
  260. // Parameters :
  261. // --------------------------------------------------------------------------------
  262. function TrMessage($p_file, $p_line, $p_level, $p_message="")
  263. {
  264. global $g_pcl_trace_level;
  265. global $g_pcl_trace_mode;
  266. global $g_pcl_trace_filename;
  267. global $g_pcl_trace_name;
  268. global $g_pcl_trace_index;
  269. global $g_pcl_trace_entries;
  270. // ----- Look for disabled trace
  271. if ($g_pcl_trace_level < $p_level)
  272. return;
  273. // ----- Update the entry
  274. $i = sizeof($g_pcl_trace_entries);
  275. $g_pcl_trace_entries[$i][name] = "";
  276. $g_pcl_trace_entries[$i][param] = "";
  277. $g_pcl_trace_entries[$i][message] = $p_message;
  278. $g_pcl_trace_entries[$i][file] = $p_file;
  279. $g_pcl_trace_entries[$i][line] = $p_line;
  280. $g_pcl_trace_entries[$i][index] = $g_pcl_trace_index;
  281. $g_pcl_trace_entries[$i][type] = "4"; // means simple message
  282. // ----- Action depending on mode
  283. PclTraceAction($g_pcl_trace_entries[$i]);
  284. }
  285. // --------------------------------------------------------------------------------
  286. // --------------------------------------------------------------------------------
  287. // Function : TrDisplay()
  288. // Description :
  289. // Parameters :
  290. // --------------------------------------------------------------------------------
  291. function TrDisplay()
  292. {
  293. global $g_pcl_trace_level;
  294. global $g_pcl_trace_mode;
  295. global $g_pcl_trace_filename;
  296. global $g_pcl_trace_name;
  297. global $g_pcl_trace_index;
  298. global $g_pcl_trace_entries;
  299. // ----- Look for disabled trace
  300. if (($g_pcl_trace_level <= 0) || ($g_pcl_trace_mode != "memory"))
  301. return;
  302. $v_font = "\"Verdana, Arial, Helvetica, sans-serif\"";
  303. // ----- Trace Header
  304. echo "<table width=100% border=0 cellspacing=0 cellpadding=0>";
  305. echo "<tr bgcolor=#0000CC>";
  306. echo "<td bgcolor=#0000CC width=1>";
  307. echo "</td>";
  308. echo "<td><div align=center><font size=3 color=#FFFFFF face=$v_font>Trace</font></div></td>";
  309. echo "</tr>";
  310. echo "<tr>";
  311. echo "<td bgcolor=#0000CC width=1>";
  312. echo "</td>";
  313. echo "<td>";
  314. // ----- Content header
  315. echo "<table width=100% border=0 cellspacing=0 cellpadding=0>";
  316. // ----- Display
  317. $v_again=0;
  318. for ($i=0; $i<sizeof($g_pcl_trace_entries); $i++)
  319. {
  320. // ---- Row header
  321. echo "<tr>";
  322. echo "<td><table width=100% border=0 cellspacing=0 cellpadding=0><tr>";
  323. $n = ($g_pcl_trace_entries[$i][index]+1)*10;
  324. echo "<td width=".$n."><table width=100% border=0 cellspacing=0 cellpadding=0><tr>";
  325. for ($j=0; $j<=$g_pcl_trace_entries[$i][index]; $j++)
  326. {
  327. if ($j==$g_pcl_trace_entries[$i][index])
  328. {
  329. if (($g_pcl_trace_entries[$i][type] == 1) || ($g_pcl_trace_entries[$i][type] == 2))
  330. echo "<td width=10><div align=center><font size=2 face=$v_font>+</font></div></td>";
  331. }
  332. else
  333. echo "<td width=10><div align=center><font size=2 face=$v_font>|</font></div></td>";
  334. }
  335. //echo "<td>&nbsp</td>";
  336. echo "</tr></table></td>";
  337. echo "<td width=2></td>";
  338. switch ($g_pcl_trace_entries[$i][type]) {
  339. case 1:
  340. echo "<td><font size=2 face=$v_font>".$g_pcl_trace_entries[$i][name]."(".$g_pcl_trace_entries[$i][param].")</font></td>";
  341. break;
  342. case 2:
  343. echo "<td><font size=2 face=$v_font>".$g_pcl_trace_entries[$i][name]."()=".$g_pcl_trace_entries[$i][param]."</font></td>";
  344. break;
  345. case 3:
  346. case 4:
  347. echo "<td><table width=100% border=0 cellspacing=0 cellpadding=0><td width=20></td><td>";
  348. echo "<font size=2 face=$v_font>".$g_pcl_trace_entries[$i][message]."</font>";
  349. echo "</td></table></td>";
  350. break;
  351. default:
  352. echo "<td><font size=2 face=$v_font>".$g_pcl_trace_entries[$i][name]."(".$g_pcl_trace_entries[$i][param].")</font></td>";
  353. }
  354. echo "</tr></table></td>";
  355. echo "<td width=5></td>";
  356. echo "<td><font size=1 face=$v_font>".basename($g_pcl_trace_entries[$i][file])."</font></td>";
  357. echo "<td width=5></td>";
  358. echo "<td><font size=1 face=$v_font>".$g_pcl_trace_entries[$i][line]."</font></td>";
  359. echo "</tr>";
  360. }
  361. // ----- Content footer
  362. echo "</table>";
  363. // ----- Trace footer
  364. echo "</td>";
  365. echo "<td bgcolor=#0000CC width=1>";
  366. echo "</td>";
  367. echo "</tr>";
  368. echo "<tr bgcolor=#0000CC>";
  369. echo "<td bgcolor=#0000CC width=1>";
  370. echo "</td>";
  371. echo "<td><div align=center><font color=#FFFFFF face=$v_font>&nbsp</font></div></td>";
  372. echo "</tr>";
  373. echo "</table>";
  374. }
  375. // --------------------------------------------------------------------------------
  376. // --------------------------------------------------------------------------------
  377. // Function : PclTraceAction()
  378. // Description :
  379. // Parameters :
  380. // --------------------------------------------------------------------------------
  381. function PclTraceAction($p_entry)
  382. {
  383. global $g_pcl_trace_level;
  384. global $g_pcl_trace_mode;
  385. global $g_pcl_trace_filename;
  386. global $g_pcl_trace_name;
  387. global $g_pcl_trace_index;
  388. global $g_pcl_trace_entries;
  389. if ($g_pcl_trace_mode == "normal")
  390. {
  391. for ($i=0; $i<$p_entry[index]; $i++)
  392. echo "---";
  393. if ($p_entry[type] == 1)
  394. echo "<b>".$p_entry[name]."</b>(".$p_entry[param].") : ".$p_entry[message]." [".$p_entry[file].", ".$p_entry[line]."]<br>";
  395. else if ($p_entry[type] == 2)
  396. echo "<b>".$p_entry[name]."</b>()=".$p_entry[param]." : ".$p_entry[message]." [".$p_entry[file].", ".$p_entry[line]."]<br>";
  397. else
  398. echo $p_entry[message]." [".$p_entry[file].", ".$p_entry[line]."]<br>";
  399. }
  400. }
  401. // --------------------------------------------------------------------------------
  402. // ----- End of double include look
  403. }
  404. ?>