2 /*-------------------------------------------------------------------------
3 dbg.php - Dbg class implementation
5 Copyright (C) 2012 Borut Razem <borut.razem AT gmail.com>
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 -------------------------------------------------------------------------*/
28 private function d($s)
31 echo($s . "<br />\n");
35 public function __construct($fname = null, $do_append = false, $do_debug = true)
39 if ($fname !== null) {
46 if (!($this->fh
= fopen($fname, $mode))) {
47 echo('Can\'t create ' . $fname . "\n");
50 $this->debug
= $do_debug;
52 $this->begin_time
= time();
54 $this->dbg('--- Begin ' . date('Y-m-d H:i:s', $this->begin_time
) . ' ---');
57 public function set_debug($val)
64 public function dbg($s)
70 fwrite($this->fh
, $s . "\n");
73 echo($s . "<br />\n");
78 public function dbg_r($s)
84 fwrite($this->fh
, print_r($s, true) . "\n");
93 public function __destruct()
98 $this->dbg('--- End: ' . date('Y-m-d H:i:s', $end_time) .
99 ', Duration: ' . ($end_time - $this->begin_time
) . 's ---');