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

By Dave - March 17, 2015

Hi Jerry, 

You can prevent errors from being displayed on web pages with this setting:
Admin > General Settings > Security Settings > Hide PHP Errors [x] Hide all PHP errors and warnings (still logged to error log)

However, there's no way to disable logging of errors, which actually include notices, warnings and other diagnostic messages.  The error log will, however, only store the last (approximately) 1000 error messages.  

As far as how to explain this to your clients.  I'd just acknowledge that there is, in fact, an error log accessible to admin users under the admin menu.  That it's purpose is to provide diagnostic data to developers and programmers.  And that it can be safely ignored.

Most of the software used in building websites maintains "error" logs of various sorts, include the webserver (Apache error logs), mysql, etc.  Even every windows computer has an "event log" full of "errors".

When building new websites, I'd recommend avoid writing code that produces php warnings/notices/etc just because it will make it easier to spot actual errors in the log.  But for existing websites, I wouldn't bother with making any changes unless you're updating the website anyway.  One last point on that is that PHP adds and removes warnings and notices about various things in between the difference versions.  Sometimes even outputting a warning with a new release only to hide it later.  It's really just a diagnostic log for developers, clients don't need to worry about it.

Hope that helps, let me know any questions or if there's any remaining issues that this doesn't address.

PS: If you have the email notification feature on and it's emailing them, just edit the error notification email template under Admin > Email Templates and set the To: address to your own email.

Dave Edis - Senior Developer
interactivetools.com

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

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