3 * XMPPHP: The PHP XMPP Library
4 * Copyright (C) 2008 Nathanael C. Fritz
5 * This file is part of SleekXMPP.
7 * XMPPHP is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * XMPPHP 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 XMPPHP; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
24 * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
25 * @author Michael Garvin <JID: gar@netflint.net>
26 * @copyright 2008 Nathanael C. Fritz
33 * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
34 * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
35 * @author Michael Garvin <JID: gar@netflint.net>
36 * @copyright 2008 Nathanael C. Fritz
41 const LEVEL_ERROR = 0;
42 const LEVEL_WARNING = 1;
44 const LEVEL_DEBUG = 3;
45 const LEVEL_VERBOSE = 4;
50 protected $data = array();
55 protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');
70 * @param boolean $printout
71 * @param string $runlevel
73 public function __construct($printout = false, $runlevel = self::LEVEL_INFO) {
74 $this->printout = (boolean)$printout;
75 $this->runlevel = (int)$runlevel;
79 * Add a message to the log data array
80 * If printout in this instance is set to true, directly output the message
83 * @param integer $runlevel
85 public function log($msg, $runlevel = self::LEVEL_INFO) {
87 #$this->data[] = array($this->runlevel, $msg, $time);
88 if($this->printout and $runlevel <= $this->runlevel) {
89 $this->writeLine($msg, $runlevel, $time);
94 * Output the complete log.
95 * Log will be cleared if $clear = true
97 * @param boolean $clear
98 * @param integer $runlevel
100 public function printout($clear = true, $runlevel = null) {
101 if($runlevel === null) {
102 $runlevel = $this->runlevel;
104 foreach($this->data as $data) {
105 if($runlevel <= $data[0]) {
106 $this->writeLine($data[1], $runlevel, $data[2]);
110 $this->data = array();
114 protected function writeLine($msg, $runlevel, $time) {
115 //echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n";
116 echo $time." [".$this->names[$runlevel]."]: ".$msg."\n";