old-www/HOWTO/Caudium-HOWTO/printsomethingtodebuglogfil...

259 lines
3.8 KiB
HTML

<HTML
><HEAD
><TITLE
>How to print something to debug log file</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Caudium HOWTO"
HREF="index.html"><LINK
REL="UP"
TITLE="Developing with Caudium"
HREF="developing.html"><LINK
REL="PREVIOUS"
TITLE="How to use a backtrace"
HREF="backtrace.html"><LINK
REL="NEXT"
TITLE="How to help the Caudium community"
HREF="helpcaudiumcommunity.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Caudium HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="backtrace.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 6. Developing with Caudium</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="helpcaudiumcommunity.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="printsomethingtodebuglogfile">6.6. How to print something to debug log file</H1
><P
>&#13; With Caudium you can output something to the web page or to the debug log file
located in <TT
CLASS="filename"
>../logs/debug/default.*</TT
>. This way the end-user will not see any
line you can output in your debug log file. Sending output to the debug log file is simple, just write to stdout:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;write("my message to log file\n");
</PRE
></FONT
></TD
></TR
></TABLE
>
It is also usually useful to use <TT
CLASS="function"
>sprintf</TT
> to format what you want to output:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;int i = 2; write(sprintf("i=%d\n", i));
</PRE
></FONT
></TD
></TR
></TABLE
>
This line will output <TT
CLASS="computeroutput"
>i=2</TT
>, but it is better when you output array or mapping,
as Pike is able to print them in a human-comprehensible format:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;array a = ({ "test", "test2", 2 }); write(sprintf("a=%O\n", a));
</PRE
></FONT
></TD
></TR
></TABLE
>
Which will output:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;a = ({ /* 2 elements */
"test",
"test2"
})
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><DIV
CLASS="note"
><P
></P
><TABLE
CLASS="note"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/note.gif"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>&#13; the %O format is very useful since it can output any type from
int to mapping. The only type you can't format is object.
</P
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="backtrace.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="helpcaudiumcommunity.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>How to use a backtrace</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="developing.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>How to help the Caudium community</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>