Inside Mod Manager v12 Logging

From TNG_Wiki
Jump to navigation Jump to search

Mod Manager Logging

Logging is done whenever an object actually changes or attempts to change the TNG environment.

Mod Manager objects which log events use a common set of logging routines provided by Modbase.

A global string, $this->eventlog is initialized to keep the cumulative log results until the calling object has finished processing a mod.

Log events are simply a series of styled and formatted strings appended to $this->eventlog during the processing.

New Log Event

A log event is meant to include everything that happened during the processing of a single mod configuration file.

A Log event entry is started using $this->new_logevent($string) where the $string being passes contains the process being started and the mod configuration (cfg) file name.

$this->new_logevent( "{$this->admtext['installing']} <strong>$cfgpath</strong>" );

$this->new_logevent($string) initializes $this->eventlog (global variable) with the date and time, operation, mod name, mod version, status placeholder (zzzxxzzz), and current user placeholder (xxxzzxxx). Placeholders will be filled in at the end of processing when the final status is known. Finally, it appends the function's $string argument which contains operation being attempted and the mod file name -- Installing [mod file], Removing [mod file], etc.

Add Log Event

A log event is everything concerning the processing of a single mod configuration file. This function would have been better named add_log_item() since it is used to add subevents to the mod-wide log event.

After starting the log, the calling object appends a result string for each operation performed using $this->add_logevent($string). This function adds a bit of CSS for spacing and appends the string to $this->eventlog.

Here we log the fact that a file was successfully copied using localized language support.

$logstring = "{$this->admtext['line']} {$tags[$j]['line']}: %<span class=\"tag\">{$tags[$j]['name']}:</span>";
$logstring .= "<span class=\"tgtfile\">{$flag}$dest_path</span>%&nbsp;";
.
.
$logstring .= "<span class=\"msgapproved\">{$this->admtext['copied']}</span>";
$this->add_logevent($logstring);

Write Event Log

When the calling object is finished processing a mod, and done adding event results to the log string, it calls $this->write_eventlog($error=false). If there is an error preventing the object from doing its job, $error is set to true so the function will highlight the log event as a parse error.

$this->mod_status = $status;
$this->write_eventlog();

This function checks to see that the log file exists and, if not, creates it using Modbase function $this->create_logfile() which inserts the date and time the log is created. Not sure this this text is useful as it disappears from the bottom of the log as soon as the max allowed lines are exceeded.

The log path/file is named in user $options['modlogfile']. The default is modmgrlog.txt, but the path and name may be changed using the Mod Manager Options tab, or directly edited in the mmconfig.php file. File paths are relative to the TNG root directory. If you want to keep the log in the "safe" area above the public_html, you can set it to something like this:

$options['modlogfile'] = "../modmgrlog.txt";

Function uses global string $this->mod_status to fill the header place holders in the $this->eventlog string with with final status data.

$this->eventlog=str_replace("zzzxxzzz", $modstat1, $this->eventlog);
$this->eventlog=str_replace("xxxzzxxx", $modstat2, $this->eventlog);

Finally, to write the accumulated event string -- $this->eventlog -- to the log file, this function reads the log file into an array of lines and inserts the $this->eventlog string at the top of the lines array using PHP function array_unshift(). Then it starts a clean log file and writes the line array one line at a time, stopping when it has reached $this->maxloglines from the Mod Manager user options.

Note: Because each logged event is one long line using <br /> instead of CRLF, $this->maxloglines is really a count of max logged events consisting of many physical lines each. The good thing is that the log is not cut off in the middle of an event as it probably would be if the log event string were broken into separate text lines.

Inside Mod Manger v12 Directory

Chapters

Inside Mod Manager v12 (Home)

  1. Mod Manager and OOP
  2. Page Headings
  3. Main Script
  4. Class Modbase
  5. Class Modparser
  6. Class Modlister
  7. Class Modinstaller
  8. Class Modeditor
  9. Class Modremover
  10. Class Moddeleter
  11. Formulas
  12. Mod Options
  13. Mod Logging
  14. Tools
  15. Issues