Files | |
file | qoflog.h |
QOF error logging and tracing facility. | |
Defines | |
#define | QOF_MOD_ENGINE "qof-engine" |
#define | LOG_LEVEL_LIST(_) |
#define | FUNK qof_log_prettify(__FUNCTION__) |
#define | FATAL(format, args...) |
#define | PERR(format, args...) |
#define | PWARN(format, args...) |
#define | PINFO(format, args...) |
#define | DEBUG(format, args...) |
#define | ENTER(format, args...) |
#define | LEAVE(format, args...) |
#define | TRACE(format, args...) |
#define | DEBUGCMD(x) |
Typedefs | |
typedef void(* | QofLogCB )(QofLogModule log_module, QofLogLevel *log_level, gpointer user_data) |
Enumerations | |
enum | QofLogLevel { QOF_LOG_FATAL = 0, QOF_LOG_ERROR = 1, QOF_LOG_WARNING = 2, QOF_LOG_INFO = 3, QOF_LOG_DEBUG = 4, QOF_LOG_DETAIL = 5, QOF_LOG_TRACE = 6 } |
Functions | |
const gchar * | QofLogLevelasString (QofLogLevel n) |
QofLogLevel | QofLogLevelfromString (const gchar *str) |
void | qof_log_add_indent (void) |
gint | qof_log_get_indent (void) |
void | qof_log_drop_indent (void) |
void | qof_log_init (void) |
void | qof_log_set_level (QofLogModule module, QofLogLevel level) |
void | qof_log_set_level_registered (QofLogLevel level) |
void | qof_log_set_file (FILE *outfile) |
void | qof_log_init_filename (const gchar *logfilename) |
void | qof_log_shutdown (void) |
const gchar * | qof_log_prettify (const gchar *name) |
gboolean | qof_log_check (QofLogModule log_module, QofLogLevel log_level) |
void | qof_log_set_default (QofLogLevel log_level) |
void | qof_log_module_foreach (QofLogCB cb, gpointer data) |
gint | qof_log_module_count (void) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_DEBUG)) { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ "Debug: %s(): " format, \ FUNK , ## args); \ } \ } while (0) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_DEBUG)) { \ (x); \ } \ } while (0) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_DEBUG)) { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ "Enter in %s: %s()" format, __FILE__, \ FUNK , ## args); \ qof_log_add_indent(); \ } \ } while (0) |
|
Value: do { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, \ "Fatal Error: %s(): " format, FUNK , ## args); \ } while (0) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_DEBUG)) { \ qof_log_drop_indent(); \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ "Leave: %s()" format, \ FUNK , ## args); \ } \ } while (0) |
|
Value: |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_ERROR)) { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, \ "Error: %s(): " format, FUNK , ## args); \ } \ } while (0) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_INFO)) { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, \ "Info: %s(): " format, \ FUNK , ## args); \ } \ } while (0) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_WARNING)) { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, \ "Warning: %s(): " format, FUNK , ## args); \ } \ } while (0) |
|
Value: do { \ if (qof_log_check (log_module, QOF_LOG_TRACE)) { \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ "Trace: %s(): " format, FUNK , ## args); \ } \ } while (0) |
|
Convert QofLogLevel to a string. The macro correlates the enum value and an exact copy as a string, removing the need to keep two separate lists in sync. |
|
indents once for each ENTER macro Definition at line 48 of file qoflog.c.
|
|
Do not log log_modules that have not been enabled. Definition at line 205 of file qoflog.c. 00206 { 00207 gchar *log_string; 00208 /* Any positive log_level less than this will be logged. */ 00209 QofLogLevel maximum; 00210 00211 log_string = NULL; 00212 if (log_level > QOF_LOG_TRACE) 00213 log_level = QOF_LOG_TRACE; 00214 if (!log_table || log_module == NULL || log_level < 0) 00215 { 00216 return FALSE; 00217 } 00218 log_string = (gchar *) g_hash_table_lookup (log_table, log_module); 00219 /* if log_module not found, do not log. */ 00220 if (!log_string) 00221 { 00222 return FALSE; 00223 } 00224 maximum = QofLogLevelfromString (log_string); 00225 if (log_level <= maximum) 00226 { 00227 return TRUE; 00228 } 00229 return FALSE; 00230 }
|
|
drops back one indent for each LEAVE macro indent is reset to zero if less than a single indent would exist. Definition at line 60 of file qoflog.c. 00061 { 00062 qof_log_num_spaces = (qof_log_num_spaces < QOF_LOG_INDENT_WIDTH) ? 00063 0 : qof_log_num_spaces - QOF_LOG_INDENT_WIDTH; 00064 }
|
|
gets the running total of the indent Definition at line 54 of file qoflog.c.
|
|
Initialize the error logging subsystem
Definition at line 76 of file qoflog.c. 00077 { 00078 if (!fout) /* allow qof_log_set_file */ 00079 { 00080 fout = fopen ("/tmp/qof.trace", "w"); 00081 } 00082 00083 if (!fout && (filename = (gchar *) g_malloc (MAX_TRACE_FILENAME))) 00084 { 00085 snprintf (filename, MAX_TRACE_FILENAME - 1, "/tmp/qof.trace.%d", 00086 getpid ()); 00087 fout = fopen (filename, "w"); 00088 g_free (filename); 00089 } 00090 00091 if (!fout) 00092 fout = stderr; 00093 00094 g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, fh_printer, fout); 00095 }
|
|
Specify a filename for log output. Calls qof_log_init() for you. Definition at line 145 of file qoflog.c. 00146 { 00147 if (!logfilename) 00148 { 00149 fout = stderr; 00150 } 00151 else 00152 { 00153 filename = g_strdup (logfilename); 00154 fout = fopen (filename, "w"); 00155 } 00156 qof_log_init (); 00157 }
|
|
Number of log_modules registered Definition at line 284 of file qoflog.c. 00285 { 00286 if (!log_table) 00287 { 00288 return 0; 00289 } 00290 return g_hash_table_size (log_table); 00291 }
|
|
Iterate over each known log_module Only log_modules with log_levels set will be available. Definition at line 270 of file qoflog.c. 00271 { 00272 struct hash_s qiter; 00273 00274 if (!cb) 00275 { 00276 return; 00277 } 00278 qiter.cb = cb; 00279 qiter.data = data; 00280 g_hash_table_foreach (log_table, hash_cb, (gpointer) &qiter); 00281 }
|
|
qof_log_prettify() cleans up subroutine names. AIX/xlC has the habit of printing signatures not names; clean this up. On other operating systems, truncate name to QOF_LOG_MAX_CHARS chars. Definition at line 178 of file qoflog.c. 00179 { 00180 gchar *p, *buffer; 00181 gint length; 00182 00183 if (!name) 00184 { 00185 return ""; 00186 } 00187 buffer = g_strndup (name, QOF_LOG_MAX_CHARS - 1); 00188 length = strlen (buffer); 00189 p = g_strstr_len (buffer, length, "("); 00190 if (p) 00191 { 00192 *(p + 1) = ')'; 00193 *(p + 2) = 0x0; 00194 } 00195 else 00196 { 00197 strcpy (&buffer[QOF_LOG_MAX_CHARS - 4], "...()"); 00198 } 00199 function_buffer = g_strdup (buffer); 00200 g_free (buffer); 00201 return function_buffer; 00202 }
|
|
Set the default QOF log_modules to the log level. Definition at line 233 of file qoflog.c. 00234 { 00235 qof_log_set_level (QOF_MOD_BACKEND, log_level); 00236 qof_log_set_level (QOF_MOD_CLASS, log_level); 00237 qof_log_set_level (QOF_MOD_ENGINE, log_level); 00238 qof_log_set_level (QOF_MOD_OBJECT, log_level); 00239 qof_log_set_level (QOF_MOD_KVP, log_level); 00240 qof_log_set_level (QOF_MOD_MERGE, log_level); 00241 qof_log_set_level (QOF_MOD_QUERY, log_level); 00242 qof_log_set_level (QOF_MOD_SESSION, log_level); 00243 qof_log_set_level (QOF_MOD_CHOICE, log_level); 00244 qof_log_set_level (QOF_MOD_UTIL, log_level); 00245 qof_log_set_level (QOF_MOD_TIME, log_level); 00246 qof_log_set_level (QOF_MOD_DATE, log_level); 00247 qof_log_set_level (QOF_MOD_UNDO, log_level); 00248 }
|
|
Specify an alternate log output, to pipe or file. By default, all logging goes to /tmp/qof.trace Needs to be called before qof_log_init() Definition at line 134 of file qoflog.c. 00135 { 00136 if (!outfile) 00137 { 00138 fout = stderr; 00139 return; 00140 } 00141 fout = outfile; 00142 }
|
|
Set the logging level of the given log_module. Registers the log_module with the qof_log hashtable and sets an initial value for the loglevel for that log_module. Definition at line 98 of file qoflog.c. 00099 { 00100 gchar *level_string; 00101 00102 if (!log_module || level == 0) 00103 { 00104 return; 00105 } 00106 level_string = g_strdup (QofLogLevelasString (level)); 00107 if (!log_table) 00108 { 00109 log_table = g_hash_table_new (g_str_hash, g_str_equal); 00110 } 00111 g_hash_table_insert (log_table, (gpointer) log_module, level_string); 00112 }
|
|
Set the logging level for all registered log_modules.
e.g. if you are working in one section of the code and do not want the extra log information created by allowing the default modules to log as well. This makes the log itself easier to use when working in a small area of the codebase. Silent log_modules can also be useful where no default currently exists - again to isolate certain sections of the default log output - and using qof_log_set_level_registered allows these silent log_modules to be retained in the code without being logged by other developers etc. Definition at line 121 of file qoflog.c. 00122 { 00123 gchar *level_string; 00124 00125 if (!log_table || level == 0) 00126 { 00127 return; 00128 } 00129 level_string = g_strdup (QofLogLevelasString (level)); 00130 g_hash_table_foreach (log_table, log_module_foreach, level_string); 00131 }
|
|
Be nice, close the logfile if possible. Definition at line 160 of file qoflog.c. 00161 { 00162 if (fout && fout != stderr) 00163 { 00164 fclose (fout); 00165 } 00166 if (filename) 00167 { 00168 g_free (filename); 00169 } 00170 if (function_buffer) 00171 { 00172 g_free (function_buffer); 00173 } 00174 g_hash_table_destroy (log_table); 00175 }
|
|
Convert a QofLogLevel to the log_string Only for use as a partner to QofLogLevelfromString Definition at line 45 of file qoflog.c.
|
|
Convert the log_string to a QofLogLevel Only for use as a partner to QofLogLevelasString Definition at line 46 of file qoflog.c.
|