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

📄 glib-message-logging.html

📁 glid编写实例
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Message Logging</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-core.html" title="GLib Core Application Support"><link rel="prev" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions"><link rel="next" href="glib-utilities.html" title="GLib Utilities"><meta name="generator" content="GTK-Doc V1.4 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Warnings-and-Assertions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-core.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-utilities.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Message-Logging"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Message Logging</span></h2><p>Message Logging &#8212; versatile support for logging messages with different levels of importance.</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include &lt;glib.h&gt;#define     <a href="glib-Message-Logging.html#G-LOG-DOMAIN:CAPS">G_LOG_DOMAIN</a>#define     <a href="glib-Message-Logging.html#G-LOG-FATAL-MASK:CAPS">G_LOG_FATAL_MASK</a>#define     <a href="glib-Message-Logging.html#G-LOG-LEVEL-USER-SHIFT:CAPS">G_LOG_LEVEL_USER_SHIFT</a>void        (<a href="glib-Message-Logging.html#GLogFunc">*GLogFunc</a>)                     (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> user_data);enum        <a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a>;void        <a href="glib-Message-Logging.html#g-log">g_log</a>                           (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> *format,                                             ...);void        <a href="glib-Message-Logging.html#g-logv">g_logv</a>                          (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> *format,                                             va_list args);#define     <a href="glib-Message-Logging.html#g-message">g_message</a>                       (...)#define     <a href="glib-Message-Logging.html#g-warning">g_warning</a>                       (...)#define     <a href="glib-Message-Logging.html#g-critical">g_critical</a>                      (...)#define     <a href="glib-Message-Logging.html#g-error">g_error</a>                         (...)#define     <a href="glib-Message-Logging.html#g-debug">g_debug</a>                         (...)<a href="glib-Basic-Types.html#guint">guint</a>       <a href="glib-Message-Logging.html#g-log-set-handler">g_log_set_handler</a>               (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);void        <a href="glib-Message-Logging.html#g-log-remove-handler">g_log_remove_handler</a>            (const <a href="glib-Basic-Types.html#gchar">gchar</a> *log_domain,                                             <a href="glib-Basic-Types.html#guint">guint</a> handler_id);<a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> <a href="glib-Message-Logging.html#g-log-set-always-fatal">g_log_set_always_fatal</a>       (<a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> fatal_mask);<a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> <a href="glib-Message-Logging.html#g-log-set-fatal-mask">g_log_set_fatal_mask</a>         (const <a href="glib-Basic-Types.html#gchar">gchar</a> *log_domain,                                             <a href="glib-Message-Logging.html#GLogLevelFlags">GLogLevelFlags</a> fatal_mask);void        <a href="glib-Message-Logging.html#g-log-default-handler">g_log_default_handler</a>           (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);<a href="glib-Message-Logging.html#GLogFunc">GLogFunc</a>    <a href="glib-Message-Logging.html#g-log-set-default-handler">g_log_set_default_handler</a>       (<a href="glib-Message-Logging.html#GLogFunc">GLogFunc</a> log_func,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre></div><div class="refsect1" lang="en"><a name="id2932744"></a><h2>Description</h2><p>These functions provide support for logging error messages or messages used for debugging. </p><p>There are several built-in levels of messages, defined in <a href="glib-Message-Logging.html#GLogLevelFlags"><span class="type">GLogLevelFlags</span></a>.These can be extended with user-defined levels.</p></div><div class="refsect1" lang="en"><a name="id2932768"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2932774"></a><h3><a name="G-LOG-DOMAIN:CAPS"></a>G_LOG_DOMAIN</h3><a class="indexterm" name="id2932785"></a><pre class="programlisting">#define G_LOG_DOMAIN    ((gchar*) 0)</pre><p>Defines the log domain.For applications, this is typically left as the default <code class="literal">NULL</code> (or "") domain.Libraries should define this so that any messages which they log canbe differentiated from messages from other libraries and application code.But be careful not to define it in any public header files.</p><p>For example, GTK+ uses this in its Makefile.am:</p><div class="informalexample"><pre class="programlisting">INCLUDES = -DG_LOG_DOMAIN=\"Gtk\"</pre></div></div><hr><div class="refsect2" lang="en"><a name="id2932823"></a><h3><a name="G-LOG-FATAL-MASK:CAPS"></a>G_LOG_FATAL_MASK</h3><a class="indexterm" name="id2932834"></a><pre class="programlisting">#define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)</pre><p>GLib log levels that are considered fatal by default.</p></div><hr><div class="refsect2" lang="en"><a name="id2932851"></a><h3><a name="G-LOG-LEVEL-USER-SHIFT:CAPS"></a>G_LOG_LEVEL_USER_SHIFT</h3><a class="indexterm" name="id2932862"></a><pre class="programlisting">#define G_LOG_LEVEL_USER_SHIFT  (8)</pre><p>Log level shift offset for user defined log levels (0-7 are used by GLib).</p></div><hr><div class="refsect2" lang="en"><a name="id2932879"></a><h3><a name="GLogFunc"></a>GLogFunc ()</h3><a class="indexterm" name="id2932889"></a><pre class="programlisting">void        (*GLogFunc)                     (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> user_data);</pre><p>Specifies the prototype of log handler functions.</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 log level of the message (including the fatal and recursionflags).</td></tr><tr><td><span class="term"><em class="parameter"><code>message</code></em>&#160;:</span></td><td>the message to process.</td></tr><tr><td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td><td>user data, set 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="id2933014"></a><h3><a name="GLogLevelFlags"></a>enum GLogLevelFlags</h3><a class="indexterm" name="id2933024"></a><pre class="programlisting">typedef enum{  /* log flags */  G_LOG_FLAG_RECURSION          = 1 &lt;&lt; 0,  G_LOG_FLAG_FATAL              = 1 &lt;&lt; 1,  /* GLib log levels */  G_LOG_LEVEL_ERROR             = 1 &lt;&lt; 2,       /* always fatal */  G_LOG_LEVEL_CRITICAL          = 1 &lt;&lt; 3,  G_LOG_LEVEL_WARNING           = 1 &lt;&lt; 4,  G_LOG_LEVEL_MESSAGE           = 1 &lt;&lt; 5,  G_LOG_LEVEL_INFO              = 1 &lt;&lt; 6,  G_LOG_LEVEL_DEBUG             = 1 &lt;&lt; 7,  G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)} GLogLevelFlags;</pre><p>Flags specifying the level of log messages.</p></div><hr><div class="refsect2" lang="en"><a name="id2933054"></a><h3><a name="g-log"></a>g_log ()</h3><a class="indexterm" name="id2933064"></a><pre class="programlisting">void        g_log                           (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> *format,                                             ...);</pre><p>Logs an error or debugging message.If the log level has been set as fatal, the <code class="function">abort()</code>function is called to terminate the program.</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, usually <a href="glib-Message-Logging.html#G-LOG-DOMAIN:CAPS"><span class="type">G_LOG_DOMAIN</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>log_level</code></em>&#160;:</span></td><td>the log level, either from <a href="glib-Message-Logging.html#GLogLevelFlags"><span class="type">GLogLevelFlags</span></a> or a user-defined level.</td></tr><tr><td><span class="term"><em class="parameter"><code>format</code></em>&#160;:</span></td><td>the message format. See the <code class="function">printf()</code>documentation.</td></tr><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="id2933211"></a><h3><a name="g-logv"></a>g_logv ()</h3><a class="indexterm" name="id2933221"></a><pre class="programlisting">void        g_logv                          (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> *format,                                             va_list args);</pre><p>Logs an error or debugging message.If the log level has been set as fatal, the <code class="function">abort()</code>function is called to terminate the program.</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>log_level</code></em>&#160;:</span></td><td>the log level.</td></tr><tr><td><span class="term"><em class="parameter"><code>format</code></em>&#160;:</span></td><td>the message format. See the <code class="function">printf()</code>documentation.</td></tr><tr><td><span class="term"><em class="parameter"><code>args</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="id2933356"></a><h3><a name="g-message"></a>g_message()</h3><a class="indexterm" name="id2933367"></a><pre class="programlisting">#define     g_message(...)</pre><p>A convenience function/macro to log a normal 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></div><hr><div class="refsect2" lang="en"><a name="id2933412"></a><h3><a name="g-warning"></a>g_warning()</h3><a class="indexterm" name="id2933422"></a><pre class="programlisting">#define     g_warning(...)</pre><p>A convenience function/macro to log a warning 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></div><hr><div class="refsect2" lang="en"><a name="id2933467"></a><h3><a name="g-critical"></a>g_critical()</h3><a class="indexterm" name="id2933478"></a><pre class="programlisting">#define     g_critical(...)</pre>

⌨️ 快捷键说明

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