Difference between revisions of "Prolog Mod"
Line 53: | Line 53: | ||
===Log Rotation=== | ===Log Rotation=== | ||
− | Both Prolog and the system will log errors to the PHP file. At the close of each GMT day Prolog will archive the PHP log to a dated backup and start the PHP log over again. After the first day no single log will contain more that one day's errors. That keeps all of them relatively small and manageable. | + | Both Prolog and the PHP system will log errors to the PHP file. At the close of each GMT day Prolog will archive the PHP log to a dated backup and start the PHP log over again. After the first day no single log will contain more that one day's errors. That keeps all of them relatively small and manageable. |
Prolog modifies subroot.php to add logging to all TNG pages. Scripts that work independently of TNG will not be logged by this mod; however, those errors will be logged by the system in the same PHP log. | Prolog modifies subroot.php to add logging to all TNG pages. Scripts that work independently of TNG will not be logged by this mod; however, those errors will be logged by the system in the same PHP log. |
Revision as of 18:15, 10 August 2020
If this mod is installed or configured incorrectly it could make your site appear to crash. Don't panic. Edit your subroot.php and remove the last line pertaining to Prolog. Then in mod manager "Clean" the partially installed Prolog to remove the mod. See Below for detail |
Downloads of Prolog Mod are restricted to logged in users. If you do not have a user account on the TNG Wiki use the Request Account link to request a user account | ||
If you have trouble downloading with Google Chrome, Vivaldi, Brave or other Chromium based browser, try using a right-click and select Open in new Window, then F5, or use another browser such as Firefox
|
Prolog Mod | ||
---|---|---|
Summary | Adds PHP Rotating Logs to TNG site | |
Validation | ||
Mod Updated | 13 Mar 2020 | |
Download link | version 12.0.0.8.zip
| |
Download stats | view statistics | |
Author(s) | Rick Bisbee | |
Homepage | Bisbee Family Connection | |
Mod Support | Support for Prolog_Mod | |
Contact Developer | As above | |
Latest Mod | 12.0.0.8 | |
Min TNG V | 12.0 | |
Max TNG V | 12.3+ | |
Files modified | ||
Related Mods | ||
Notes |
Prolog (PHP Rotating Log) Introduction
Prolog is a utility for TNG testers, mod developers and anyone who wants to monitor their websites for PHP or user issues. It is an extension of the Show PHP Errors mod created by Roger Mitchell (decd) and provides three selectable levels of error logging: 1) just errors; 2) all errors, warnings and deprecations except for notices (default); or 3) all errors, warnings, notices, and deprecated functions.
An important feature is that fatal errors displayed to the screen are generic and never reveal server information that a hacker may be looking for.
Error Log Location
Prolog will 1) use the php.ini error_log setting to place its logs in the same location as PHP. If the php.ini is not set, or if it is inaccessible, prolog will 2) use the TNG root-relative path you've set in the Mod Edit Options. If not set there, Prolog will 3) create and default to a logs directory in your TNG root directory. While the third option works fine for offline test sites, for security reasons it is not recommended for a live site.
php.ini error_log directive
You must set the php.ini error_log directive with the full server path to the PHP error log for the site. Error logs can be located above the public_html for greater security (recommended.) In a local WAMP server you can edit it directly into the WAMPS php.ini file. On a shared hosting server you may be able to add a php.ini file to your root directory with just this directive to override the master php.ini. Some hosts allow a user.ini to serve the same purpose. See PHP error log for additional information on setting up error logs. The directive will look something like this (note the absolute server path):
error_log = /home/mysite/mylogs/php_error.log OR FOR A WAMPS where wamps is your server folder name error_log = D:/wamps/logs/php_error.log
Log Rotation
Both Prolog and the PHP system will log errors to the PHP file. At the close of each GMT day Prolog will archive the PHP log to a dated backup and start the PHP log over again. After the first day no single log will contain more that one day's errors. That keeps all of them relatively small and manageable.
Prolog modifies subroot.php to add logging to all TNG pages. Scripts that work independently of TNG will not be logged by this mod; however, those errors will be logged by the system in the same PHP log.
That said, if you do want to Prolog independent scripts, you can include prolog_conf.php at the top of a primary (as opposed to an included) script and as long as the mod remains installed, errors will be logged in the same way as TNG scripts to protect fatal errors from revealing server information.
if(file_exists('prolog_conf.php')) require_once 'prolog_conf.php';
How Prolog Works
Prolog has two main files:
- prolog_conf.php creates the log files and directs the logging
- prolog.php displays and manages rotating logs from the Admin screen.
Prolog adds a log access page link in the TNG Admin management area and features the following:
- Rotating error logs are created daily to prevent them becoming too large to manage;
- The php.ini error log collects all of today's errors;
- Errors from previous days may be found in the dated archive logs;
- Archived logs and error entries are timestamped using the timezone set in php.ini;
- A clock is provided for admin perspective on timestamps;
- Mod Edit Option to select error level for logging;
- Mod Edit Option to set number of daily logs to keep before auto-deleting the oldest;
- Logs selectable from drop down list (see screen shot);
- Logged items are listed from most recent to oldest for admin convenience;
- A Filter is provided to limit viewing of logged errors to only items of interest;
- Language support included in mod folder for easier maintenance;
- A fatal shutdown handler.
Shutdown Handler
The shutdown handler is for errors that might not otherwise be logged because the system shuts down before processing them. Some, but not all servers are able to log fatal errors before shutting down, so there may be double entries in the logs -- but there will always be at least one if it occurs.
Fatal errors are very useful for revealing deliberate attacks that often result in displaying server information that attackers hope to exploit. While Prolog records them for the administrator, all the attacker sees is this, for example, after attempting to access a forbidden script:
[20-02-24 18:34:02] Something went wrong. Please report the error or come back later.
The exact time can be used to compare with the logs, should a legitimate user choose to report it. Compare the actual log entry with the displayed message above:
[24-Feb-2020 18:34:02 America/Phoenix] PRO Fatal error: File access violation in fgw/fgw_setup.php on line 26
This was probably a hack attempt. Both the displayed and logged errors were triggered by fgw_setup.php using the following code:
// ONLY ADMINISTRATOR GETS ACCESS TO THE SETUP PAGE if( empty( $superuser ) ) { trigger_error( $admtext['wse_access'], E_USER_ERROR ); die(); }
Language Support
The mod support folder contains support for Czech, English, French, German, Spanish and Swedish. You can modify the files right in the support folder to change the translations. You can add new folders with other languages if you like. If you make changes or additions I will be happy to add them to the distribution package for others to use as well. Just email them to me or use the mod support link on the Prolog_Mod TNGWiki page.
Using the PHP and System Logs
In your php.ini set the logfile, for example:
error_log = D:/wampsdir/mylogs/php_error.php
Prolog will detect the file and use it to log errors.
If you want to view Apache system logs in your WAMPS, in your WAMPS httpd.conf file set up a VirtualHost something like this.
<VirtualHost *:80> ErrorDocument 404 /errdocs/_err404.php ErrorDocument 403 /errdocs/_err403.php ErrorLog D:/wampsdir/mylogs/server_error.log </VirtualHost>
using the same directory as the php.ini error log.
Prolog will list and display that one too. It must be managed to prevent it from becoming too large and crashing the system with out-of-memory errors.
See PHP error log for more complete information on setting up error logs in different environments
More About Error Files and Log Dates
Archived error files and error items use the date set in the date.timezone directive in the php.ini file. If not set, GMT will be used.
On a live site with shared hosting, you may be able to set the timezone by creating a php.ini file in your document root and entering directives, for example:
date.timezone = America/Phoenix error_log = /home/bisbeefa/mylogs/php_error.log
It may take 20-30 minutes or more for the changes to take effect on shared hosting, so be patient.
You may also be able to add the following to your site's main .htaccess file for both error_log and date.timezone:
<IfModule php7_module> php_value date.timezone "America/Phoenix" php_value error_log "/home/bisbeefa/mylogs/php_error.log" </IfModule>
If you are still using PHP 5, change the first line above to reflect that.
My web host (Bluehost) also uses the following:
<IfModule lsapi_module> php_value date.timezone "America/Phoenix" php_value error_log "/home/bisbeefa/mylogs/php_error.log" </IfModule>
lsapi is a drop-in module to speed up serving PHP pages.
TNG Version Compatibility
Prolog is compatible with TNG version 12.0 and up.
Mod Revision History
Version | Date | Updates
|
---|---|---|
v12.0.0.8 | 10 Aug 2020 |
|
v12.0.0.7a | 13 Mar 2020 |
|
v12.0.0.7 | 12 Mar 2020 |
|
v12.0.0.6 | 9 Mar 2020 |
|
v12.0.0.5 | 5 Mar 2020 |
|
v12.2.0.4 | 3 Mar 2020 |
|
v12.2.0.3 | 1 Mar 2020 |
|
v12.2.0.2 | 24 Feb 2020 |
|
Screen Shots
PC Based WAMPS Test Site
PHP Prolog link in the Admin page header menu. Note the daily log selected from the drop down list, and that the site's PHP version and current error reporting level are displayed in the prolog header bar. In the above example, All errors, notices, warnings and deprecations are being logged. A developer would want to show all errors and correct those thrown by their own mods or scripts, which can be isolated from any others by using the filter.
The filter searches each logged entry for a matching sub-string and displays the whole line if found. You could filter on a file name to display errors coming from just that script, or on 'Warning' to only see warnings, or 'Undefined: index' to only display those kinds of notices. After entering the filter string you can hit enter or click on the circular arrows to activate it.
Prolog Edit Options Screen
Installation
Prolog installs as a normal TNG mod. Download and unzip the contents -- one file and one folder. Place the prolog.cfg file and the support folder into your TNG site's mods directory. Do not remove folders and files from the support folder -- just leave them there. Navigate to your Mod Manager, find and open the mod listing and click on Install.
Upgrade
When installing an updated version of Prolog, it is important that you first use Mod Manager to completely remove any earlier version and preferably delete it.
Configuration
You must have a site-wide PHP error log set in your php.ini file, either by directly editing the file in a local WAMPS, or in shared hosting, indirectly by adding a php.ini (or user.ini) file to your TNG root directory with the error_log directive, for example:
error_log = /home/mysite/mylogs/php_error.log
The error log file should use the extensions .log.
Setting the Error Level
- Error level 1 will only log actual, usually fatal errors.
- Error level 2, the default, should be about right for a live site. It will log errors, warnings and PHP function deprecations. That latter means the scripts will stop working with new PHP upgrades, so we should know about them.
- Error level 3 logs everything -- errors, notices, warnings and deprecations. Because TNG emotes large numbers of notices right now, error level 3 should only be used while actually testing a script and reduced back to 1 or 2 when not testing. Even a daily log can get very large at error level 3.
Warning
If installed incorrectly this mod can cause the site to appear to crash. Don't panic. Edit subroot.php and remove the last line pertaining to Prolog. The site will come good again. Then go to mod manager and Clean up the partially installed Prolog mod. Prolog modifies subroot.php by including prolog_conf.php with parameters that are set in the mod's Edit Options. If the mod's Edit Options are incorrectly set or if the mod is partially installed for some reason, subroot.php may fail and so will all pages that include it.
Mod Manager Bug
There was a bug in Mod Manager up to TNGv12.3 beta which was corrected during testing. If a parameter expects a numeric value and you update it with and empty field, it renders a parameter variable such as $mycount
$mycount = ;
That will cause a fatal error and the script containing the parameter will fail. After the fix to mod manager it will render it as
$mycound = 0;
.
Sites using this mod
If you download this mod, please add your TNG site to the table below:
URL | User | Note | Mod-Version | TNG-Version | User-language |
---|---|---|---|---|---|
A Bisbee Family History | Rick Bisbee | Mod Developer. A must-have for mod developers | 12.0.0.7 | 12.1 | English |
Our Roy and Boucher Family | Ken Roy | Using with Show PHP Error Log on test site | 12.0.0.5 | 12.2.0/12.3.0 beta | EN, FR |
Roots & Relatives Remembered | Ron Krzmarzick | Public & Private | See Here | See Here | EN,DE,CS,ES |