*
PANIC 0
* ERROR 1
* WARNING 2
* NOTICE 3
* DEBUG_USER 4
* DEBUG_IGEP 5
*
*
* @version $Id: IgepDebug.php,v 1.39 2010-05-26 10:30:54 afelixf Exp $
* @author Toni:
* @package gvHIDRA
*/
class IgepDebug{
static function setDebug($tipo,$mensaje){
if (!is_numeric($tipo))
throw new Exception('IgepDebug: el tipo de mensaje no está definido: '.$tipo);
include_once "IgepConstants.php";
$configuration = ConfigFramework::getConfig();
$debug = $configuration->getLogStatus();
//Comprobamos si tenemos que insertar
if($tipo>=$debug)
return;
//Obtenemos los datos
$aplicacion = IgepSession::dameAplicacion();
$modulo = '';
$version = $configuration->getAppVersion();
if (strlen($version) > 10)
$version = substr($version,-10);
$usuario = IgepSession::dameUsuario();
if (empty($usuario)) {
$usuario = $_SERVER['REMOTE_ADDR'];
if (empty($usuario))
$usuario = 'UNKNOWN';
if (class_exists('IgepWS_Server')) {
$login_cred = IgepWS_Server::getUsername();
if (!is_null($login_cred))
$usuario = strtoupper($login_cred).'@'.$usuario;
}
}
//reemplazamos caracter octal 0 con string \000 (relacionados con serialización de objetos)
$mensaje = str_replace("\000",'\\000',$mensaje);
//Realizamos la insercion
IgepDebug::_setDB($tipo, $mensaje, $aplicacion, $modulo, $version, $usuario);
}
static function _setDB($tipo, $mensaje, $aplicacion, $modulo, $version, $usuario){
// variable static para controlar el acceso exclusivo al metodo, y avitar asi bucles
// infinitos provocados por los propios errores dentro del metodo
static $excl = false;
static $conexion=null;
static $ins_prepared=null;
static $horabd=null;
include_once "IgepConexion.php";
$conf = ConfigFramework::getConfig();
$dsn_log = $conf->getDSNLog();
if(empty($dsn_log))
return;
//Conexion persistente para el log
$conexion = $conf->getLogConnection();
if(!is_object($conexion->obj_conexion)) {
if ($excl === true) {
$excl = false;
throw new Exception('Error de acceso a BD en debug: '.$mensaje);
}
$conexion = new IgepConexion($dsn_log,true);
$conf->setLogConnection($conexion);
}
$excl = true;
if (PEAR::isError($conexion->obj_conexion))
throw new Exception('Error de conexión al debug: '.$conexion->obj_conexion->userinfo);
//Obtenemos la fecha en el formato que admita la BD
$fechabd = IgepDB::mascaraFechas($dsn_log);
if (is_null($horabd))
$horabd = $conf->getTimeMask();
$fecha = date($fechabd.' '.$horabd);
if (IgepDB::obtenerDBMS($dsn_log)=='mysql') {
$iderror = 'null';
} else {
$sql = IgepDB::obtenerSecuenciaBD($dsn_log,'scmn_id_errlog');
$res = $conexion->obj_conexion->query($sql);
if (PEAR::isError($res)) {
$excl = false;
throw new Exception('Error al obtener secuencia de scmn_id_errlog: '.$res->userinfo);
}
$iderror = $res->fetchOne('nextval');
}
$conexion->obj_conexion->beginTransaction();
if (empty($ins_prepared)) {
$ins = "INSERT INTO tcmn_errlog (iderror,aplicacion,modulo,version,usuario,fecha,tipo,mensaje) values(?,?,null,?,?,?,?,?)";
$ins_prepared = $conexion->obj_conexion->prepare($ins, array('integer','text','text','text','text','text','text'));
if (PEAR::isError($ins_prepared)) {
$excl = false;
$prep = $ins_prepared;
$ins_prepared = null;
$conexion->obj_conexion->rollback();
throw new Exception('Error preparando inserción en tcmn_errlog: '.$prep->userinfo);
}
}
$res = $ins_prepared->execute(array($iderror,$aplicacion,$version,$usuario,$fecha, $tipo, $mensaje));
$excl = false;
if (PEAR::isError($res)) {
$conexion->obj_conexion->rollback();
throw new Exception('Error al insertar en tcmn_errlog: '.$res->userinfo);
}
$conexion->obj_conexion->commit();
}
}
?>