MsgLogS.sgm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!-- $XConsortium: MsgLogS.sgm /main/9 1996/11/12 11:26:42 cdedoc $ -->
  2. <!-- (c) Copyright 1996 Digital Equipment Corporation. -->
  3. <!-- (c) Copyright 1996 Hewlett-Packard Company. -->
  4. <!-- (c) Copyright 1996 International Business Machines Corp. -->
  5. <!-- (c) Copyright 1996 Sun Microsystems, Inc. -->
  6. <!-- (c) Copyright 1996 Novell, Inc. -->
  7. <!-- (c) Copyright 1996 FUJITSU LIMITED. -->
  8. <!-- (c) Copyright 1996 Hitachi. -->
  9. <![ %CDE.C.CDE; [<refentry id="CDE.MSG.DtMsgLogSetHandler">]]>
  10. <![ %CDE.C.XO; [<refentry id="XCSA.MSG.DtMsgLogSetHandler">]]>
  11. <refmeta><refentrytitle>
  12. DtMsgLogSetHandler
  13. </refentrytitle><manvolnum>library call</manvolnum></refmeta><refnamediv>
  14. <refname><function>DtMsgLogSetHandler</function></refname><refpurpose>
  15. installs an alternate message logging handler
  16. </refpurpose></refnamediv><refsynopsisdiv>
  17. <funcsynopsis>
  18. <funcsynopsisinfo>#include &lt;Dt/MsgLog.h></funcsynopsisinfo>
  19. <funcdef>DtMsgLogHandler <function>DtMsgLogSetHandler</function></funcdef>
  20. <paramdef>DtMsgLogHandler <parameter>handler</parameter></paramdef>
  21. </funcsynopsis>
  22. </refsynopsisdiv><refsect1>
  23. <title>DESCRIPTION</title>
  24. <para>The <function>DtMsgLogSetHandler</function> function
  25. installs an alternate message logging handler that will be
  26. invoked when <function>DtMsgLogMessage</function> is called.
  27. If <symbol role="Variable">handler</symbol> is <symbol role="define">NULL</symbol>,
  28. the default handler is installed.
  29. </para>
  30. <para><function>DtMsgLogSetHandler</function> is optional and should
  31. be used only to override the default message logging handler.
  32. If the handler function wants to log a message, it must use the
  33. format and file specified in &cdeman.DtMsgLogMessage;
  34. so applications can reliably parse the log file. (If the handler
  35. wants to log a message, it can obtain the byte count to output
  36. by using the return value from a call to
  37. <function>vfprint</function>.)
  38. </para>
  39. <para>The <function>DtMsgLogHandler</function> handler function has
  40. the following arguments:
  41. </para>
  42. <variablelist>
  43. <varlistentry><term><symbol role="Variable">program_name</symbol></term>
  44. <listitem>
  45. <para>A string "tag" to identify the application
  46. issuing the message. This is generally an application's
  47. <literal>argv[0]</literal>.
  48. </para>
  49. </listitem>
  50. </varlistentry>
  51. <varlistentry><term><symbol role="Variable">msg_type</symbol></term>
  52. <listitem>
  53. <para>The message type.
  54. </para>
  55. </listitem>
  56. </varlistentry>
  57. <varlistentry><term><symbol role="Variable">format</symbol></term>
  58. <listitem>
  59. <para>Specifies the <function>sprintf</function> format of the message.
  60. </para>
  61. </listitem>
  62. </varlistentry>
  63. <varlistentry><term><symbol role="Variable">args</symbol></term>
  64. <listitem>
  65. <para>Specifies the variable number of arguments needed by
  66. <symbol role="Variable">format</symbol>.
  67. </para>
  68. </listitem>
  69. </varlistentry>
  70. </variablelist>
  71. <para>The handler function should not call <function>DtMsgLogMessage</function>.
  72. </para>
  73. <para>A sample use of the <function>DtMsgLogSetHandler</function> function
  74. is in an application that prints the
  75. CDE data types and actions databases. If an error occurs when the
  76. databases are loaded, the error messages are logged and the application
  77. is not able to get the messages. However, if the application installs
  78. a message logging handler, when the database loading code encounters
  79. an error, the application's installed handler will be invoked to give
  80. the application access to the database loading error messages.
  81. </para>
  82. </refsect1><refsect1>
  83. <title>ARGUMENTS</title>
  84. <variablelist>
  85. <varlistentry><term><symbol role="Variable">handler</symbol></term>
  86. <listitem>
  87. <para>Specifies a message handler function.
  88. </para>
  89. </listitem>
  90. </varlistentry>
  91. </variablelist>
  92. </refsect1><refsect1>
  93. <title>ENVIRONMENT VARIABLES</title>
  94. <para>None.
  95. </para>
  96. </refsect1><refsect1>
  97. <title>RESOURCES</title>
  98. <para>None.</para>
  99. </refsect1><refsect1>
  100. <title>ACTIONS/MESSAGES</title>
  101. <para>None.
  102. </para>
  103. </refsect1><refsect1>
  104. <title>ERRORS/WARNINGS</title>
  105. <para>None.</para>
  106. </refsect1><refsect1>
  107. <title>EXAMPLES</title>
  108. <para>The following code installs a
  109. <function>DtMsgLogHandler</function> handler
  110. and then calls <function>DtDbLoad</function> to load the CDE
  111. data typing and action databases. If an error occurs when the
  112. databases are loaded, the handler function will be invoked.
  113. The handler writes the message to an alternate file. After the databases are
  114. loaded, the default handler is restored.
  115. </para>
  116. <programlisting>
  117. (void) DtMsgLogSetHandler (msglog_handler);
  118. DtDbLoad ();
  119. (void) DtMsgLogSetHandler (NULL);
  120. void my_handler (
  121. const char * prog_name,
  122. DtMsgLogType msg_type,
  123. const char * format,
  124. va_list args)
  125. {
  126. FILE *fp;
  127. fp = fopen ("/tmp/foo", "a+");
  128. (void) fprintf (fp, "progname = %s\n\tformat = %s\n\tmsg_type = %d\n",
  129. prog_name, format, msg_type);
  130. (void) vfprintf (fp, format, args);
  131. (void) fprintf (fp, "\n");
  132. }
  133. </programlisting>
  134. </refsect1><refsect1>
  135. <title>RETURN VALUE</title>
  136. <para>If <function>DtMsgLogMessage</function> completes
  137. successfully, it returns the previously installed handler.
  138. If it fails, it returns <symbol role="define">NULL</symbol>.
  139. </para>
  140. </refsect1><refsect1>
  141. <title>FILES</title>
  142. <para>None.
  143. </para>
  144. </refsect1><refsect1>
  145. <title>SEE ALSO</title>
  146. <para>&cdeman.DtMsgLogMessage;,
  147. &cdeman.DtMsgLogOpenFile;</para>
  148. </refsect1></refentry>