Page 1 of 1
error log?
Posted: Thu Jan 29, 2015 7:58 pm
by mrodent
Newbie again... sorry!
(see my previous post): I'm encountering an error creating a form from one particular table... Sometimes the Javascript "alert" which comes up gives the full error message, but more often it simply says
"===USER==========
globeadmin"
... so I'm just wondering if these error messages (and maybe other log messages) are in fact being logged to a file which I can look at when things go wrong?
... or maybe there's a way to turn on some sort of logging???
Re: error log?
Posted: Thu Jan 29, 2015 11:51 pm
by admin
mrodent,
Its written to zzzsys_debug and you can view it here..
Capture.PNG
Steven
Re: error log?
Posted: Fri Jan 30, 2015 7:18 pm
by mrodent
Tx
Re: error log?
Posted: Sun Feb 01, 2015 7:21 pm
by mrodent
I just found an error which was not reported in this dbase table and wonder whether it was being logged somewhere else. The circumstances: I was basically following video 7 (invoice items) ... so I have a subform with multiple invoice items for a given invoice.
I entered a new invoice item in the "tentative append" (empty lowest row) of the grid... and clicked "Save".
I got a JS alert: "Internal Server Error [500]".
This probably relates to a refused SQL INSERT command... maybe to do with foreign constraints (although I made sure that the new line had the right invoice number).
The problem is that it's difficult to solve problems if they're not logged, and this event was not logged in zzzsys_debug.
If you can suggest the PHP file where the error probably occurred I could fiddle with the code and implement my own logging.
Re: error log?
Posted: Sun Feb 01, 2015 11:33 pm
by admin
mrodent,
A js error won't come up in php logs.
You would be better off commenting out your code until you find the problem.
You could also use the browser's debug (F12) to see if any error shows in the console.
BUT! I bet your problem has to do with field names with spaces in them, You can't use nuBuilder if they exist.
Steven
Re: error log?
Posted: Mon Feb 02, 2015 10:36 am
by mrodent
Thanks...
"Server error 500" is an indication of a PHP exception/error... I just meant that it was throwing up an alert (which is obviously a JS alert...) but the problem is coming from execution of a PHP file.
I've got rid of field names with spaces!
Yep, I've been using Firefox debug ... no useful info.
So I've added a few lines to end of nucommon.php to intercept all exception and error calls and log them (using log4php) to a file.
These are the lines which generate errors:
"error_handler called: Undefined index: fields, D:\Apache root\nuBuilderPro-kernel\nucommon.php, 427"
"error_handler called: Undefined index: tblinvoices_log_changed_at, D:\Apache root\nuBuilderPro-kernel\nuapi.php, 2968"
and finally, chronologically
exception_handler called: exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '54' for key 'PRIMARY'' in D:\Apache root\nuBuilderPro-kernel\nuapi.php:
784 Stack trace:
#0 D:\Apache root\nuBuilderPro-kernel\nuapi.php(784): PDO->exec('INSERT INTO `tb...')
#1 D:\Apache root\nuBuilderPro-kernel\nuapi.php(669): nuGetNewPrimaryKey('tblinvoiceitems', 'ItemNo')
#2 D:\Apache root\nuBuilderPro-kernel\nuapi.php(136): nuSaveForm(Array, Array)
#3 {main}
I then logged this SQL statement made at this point of nuapi.php:
"INSERT INTO `tblinvoiceitems` (`ItemNo`) VALUES ('54cfbc18b43b3a1')"
"ItemNo" is the primary key field of this table tblinvoiceitems. This means that by default (seemingly) it is not shown on your forms and subforms. Anyway, I changed this field to make it AUTOINCREMENT. I then got the following:
"INSERT INTO `tblinvoiceitems` (`ItemNo`) VALUES (NULL)"... which didn't cause an error because the PK here is AUTOINCREMENT, so a row was successfully added to the subform.
I can't help wondering why the PK is hidden by default in Nubuilder forms and subforms... what happens with multi-field PKs, I wonder...
NB am still getting the "Undefined index" errors... but these seem to be curtailing "non-vital" PHP execution threads. Will investigate though.
Re: error log?
Posted: Mon Feb 02, 2015 10:57 pm
by admin
mrodent,
Comment out all of the php code and add it back bit by bit until you find the problem.
A lesson for any programmer.
Steven
Re: error log?
Posted: Tue Feb 03, 2015 10:43 am
by mrodent
Yes, I'll do that... but you might want to think about adding catch-all logging to the bottom of nucommon.php... log4php is pretty good and allows for logging to a "rolling log" (never gets too big), to a database table, etc. etc.
The end of my nucommon.php now looks like this:
Code: Select all
////////////// ERROR HANDLING
define('LOG_FULL_PATH', 'D:/output/logging/php/nubuilder_kernel/myRollingLog.htm' );
ini_set('error_log', LOG_FULL_PATH);
ini_set('log_errors', 'On');
// turn off logging to browser
ini_set('display_errors', 'Off');
include ('..\\log4php\\Logger.php');
Logger::configure ( 'config.xml' );
$log = Logger::getLogger('main');
function shutdown_function( ) {
global $log;
$error = error_get_last();
if( is_object( $log )){
if( is_object( $error) ){
$log->error( "shutdown function called, error message: " . $error->getMessage() );
}
else {
$error_type = gettype( $error );
if( is_array( $error )){
$error_details = print_r( $error, true );
$log->error( "shutdown function called, error details: $error_details" ) ;
}
else {
$log->info( "shutdown function called, seemingly no error" );
}
}
}
}
register_shutdown_function('shutdown_function');
// default (non-fatal) error handling...
function error_handler($err_no, $err_str, $err_file, $err_line) {
global $log;
if( is_object( $log )){
$log->error( "error_handler called: $err_str, $err_file, $err_line");
}
}
set_error_handler('error_handler');
// default exception handling...
function exception_handler($e) {
global $log;
if( is_object( $log )){
$log->error( "exception_handler called: $e");
}
}
set_exception_handler('exception_handler');
Re: error log?
Posted: Sat Feb 07, 2015 7:42 pm
by mrodent
also, I'd just like to suggest that you need, ideally, catch-all logging in your JS scripts, and you very sensibly have a file nucommon.js.
I've added the following lines to the top of this file:
Code: Select all
// NB this is a flag
common_js_error = false;
// generic error-handler: logs to server and if applicable displays in console
onerror = function(err_msg, url, line_number) {
var output = 'JS error thrown, url: ' + url + ', line number: ' + line_number + '<br>message: ' + err_msg;
if ( typeof (console ) != 'undefined') {
console.error( output);
}
if ( typeof (log_to_server ) != 'undefined') {
// if implemented, this function obviously uses an Ajax call to a php file, which logs the problem (unified PHP and JS log...)
log_to_server(output, 3); // 2nd field when equal to "3" might signal an error condition
}
// NB set flag - up to you whether you clear it and how you use it
common_js_error = true;
// returning true or false does not cause the previously defined onerror to be called
// however it is stated that returning true "prevents the firing of the default event handler"
return true;
};