Ahora se capturan y envian todos los mensajes de error y advertencia al syslog

This commit is contained in:
Juan Ferrer Toribio 2015-08-28 02:44:34 +02:00
parent 929eb0972b
commit 39e436e275
10 changed files with 106 additions and 35 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.207-1) stable; urgency=low hedera-web (1.208-1) stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -10,4 +10,8 @@ if (!defined (__NAMESPACE__.'\_DEVELOPER_MODE'))
require_once (_CONFIG_DIR .'/config.php'); require_once (_CONFIG_DIR .'/config.php');
ini_set ('log_errors', TRUE);
ini_set ('error_log', 'syslog');
//ini_set ('error_log', _LOG_DIR .'/hedera-web.log');
?> ?>

View File

@ -19,9 +19,8 @@ class Tpv
{ {
global $conf; global $conf;
ini_set ('log_errors', TRUE); openlog ('hedera-web', LOG_ODELAY, LOG_LOCAL0);
ini_set ('error_log', Hedera\_LOG_DIR .'/hedera-web.log');
self::$conn = new Db\Conn (); self::$conn = new Db\Conn ();
self::$conn->open ( self::$conn->open (
$conf['db']['host'] $conf['db']['host']
@ -37,6 +36,7 @@ class Tpv
static function deinit () static function deinit ()
{ {
self::$conn->close (); self::$conn->close ();
closelog ();
} }
/** /**

View File

@ -1,5 +1,7 @@
<?php <?php
openlog ('hedera-web', LOG_ODELAY, LOG_LOCAL0);
require_once ('vn/hedera/web.php'); require_once ('vn/hedera/web.php');
require_once ('vn/hedera/js.php'); require_once ('vn/hedera/js.php');
require_once ('vn/hedera/util.php'); require_once ('vn/hedera/util.php');
@ -7,12 +9,10 @@ require_once ('vn/hedera/util.php');
use Vn\Hedera\Web; use Vn\Hedera\Web;
use Vn\Lib\Locale; use Vn\Lib\Locale;
ini_set ('log_errors', TRUE);
ini_set ('error_log', Vn\Hedera\_LOG_DIR .'/hedera-web.log');
function myExitHandler () function myExitHandler ()
{ {
Web::deinit (); Web::deinit ();
closelog ();
} }
function myGlobalErrorHandler () function myGlobalErrorHandler ()
@ -24,7 +24,7 @@ function myGlobalErrorHandler ()
function myErrorHandler ($errno, $message, $file, $line, $context) function myErrorHandler ($errno, $message, $file, $line, $context)
{ {
error_log ("$file:$line: $message"); error_log ("Error: $file($line): $message");
switch ($errno) switch ($errno)
{ {
@ -37,7 +37,12 @@ function myErrorHandler ($errno, $message, $file, $line, $context)
function myExceptionHandler ($e) function myExceptionHandler ($e)
{ {
error_log ($e->getFile () .':'. $e->getLine () .': '. $e->getMessage ()); error_log (sprintf ('Exception: %s(%d): %s. Trace: %s'
,$e->getFile ()
,$e->getLine ()
,$e->getMessage ()
,$e->getTraceAsString ()
));
myGlobalErrorHandler (); myGlobalErrorHandler ();
} }

View File

@ -180,6 +180,7 @@ Db.Conn.implement
*/ */
,execDone: function (httpRequest, callback, success) ,execDone: function (httpRequest, callback, success)
{ {
var e;
var error = null; var error = null;
var results = null; var results = null;
@ -189,7 +190,10 @@ Db.Conn.implement
this.signalEmit ('loading-changed', false); this.signalEmit ('loading-changed', false);
if (!success) if (!success)
error = new Vn.Error ('Http', 'connError', _('ConnError')); {
error = new Vn.Error ('Conn', 'connError', _('ConnError'));
this.signalEmit ('error', error);
}
else else
try { try {
var json = httpRequest.getJson (); var json = httpRequest.getJson ();
@ -231,17 +235,20 @@ Db.Conn.implement
} }
} }
} }
catch (e) { catch (e)
error = new Vn.Error ('Http', 'badReply', e.message); {
this.signalEmit ('error', e);
error = e;
} }
var errorHandled = false;
if (callback) if (callback)
errorHandled = callback (new Db.ResultSet (results, error)); try {
callback (new Db.ResultSet (results, error));
if (error && errorHandled != true) }
this.signalEmit ('error', error); catch (e)
{
this.signalEmit ('error', e);
}
} }
}); });

View File

@ -19,7 +19,7 @@ Vn.HttpRequest = new Class
,requestStateChanged: function (callback) ,requestStateChanged: function (callback)
{ {
if (this.request.readyState == 4) if (this.request.readyState == 4 && callback)
callback (this, this.request.status == 200); callback (this, this.request.status == 200);
} }

20
web/log.php Executable file
View File

@ -0,0 +1,20 @@
<?php
openlog ('hedera-web', LOG_ODELAY, LOG_LOCAL0);
require_once ('vn/hedera/init.php');
if (isset ($_REQUEST['file'])
&& isset ($_REQUEST['line'])
&& isset ($_REQUEST['message'])
&& isset ($_REQUEST['stack']))
error_log (sprintf ('Javascript: %s(%d): %s. Stack: %s'
,$_REQUEST['file']
,$_REQUEST['line']
,$_REQUEST['message']
,$_REQUEST['stack']
));
closeLog ();
?>

View File

@ -5,22 +5,22 @@
img img
{ {
position: absolute; position: absolute;
margin-top: -18em; margin-top: -200px;
margin-left: -18em; margin-left: -200px;
top: 50%; top: 50%;
left: 50%; left: 50%;
} }
#continue #continue
{ {
position: absolute; position: absolute;
bottom: 0px; bottom: 0;
left: 0px; left: 0;
right: 0px; right: 0;
margin: 15px; margin: 1em;
text-align: center; text-align: center;
} }
a a
{ {
color: #444; color: #444;
border-width: 0px; border-width: 0;
} }

View File

@ -14,6 +14,11 @@ Vn.Web =
,initialize: function () ,initialize: function ()
{ {
window.onerror = function (error, a, b, c, d)
{
this.errorHandler.bind (this, error);
}.bind (this);
this.loadingCount = 0; this.loadingCount = 0;
this.loader = $('loader'); this.loader = $('loader');
this.formHolder = $('form-holder'); this.formHolder = $('form-holder');
@ -157,8 +162,9 @@ Vn.Web =
this.onFormChange (); this.onFormChange ();
} }
,onConnError: function (conn, error) ,errorHandler: function (error)
{ {
if (error instanceof Vn.Error)
switch (error.domain) switch (error.domain)
{ {
case 'Auth': case 'Auth':
@ -172,9 +178,29 @@ Vn.Web =
Htk.Toast.showError (error.message); Htk.Toast.showError (error.message);
break; break;
default: default:
console.warn (error.message); console.error (error.message);
Htk.Toast.showError (_('InternalError')); Htk.Toast.showError (_('InternalError'));
} }
else
{
console.error (error);
Htk.Toast.showError (_('InternalError'));
var httpRequest = new Vn.HttpRequest ()
httpRequest.add
({
'file': error.fileName
,'line': error.lineNumber
,'message': error.message
,'stack': error.stack
});
httpRequest.send ('log.php');
}
}
,onConnError: function (conn, error)
{
this.errorHandler (error);
} }
,onConnLoading: function (conn, isLoading) ,onConnLoading: function (conn, isLoading)
@ -206,8 +232,10 @@ Vn.Web =
,newVersion: function (error) ,newVersion: function (error)
{ {
if (this.skipVersion) if (this.newVersionBlock || this.skipVersion)
return; return;
this.newVersionBlock = true;
var reload; var reload;
var message = _('NewVersionAvailable') +"\n\n"+ error.message; var message = _('NewVersionAvailable') +"\n\n"+ error.message;
@ -228,6 +256,8 @@ Vn.Web =
this.unload (); this.unload ();
location.reload (); location.reload ();
} }
this.newVersionBlock = false;
} }
,createMenu: function (res, sectionMap, parent, ul) ,createMenu: function (res, sectionMap, parent, ul)
@ -426,7 +456,7 @@ Vn.Web =
} }
catch (e) { catch (e) {
formInfo.error = true; formInfo.error = true;
console.error (e); this.errorHandler (error);
} }
} }
else else

View File

@ -1,5 +1,7 @@
<?php <?php
openlog ('hedera-web', LOG_ODELAY, LOG_LOCAL0);
require_once ('vn/hedera/web.php'); require_once ('vn/hedera/web.php');
require_once ('vn/rest/rest.php'); require_once ('vn/rest/rest.php');
@ -7,13 +9,11 @@ use Vn\Lib\Locale;
use Vn\Rest; use Vn\Rest;
use Vn\Hedera\Web; use Vn\Hedera\Web;
ini_set ('log_errors', TRUE);
ini_set ('error_log', Vn\Hedera\_LOG_DIR .'/hedera-web.log');
function myExitHandler () function myExitHandler ()
{ {
Web::deinit (); Web::deinit ();
Rest\Service::sendReply (); Rest\Service::sendReply ();
closelog ();
} }
function myGlobalErrorHandler () function myGlobalErrorHandler ()
@ -25,7 +25,7 @@ function myGlobalErrorHandler ()
function myErrorHandler ($errno, $message, $file, $line, $context) function myErrorHandler ($errno, $message, $file, $line, $context)
{ {
error_log ("$file:$line: $message"); error_log ("Error: $file($line): $message");
switch ($errno) switch ($errno)
{ {
@ -40,7 +40,12 @@ function myErrorHandler ($errno, $message, $file, $line, $context)
function myExceptionHandler ($e) function myExceptionHandler ($e)
{ {
error_log ($e->getFile () .':'. $e->getLine () .': '. $e->getMessage ()); error_log (sprintf ('Exception: %s(%d): %s. Trace: %s'
,$e->getFile ()
,$e->getLine ()
,$e->getMessage ()
,$e->getTraceAsString ()
));
myGlobalErrorHandler (); myGlobalErrorHandler ();
} }