[Templates] basic question about logging from TT
Andy Wardley
abw@wardley.org
Thu, 25 May 2006 11:03:37 +0100
markd wrote:
> I know I can do:
>
> [% PERL %]
> print STDERR "message";
> [% END %]
>
> But tedious (and presumably inefficient?)
I usually do something like this in a PRE_PROCESS config file:
[% IF debug;
MACRO debug_msg(text)
FILTER stderr; " # $text\n"; END;
ELSE;
debug_msg = '';
END;
%]
I use a 'debug' flag (set in my ttree config file or in variables passed
in from my Perl code/Apache handle) to enable/disable debugging en
masse. If debugging is on then the debug_msg() MACRO is defined to
print its argument to stderr (via the stderr FILTER), otherwise it's a
nullup.
Then in my templates I write:
[% debug_msg("Hello World") %]
HTH
A