[Pmwiki-users] Verbose-mechanism

Christian Ridderström chr
Sun Jan 18 15:45:01 CST 2004


Hi

When I develop programs I frequently find it useful to implement a 
function to let the program be more or less verbose. I often use '-v' 
as command line option to indicate this, which isn't possible here of 
course. Instead, we supply an extra argument to the URI when we want 
increased verbosity:

	&verbocity=3

where the number indicates verbocity and 0 is default, which typically 
means no additional logged information. 

Here's one way of how it can be implemented:

  // Extract the optional verbocity parameter (default is zero)
  foreach(array('verbocity') as $v) {
    if (isset($HTTP_GET_VARS[$v])) $$v=$HTTP_GET_VARS[$v];
    elseif (isset($HTTP_POST_VARS[$v])) $$v=$HTTP_POST_VARS[$v];
    else $$v = 0;
  }


// Function that produces output only if $verboseness is greater 
// than or equal to the global level of $Verbocity.
function Verbose($verboseness, $text) {
  global $Verbocity;
  if($verboseness >= $Verbocity)
    echo "<I>Verbose:</I> <code>".$text."</code><br>";
}

And here's how it can actually be used:

  Verbose(1, "dir = $dir");
  Verbose(1, "path = $path");
  Verbose(4, "This text is only printed if verbocity is >= 4");

where the output is illustrated here:
    http://www.lyx.org/~chr/attachlist/pmwiki.php?pagename=Main.TestWithBarelyLegalDir


Any thoughts on this? Are there better solutions available in Php? 

/Christian

-- 
Dr. Christian Ridderstr?m, +46-8-768 39 44       http://www.md.kth.se/~chr




More information about the pmwiki-users mailing list