/* Enjoy!!! Dino Ciuffetti - dam2k@users.sourceforge.net
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program (COPYING); if not, go to http://www.fsf.org/ or write
* to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/**
* This class handles cmsdAm logging. cmsdAm uses a log file for now, in future we'll use syslog
* logging, socket, database, ecc.
* Class instance: $cms->logs
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
class cmsdam_logs
{
/**
* You should not use this variable from your section.
* Configuration class instance.
* @access private
*/
var $conf;
/**
* You should not use this variable from your section.
* HTTP class instance.
* @access private
*/
var $http;
/**
* You should not use this variable from your section.
* Debug class instance.
* @access private
*/
var $debug;
/* LOGS */
/**
* This method open a filedescriptor for writing on the log file and writes a row.
* You can use "$level" to define the log priority. The higher the number, the lower
* the priority.
* @param int level The logging level
* @param str text The line to log
* @return bool False on errors, True on success
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function log_note ($level, $text)
{ /* This method open a filedescriptor for writing on the log file and writes a row.
$level is the log level for that string
$text is the string to be written
If $level > $LOG_level this method doesn't write nothing and returns true
If $text is empty this method doesn't write nothing and returns true
It returns the bytes written on success and false on error.
*/
$client_ip = $this->http->client_ip;
$LOG_path = $this->conf->LOG_path;
$LOG_file = $this->conf->LOG_file;
$LOG_level = $this->conf->LOG_level;
// Some checks
if ($LOG_level <= 0) { // Logging is deactivated
return true;
}
if ($level > $LOG_level) { // Logging is deactivated
return true;
}
if (($text == null) || strlen($text) == 0) { // $text is empty
return true;
}
$this->debug->debug_write(9, "log_note: " . $LOG_path . "/" . $LOG_file);
// Open the log file descriptor in append mode
$LOG_FD = @fopen ($LOG_path . "/" . $LOG_file, 'a');
if ($LOG_FD == false) {
$this->debug->debug_write(3, "log_note: Error opening logging file descriptor");
return false;
}
// Format the date
$format = date("D M j G:i:s T Y");
$format .= " - $client_ip - " . session_id() . " - Level: $level";
$write = @fwrite ($LOG_FD, $format . " - " . $text . "\n", 512);
@fflush($LOG_FD);
if ($write != -1) { // Write $text to the log file
fclose ($LOG_FD);
return false;
}
fclose ($LOG_FD);
return $write;
}
}
?>