*
PANIC 0
* ERROR 1
* WARNING 2
* NOTICE 3
* DEBUG_USER 4
* DEBUG_IGEP 5
*
*
* @version $Id: IgepDebug.php,v 1.23.2.4 2009-07-02 10:28:06 gaspar Exp $
* @author Toni:
* @package igep
*/
class IgepDebug{
static function setDebug($tipo,$mensaje){
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();
$usuario = IgepSession::dameUsuario();
if (empty($usuario))
$usuario = $_SERVER['REMOTE_ADDR'];
//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;
include_once "IgepConexion.php";
$conf = ConfigFramework::getConfig();
$dsn_log = $conf->getDSN('gvh_dsn_log');
if(empty($dsn_log))
return;
if ($excl === true) {
$excl = false;
throw new Exception('Error de acceso a BD en debug: '.$mensaje);
}
$excl = true;
$conexion = new IgepConexion($dsn_log);
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);
$fecha = date($fechabd.' H:i:s');
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->prepararOperacion($mensaje);
$conexion->obj_conexion->beginTransaction();
$res = $conexion->obj_conexion->exec("INSERT INTO tcmn_errlog (iderror,aplicacion,modulo,version,usuario,fecha,tipo,mensaje) values($iderror,'".$aplicacion."',null,'".$version."','".$usuario."','".$fecha."','".$tipo."','".$mensaje."')");
$excl = false;
if (PEAR::isError($res))
throw new Exception('Error al insertar en tcmn_errlog: '.$res->userinfo);
$conexion->obj_conexion->commit();
unset($conexion);
}
}
?>