⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-message-logging.html

📁 glid编写实例
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<p>Logs a "critical warning" (<span class="type">G_LOG_LEVEL_CRITICAL</span>). It's more or lessapplication-defined what constitutes a critical vs. a regularwarning. You could call <a href="glib-Message-Logging.html#g-log-set-always-fatal"><code class="function">g_log_set_always_fatal()</code></a> to make criticalwarnings exit the program, then use <a href="glib-Message-Logging.html#g-critical"><code class="function">g_critical()</code></a> for fatal errors, forexample.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>...</code></em>&#160;:</span></td><td>format string, followed by parameters to insert into the format string (as with <code class="function">printf()</code>)</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2933557"></a><h3><a name="g-error"></a>g_error()</h3><a class="indexterm" name="id2933568"></a><pre class="programlisting">#define     g_error(...)</pre><p>A convenience function/macro to log an error message.Error messages are always fatal, resulting in a call to<code class="function">abort()</code> to terminate the application.This function will result in a core dump; don't use it for errors youexpect. Using this function indicates a bug in your program, i.e. anassertion failure.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>...</code></em>&#160;:</span></td><td>the parameters to insert into the format string.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2933617"></a><h3><a name="g-debug"></a>g_debug()</h3><a class="indexterm" name="id2933627"></a><pre class="programlisting">#define     g_debug(...)</pre><p>A convenience function/macro to log a debug message.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>...</code></em>&#160;:</span></td><td>format string, followed by parameters to insert into the format string (as with <code class="function">printf()</code>)</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id2933677"></a><h3><a name="g-log-set-handler"></a>g_log_set_handler ()</h3><a class="indexterm" name="id2933688"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint">guint</a>       g_log_set_handler               (const <a href="glib-Basic-Types.html#gchar">gchar</a> *log_domain,                                             <a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> log_levels,                                             <a href="glib-Message-Logging.html#GLogFunc">GLogFunc</a> log_func,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Sets the log handler for a domain and a set of log levels.To handle fatal and recursive messages the <em class="parameter"><code>log_levels</code></em> parametermust be combined with the <span class="type">G_LOG_FLAG_FATAL</span> and <span class="type">G_LOG_FLAG_RECURSION</span> bit flags.</p><p>Note that since the <span class="type">G_LOG_LEVEL_ERROR</span> log level is always fatal, if you want to set a handler for this log level you must combine it with <span class="type">G_LOG_FLAG_FATAL</span>.</p><div class="example"><a name="id2933793"></a><p class="title"><b>Example&#160;13.&#160;Adding a log handler for all warning messages in the default (application) domain</b></p><pre class="programlisting">  g_log_set_handler (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL                     | G_LOG_FLAG_RECURSION, my_log_handler, NULL);</pre></div><div class="example"><a name="id2933809"></a><p class="title"><b>Example&#160;14.&#160;Adding a log handler for all critical messages from GTK+</b></p><pre class="programlisting">  g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL | G_LOG_FLAG_FATAL                     | G_LOG_FLAG_RECURSION, my_log_handler, NULL);</pre></div><div class="example"><a name="id2933824"></a><p class="title"><b>Example&#160;15.&#160;Adding a log handler for <span class="emphasis"><em>all</em></span> messages from GLib</b></p><pre class="programlisting">  g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL                     | G_LOG_FLAG_RECURSION, my_log_handler, NULL);</pre></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>log_domain</code></em>&#160;:</span></td><td>the log domain, or <code class="literal">NULL</code> for the default "" application domain.</td></tr><tr><td><span class="term"><em class="parameter"><code>log_levels</code></em>&#160;:</span></td><td>the log levels to apply the log handler for. To handle fataland recursive messages as well, combine the log levels with the<span class="type">G_LOG_FLAG_FATAL</span> and <span class="type">G_LOG_FLAG_RECURSION</span> bit flags.</td></tr><tr><td><span class="term"><em class="parameter"><code>log_func</code></em>&#160;:</span></td><td>the log handler function.</td></tr><tr><td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td><td>data passed to the log handler.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>the id of the new handler.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2933940"></a><h3><a name="g-log-remove-handler"></a>g_log_remove_handler ()</h3><a class="indexterm" name="id2933951"></a><pre class="programlisting">void        g_log_remove_handler            (const <a href="glib-Basic-Types.html#gchar">gchar</a> *log_domain,                                             <a href="glib-Basic-Types.html#guint">guint</a> handler_id);</pre><p>Removes the log handler.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>log_domain</code></em>&#160;:</span></td><td>the log domain.</td></tr><tr><td><span class="term"><em class="parameter"><code>handler_id</code></em>&#160;:</span></td><td>the id of the handler, which was returned in <a href="glib-Message-Logging.html#g-log-set-handler"><code class="function">g_log_set_handler()</code></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2934031"></a><h3><a name="g-log-set-always-fatal"></a>g_log_set_always_fatal ()</h3><a class="indexterm" name="id2934042"></a><pre class="programlisting"><a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> g_log_set_always_fatal       (<a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> fatal_mask);</pre><p>Sets the message levels which are always fatal, in any log domain.When a message with any of these levels is logged the program terminates.You can only set the levels defined by GLib to be fatal.<code class="literal">G_LOG_LEVEL_ERROR</code> is always fatal.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>fatal_mask</code></em>&#160;:</span></td><td>the mask containing bits set for each level of error which isto be fatal.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>the old fatal mask.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2934110"></a><h3><a name="g-log-set-fatal-mask"></a>g_log_set_fatal_mask ()</h3><a class="indexterm" name="id2934121"></a><pre class="programlisting"><a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> g_log_set_fatal_mask         (const <a href="glib-Basic-Types.html#gchar">gchar</a> *log_domain,                                             <a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> fatal_mask);</pre><p>Sets the log levels which are fatal in the given domain.<code class="literal">G_LOG_LEVEL_ERROR</code> is always fatal.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>log_domain</code></em>&#160;:</span></td><td>the log domain.</td></tr><tr><td><span class="term"><em class="parameter"><code>fatal_mask</code></em>&#160;:</span></td><td>the new fatal mask.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>the old fatal mask for the log domain.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2934209"></a><h3><a name="g-log-default-handler"></a>g_log_default_handler ()</h3><a class="indexterm" name="id2934220"></a><pre class="programlisting">void        g_log_default_handler           (const <a href="glib-Basic-Types.html#gchar">gchar</a> *log_domain,                                             <a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> log_level,                                             const <a href="glib-Basic-Types.html#gchar">gchar</a> *message,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> unused_data);</pre><p>The default log handler set up by GLib; <a href="glib-Message-Logging.html#g-log-set-default-handler"><code class="function">g_log_set_default_handler()</code></a> allows to install an alternate default log handler.This is used if no log handler has been set for the particular log domainand log level combination. It outputs the message to stderr or stdoutand if the log level is fatal it calls <code class="function">abort()</code>.</p><p>stderr is used for levels <code class="literal">G_LOG_LEVEL_ERROR</code>, <code class="literal">G_LOG_LEVEL_CRITICAL</code>,<code class="literal">G_LOG_LEVEL_WARNING</code> and <code class="literal">G_LOG_LEVEL_MESSAGE</code>. stdout is used for the rest.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>log_domain</code></em>&#160;:</span></td><td>the log domain of the message.</td></tr><tr><td><span class="term"><em class="parameter"><code>log_level</code></em>&#160;:</span></td><td>the level of the message.</td></tr><tr><td><span class="term"><em class="parameter"><code>message</code></em>&#160;:</span></td><td>the message.</td></tr><tr><td><span class="term"><em class="parameter"><code>unused_data</code></em>&#160;:</span></td><td>data passed from <a href="glib-Message-Logging.html#g-log"><code class="function">g_log()</code></a> which is unused.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2934397"></a><h3><a name="g-log-set-default-handler"></a>g_log_set_default_handler ()</h3><a class="indexterm" name="id2934408"></a><pre class="programlisting"><a href="glib-Message-Logging.html#GLogFunc">GLogFunc</a>    g_log_set_default_handler       (<a href="glib-Message-Logging.html#GLogFunc">GLogFunc</a> log_func,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Installs a default log handler which is used is used if no log handler has been set for the particular log domainand log level combination. By default, GLib uses <a href="glib-Message-Logging.html#g-log-default-handler"><code class="function">g_log_default_handler()</code></a> as default log handler.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>log_func</code></em>&#160;:</span></td><td>the log handler function.</td></tr><tr><td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td><td>data passed to the log handler.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>the previous default log handler</td></tr></tbody></table></div><p>Since 2.6</p></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Warnings-and-Assertions.html"><b>&lt;&lt;&#160;Message Output and Debugging Functions</b></a></td><td align="right"><a accesskey="n" href="glib-utilities.html"><b>GLib Utilities&#160;&gt;&gt;</b></a></td></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -