Module:log globals/documentation

Documentation for Module:log globals. [edit]
This page contains usage information, categories, interwiki links and other content describing the module.

Sends a log message if any nil global variables are set or read by any module involved in the current module invocation. A less drastic version of the strict library, which triggers an error in the same situation.

This module logs uses of nil global variables in code that is executed after the module is loaded. There is no deduplication so the same message can appear many times if it is triggered by more than one template.

After the name of the variable and whether it was set or accessed, a backtrace is shown. The first line of the backtrace gives the line of the module where a global variable was used, which is often the line that needs to be changed. Sometimes a global variable is used because of a misspelling; sometimes a variable is defined and local needs to be added to its definition (which requires refactoring or forward declaration if the variable is used before it is defined).

To use it, add require("Module:log globals") temporarily at the top of the module. Preview a page by entering a page in the "Preview page with this template" box and pressing the "Show preview" button. Click to open the "Parser profiling data:" box at the bottom of the page, if it is not open already, and click the "Expand" button next to the "Lua logs" label. Inside is a log of global variables that were accessed or set in any code that was executed after this module was loaded. This includes global variables in code in other modules. After changing the global variables to local, and before saving the module, remove require("Module:log globals").