QOF: Trace: Debugging support

QOF 0.7.5

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

Files | Macros | Typedefs | Enumerations | Functions
Trace: Debugging support
Query Object Framework

## Files
file | qoflog.h
| QOF error logging and tracing facility.

## Macros
#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)

## Detailed Description

## Macro Definition Documentation

#define DEBUG | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204

Print a debugging message

Definition at line 208 of file qoflog.h.

#define DEBUGCMD | ( |  | x | ) |

Value:
do { \
if (qof_log_check (log_module, QOF_LOG_DEBUG)) { \
(x); \
} \
} while (0)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204

Definition at line 244 of file qoflog.h.

#define ENTER | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204
qof_log_add_indent
void qof_log_add_indent(void)
Definition: qoflog.c:45

Print a function entry debugging message

Definition at line 217 of file qoflog.h.

#define FATAL | ( |  | format,
|  |  | args...
| ) |  |

Value:
do { \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, \
"Fatal Error: %s(): " format, FUNK , ## args); \
} while (0)

Log error/warning/info messages to stderr or to a file. This logging infrastructure is meant for validating the correctness of the execution of the code. 'Info' level messages help trace program flow. 'Error' messages are meant to indicate internal data inconsistencies.

Messages can be logged to stdout, stderr, or to any desired file.Log a fatal error

Definition at line 177 of file qoflog.h.

#define LEAVE | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204
qof_log_drop_indent
void qof_log_drop_indent(void)
Definition: qoflog.c:57

Print a function exit debugging message

Definition at line 227 of file qoflog.h.

#define LOG_LEVEL_LIST | ( |  | _ | ) |

Value:
_(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)

Definition at line 43 of file qoflog.h.

#define PERR | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204

Log a serious error

Definition at line 183 of file qoflog.h.

#define PINFO | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204

Print an informational note

Definition at line 199 of file qoflog.h.

#define PWARN | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204

Log a warning

Definition at line 191 of file qoflog.h.

#define TRACE | ( |  | format,
|  |  | args...
| ) |  |

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)
qof_log_check
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Definition: qoflog.c:204

Print a function trace debugging message

Definition at line 237 of file qoflog.h.

## Enumeration Type Documentation

enum QofLogLevel

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.

Definition at line 58 of file qoflog.h.

179 { \

## Function Documentation

void qof_log_add_indent | ( | void |  | ) |

indents once for each ENTER macro

Definition at line 45 of file qoflog.c.

49 {

gboolean qof_log_check | ( | QofLogModule | log_module,
|  | QofLogLevel | log_level
| ) |  |

Do not log log_modules that have not been enabled.

Definition at line 204 of file qoflog.c.

208 {
209 gchar *log_string;
210 /* Any positive log_level less than this will be logged. */
211 QofLogLevel maximum;
212
213 log_string = NULL;
214 if (log_level > QOF_LOG_TRACE)
215 log_level = QOF_LOG_TRACE;
216 if (!log_table || log_module == NULL)
217 {
218 return FALSE;
219 }
220 log_string = (gchar *) g_hash_table_lookup (log_table, log_module);
221 /* if log_module not found, do not log. */
222 if (!log_string)
223 {
224 return FALSE;
225 }
226 maximum = QofLogLevelfromString (log_string);
227 if (log_level <= maximum)
228 {
229 return TRUE;
QofLogLevel
QofLogLevel
Definition: qoflog.h:58
QofLogLevelfromString
QofLogLevel QofLogLevelfromString(const gchar *str)
Definition: qoflog.c:45

void qof_log_drop_indent | ( | void |  | ) |

drops back one indent for each LEAVE macro

indent is reset to zero if less than a single indent would exist.

Definition at line 57 of file qoflog.c.

61 {

gint qof_log_get_indent | ( | void |  | ) |

gets the running total of the indent

Definition at line 51 of file qoflog.c.

55 {

void qof_log_init | ( | void |  | ) |

Initialize the error logging subsystem

Deprecated:
  Applications need to call qof_log_set_file to set the output, otherwise the default of /tmp/qof.trace will be used.

Instead, use qof_log_init_filename which sets the filename and initialises the logging subsystem in one operation.

Definition at line 74 of file qoflog.c.

78 {
79 if (!fout) /* allow qof_log_set_file */
80 {
81 fout = fopen ("/tmp/qof.trace", "w");
82 }
83
84 if (!fout && (filename = (gchar *) g_malloc (MAX_TRACE_FILENAME)))
85 {
86 snprintf (filename, MAX_TRACE_FILENAME - 1, "/tmp/qof.trace.%d",
87 getpid ());
88 fout = fopen (filename, "w");
89 g_free (filename);
90 }
91
92 if (!fout)
93 fout = stderr;

void qof_log_init_filename | ( | const gchar * | logfilename | ) |

Specify a filename for log output.

Calls qof_log_init() for you.

Definition at line 144 of file qoflog.c.

148 {
149 if (!logfilename)
150 {
151 fout = stderr;
152 }
153 else
154 {
155 filename = g_strdup (logfilename);
156 fout = fopen (filename, "w");

gint qof_log_module_count | ( | void |  | ) |

Number of log_modules registered

Definition at line 287 of file qoflog.c.

291 {
292 if (!log_table)
293 {
294 return 0;

void qof_log_module_foreach | ( | QofLogCB | cb,
|  | gpointer | data
| ) |  |

Iterate over each known log_module

Only log_modules with log_levels set will be available.

Definition at line 273 of file qoflog.c.

277 {
278 struct hash_s qiter;
279
280 if (!cb)
281 {
282 return;
283 }
284 qiter.cb = cb;

const gchar* qof_log_prettify | ( | const gchar * | name | ) |

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 177 of file qoflog.c.

181 {
182 gchar *p, *buffer;
183 gint length;
184
185 if (!name)
186 {
187 return "";
188 }
189 buffer = g_strndup (name, QOF_LOG_MAX_CHARS - 1);
190 length = strlen (buffer);
191 p = g_strstr_len (buffer, length, "(");
192 if (p)
193 {
194 *(p + 1) = ')';
195 *(p + 2) = 0x0;
196 }
197 else
198 {
199 strcpy (&buffer[QOF_LOG_MAX_CHARS - 4], "...()");
200 }
201 function_buffer = g_strdup (buffer);

void qof_log_set_default | ( | QofLogLevel | log_level | ) |

Set the default QOF log_modules to the log level.

Definition at line 232 of file qoflog.c.

236 {
237 qof_log_set_level (QOF_MOD_BACKEND, log_level);
238 qof_log_set_level (QOF_MOD_CLASS, log_level);
239 qof_log_set_level (QOF_MOD_ENGINE, log_level);
240 qof_log_set_level (QOF_MOD_OBJECT, log_level);
241 qof_log_set_level (QOF_MOD_KVP, log_level);
242 qof_log_set_level (QOF_MOD_MERGE, log_level);
243 qof_log_set_level (QOF_MOD_QUERY, log_level);
244 qof_log_set_level (QOF_MOD_SESSION, log_level);
245 qof_log_set_level (QOF_MOD_CHOICE, log_level);
246 qof_log_set_level (QOF_MOD_UTIL, log_level);
247 qof_log_set_level (QOF_MOD_TIME, log_level);
248 qof_log_set_level (QOF_MOD_DATE, log_level);
249 qof_log_set_level (QOF_MOD_UNDO, log_level);
250 qof_log_set_level (QOF_MOD_ERROR, log_level);
251 qof_log_set_level (QOF_MOD_QSF, log_level);
QOF_MOD_TIME
#define QOF_MOD_TIME
Definition: qoftime.h:94
QOF_MOD_DATE
#define QOF_MOD_DATE
Definition: qofdate.h:98
QOF_MOD_ERROR
#define QOF_MOD_ERROR
Definition: qoferror.h:121
qof_log_set_level
void qof_log_set_level(QofLogModule log_module, QofLogLevel level)
Definition: qoflog.c:96

void qof_log_set_file | ( | FILE * | outfile | ) |

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()

Deprecated:

Definition at line 133 of file qoflog.c.

137 {
138 if (!outfile)
139 {
140 fout = stderr;
141 return;

void qof_log_set_level | ( | QofLogModule | module,
|  | QofLogLevel | level
| ) |  |

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 96 of file qoflog.c.

100 {
101 gchar *level_string;
102
103 if (!log_module || level == 0)
104 {
105 return;
106 }
107 level_string = g_strdup (QofLogLevelasString (level));
108 if (!log_table)
109 {
110 log_table = g_hash_table_new (g_str_hash, g_str_equal);
QofLogLevelasString
const gchar * QofLogLevelasString(QofLogLevel n)
Definition: qoflog.c:45

void qof_log_set_level_registered | ( | QofLogLevel | level | ) |

Set the logging level for all registered log_modules.

Note
  Unless a log_module has been registered using qof_log_set_level, it will be unaffected by this change because there will be no entry in the hashtable.

"silent" log_modules are supported by the qof_log_set_level_registered function which only moderates log_levels for those modules actually registered. The advantage is that a developer can omit existing log_modules from the init code and cut down the amount of unwanted logging.

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 120 of file qoflog.c.

124 {
125 gchar *level_string;
126
127 if (!log_table || level == 0)
128 {
129 return;
130 }

void qof_log_shutdown | ( | void |  | ) |

Be nice, close the logfile if possible.

Definition at line 159 of file qoflog.c.

163 {
164 if (fout && fout != stderr)
165 {
166 fclose (fout);
167 }
168 if (filename)
169 {
170 g_free (filename);
171 }
172 if (function_buffer)
173 {
174 g_free (function_buffer);

const gchar* QofLogLevelasString | ( | QofLogLevel | n | ) |

Convert a QofLogLevel to the log_string

Only for use as a partner to QofLogLevelfromString

Definition at line 45 of file qoflog.c.

49 {

QofLogLevel QofLogLevelfromString | ( | const gchar * | str | ) |

Convert the log_string to a QofLogLevel

Only for use as a partner to QofLogLevelasString

Definition at line 45 of file qoflog.c.

49 {