Turning off error logging in 2.64

12 posts by 2 authors in: Forums > CMS Builder
Last Post: March 31, 2015   (RSS)

Hi All,

Probably missed it, but now that there's global error logging, which is a really time saving great addition, is there a way to turn off error report logging as well as the visible reports in V2.64?

That way we can work on errors that are not critical on our own time frame without building up large amounts of error report records for our clients to worry over.

And while you're updating for the next go around, is there a way that you can change the "sorry there are no records" message, to something like "Congratulations, you have no errors"? (just for this section...)

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Dave,

Unfortunately, some 'Clients' don't always understand the valid concepts that you described, and some of those can get either extremely nervous, or decide use it as a wedge to use in negotiating their (financial) position I.E.: No final payment until all the errors go away, etc.). 

Up to now, clients would have had to hunt  for most error logs (until the excellent addition in 2.64)

Before writing this post, I tried the,"Don't show this section on the menu bar" option, but that unfortunately doesn't hide the log from displaying in the admin section (in scary bright red, so client's can't miss it).

I don't want to disable this extremely useful feature, but I'd really prefer an option that hides the error log from being seen by anyone, including in the admin menu area.

Any thoughts?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - March 17, 2015

Hi Jerry, 

Ok, I got it.  That's unfortunate as catering to their requests to not show diagnostic logs will increase your cost of supporting them with their web requests.  In any case... 

You can disable error logging like this: 

- Edit /lib/menus/errorlog_functions.php
- Comment out this line at the top (add code in red): 

// enable error logging
//errorlog_enable();

This will prevent all errors from being logged and prevent any error log emails from being sent.

Note that these changes will get overwritten with an upgrade.

Hope that helps, let me know any other questions.

Dave Edis - Senior Developer
interactivetools.com

Thanks, Dave,

So I  guess there's no way to make the "don't show in menus" checkbox include the admin area?

That way the errors would get logged (as they should) and if a developer admin was aware of  the switch and wanted to view the errors to fix them, they could.

They just wouldn't always be a red flag in the client's face.

Best,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - March 17, 2015

Hi Jerry, 

Do you want to send me an email with login details and I can take a look at what the specific errors are?  You may be able to hide them by adding @ in a few places (which suppresses errors).

I could give you a line of code to add if you wanted to hide the menu on a specific install.  But it's still direct linked from a few places in the admin.  

Another option would be to not give the clients access to the admin menu.  

Can you email me details to dave@interactivetools.com so I can have a look?  

Thanks!

Dave Edis - Senior Developer
interactivetools.com

By Dave - March 18, 2015

Hi Jerry, 

So we've gone through a bit of this offline.  Here's some more info for youself and anyone else who might find it helpful.

If you want to remove the menu link with some custom code you can do that as follows:

- Open /lib/menus/header_functions.php
- Scroll to the bottom
- Add the code in red: 

  //
  $errorCount = mysql_count('_error_log');
  $adminMenus[] = array(
    'menuType'    => 'custom',
    'menuName'    => t('Error Log') . " ($errorCount)", //
    'menuOrder'   => ++$menuOrder,
    'link'        => '?menu=_error_log',
    'isSelected'  => ($menu == '_error_log'),

    'tableName'   => '_error_log',
    'recordCount' => $errorCount,
  );
  array_pop($adminMenus); // remove "Error Log" from menu
    
  //
  return $adminMenus;

The PHP array_pop() removes the last item off an array, so that line of code just removes the "Error Log" menu that was just added.  Note that you'll still be able to directly access the log with admin.php?menu=_error_log  All this code does is remove the menu link.

Next, it's not required, what I'd generally recommend is resolving any issues causing errors so that actual errors can be more easily spotted in the logs.  This can be done quite quickly by adding the error-suppression operator @ in front of @php_functions(), @$variables and @$array['lookups'].  But feel free to post any errors you find that you need help resolving and we can assist.  If you wanted to write a cookbook page on resolving PHP errors I imagine we could cover 99% of the cases in one page.

Hope that helps!  Let me know any other questions.  Cheers!

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - March 18, 2015 - edited: March 18, 2015

Thank you Dave...

I've started a page about fixing PHP errors in the CMSB Cookbook,( http://www.thecmsbcookbook.com ) and will include anything that gets posted here.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi All,

I’ve come up with a few PHP errors that I’m not sure how to suppress.

I’m guessing that adding an @ before $fieldname, in:   

if (!array_key_exists($fieldname, $CURRENT_USER)

might be the correct fix, but I wanted to check, just in case.

________________________________

The errors are:

E_NOTICE: Undefined index: approved (line 29)  in the line $wasChecked
E_NOTICE: Undefined index: last_name (line 33) inside $message=<<< __TEXT__
E_NOTICE: Undefined index: first_name (line 33)


In the emailOnApproved plugin below:

<?php
/*
Plugin Name: Email On Approved
Description: Email the user their password once they are approved
Version: 1.00
Requires at least: 2.04
*/


// UPDATE THESE VALUES

// DON'T UPDATE ANYTHING BELOW THIS LINE

addAction('record_postsave',  'emailOnApproved_sendPassword', null, 4);


//
function emailOnApproved_sendPassword($tableName, $isNewRecord, $oldRecord, $recordNum) {
  global $CURRENT_USER, $SETTINGS;
  $fieldname = 'approved';

  // error checking
    if ($tableName != 'accounts') { return; }
  if (!array_key_exists($fieldname, $CURRENT_USER)) {
    die(__FUNCTION__ .": You must create an accounts fields called '$fieldname'!");
  }

  // send email
  $wasChecked   = intval(!$oldRecord[$fieldname] && $_REQUEST[$fieldname]);
  $wasUnchecked = intval($oldRecord[$fieldname]  && !$_REQUEST[$fieldname]);

$message=<<< __TEXT__
    Welcome {$_REQUEST['first_name']} {$_REQUEST['last_name']},<br><br>
 
Your membership has been  processed successfully and you now have access to the Members Only area of our web site. <br> <br>
Your user name is: {$_REQUEST['username']} <br>
and your login password is: XXXXXX<br><br>

Once you have successfully logged in, you must change your password and can then update your own profile information. <br><br>
 
 
<a href="http://www.nawafl.com{$GLOBALS['WEBSITE_LOGIN_LOGIN_FORM_URL']}">Click here to login</a> <br><br>
 
Best, <br>  <br>
    
The Membership Committee  
__TEXT__;


$headers  = 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
$headers .="FROM:". $SETTINGS['adminEmail'];  
 
   if ($wasChecked) {
    $errors = mail($_REQUEST['email'],"Your membership has been successfully processed!",$message,$headers);  
    if ($errors!=1) { die("Mail Error: $php_errormsg"); }
  }
 
}
 
?>

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - March 30, 2015

Hi Jerry, 

Try these patches:

  // send email
  $wasChecked   = intval(!$oldRecord[$fieldname] && @$_REQUEST[$fieldname]);
  $wasUnchecked = intval($oldRecord[$fieldname]  && !@$_REQUEST[$fieldname]);

And for the first/last name, that actually indicates a possible error.  You may not want to send an email if the user hasn't filled out the form completely.  It's giving an error because it expects a field that isn't define even with a blank value.  So it's useful to know.

In any case, you can't use @ inside heredoc (http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) strings but you can force them to have defined values just above it:

$_REQUEST['first_name'] = @$_REQUEST['first_name']; 
$_REQUEST['last_name']  = @$_REQUEST['last_name']; 

$message=<<< __TEXT__
Welcome {$_REQUEST['first_name']} {$_REQUEST['last_name']},<br><br>

 Hope that helps!

Dave Edis - Senior Developer
interactivetools.com