GnuCash  4.8a-132-gcdaeb421d+
Files | Functions

The transaction logging mechanism provides a very simple, low-level logging of user input to a file. More...

Files

file  TransLog.h
 API for the transaction logger.
 

Functions

void xaccOpenLog (void)
 
void xaccCloseLog (void)
 
void xaccReopenLog (void)
 
void xaccTransWriteLog (Transaction *trans, char flag)
 
void xaccLogEnable (void)
 document me
 
void xaccLogDisable (void)
 document me
 
void xaccLogSetBaseName (const char *)
 The xaccLogSetBaseName() method sets the base filepath and the root part of the journal file name. More...
 
gboolean xaccFileIsCurrentLog (const gchar *name)
 Test a filename to see if it is the name of the current logfile.
 

Detailed Description

The transaction logging mechanism provides a very simple, low-level logging of user input to a file.

The goal of the transaction logger is to provide mechanism of last resort for recovering lost user data in the event of a crash.

Ideally, the storage backends should provide a robust journaling, logging and crash-recovery mechanism. But just in case they don't, or it didn't work, this mechanism provides a "Plan B" by providing a low-tech, fool-proof, simple logging system that can be used to recover user input. There are some simple command-line tools that will read a log and replay it.

Function Documentation

◆ xaccLogSetBaseName()

void xaccLogSetBaseName ( const char *  )

The xaccLogSetBaseName() method sets the base filepath and the root part of the journal file name.

If the journal file is already open, it will close it and reopen it with the new base name.

Definition at line 119 of file TransLog.c.

120 {
121  if (!basepath) return;
122 
123  g_free (log_base_name);
124  log_base_name = g_strdup (basepath);
125 
126  if (trans_log)
127  {
128  xaccCloseLog();
129  xaccOpenLog();
130  }
131 }

◆ xaccTransWriteLog()

void xaccTransWriteLog ( Transaction *  trans,
char  flag 
)
Parameters
transThe transaction to write out to the log
flagThe engine currently uses the log mechanism with flag char set as follows: 'B' for 'begin edit' (followed by the transaction as it looks before any changes, i.e. the 'old value') 'D' for delete (i.e. delete the previous B; echoes the data in the 'old B') 'C' for commit (i.e. accept a previous B; data that follows is the 'new value') 'R' for rollback (i.e. revert to previous B; data that follows should be identical to old B)

Definition at line 223 of file TransLog.c.

224 {
225  GList *node;
226  char trans_guid_str[GUID_ENCODING_LENGTH + 1];
227  char split_guid_str[GUID_ENCODING_LENGTH + 1];
228  const char *trans_notes;
229  char dnow[100], dent[100], dpost[100], drecn[100];
230 
231  if (!gen_logs)
232  {
233  PINFO ("Attempt to write disabled transaction log");
234  return;
235  }
236  if (!trans_log) return;
237 
238  gnc_time64_to_iso8601_buff (gnc_time(NULL), dnow);
239  gnc_time64_to_iso8601_buff (trans->date_entered, dent);
240  gnc_time64_to_iso8601_buff (trans->date_posted, dpost);
241  guid_to_string_buff (xaccTransGetGUID(trans), trans_guid_str);
242  trans_notes = xaccTransGetNotes(trans);
243  fprintf (trans_log, "===== START\n");
244 
245  for (node = trans->splits; node; node = node->next)
246  {
247  time64 time;
248  Split *split = node->data;
249  const char * accname = "";
250  char acc_guid_str[GUID_ENCODING_LENGTH + 1];
251  gnc_numeric amt, val;
252 
253  if (xaccSplitGetAccount(split))
254  {
255  accname = xaccAccountGetName (xaccSplitGetAccount(split));
257  acc_guid_str);
258  }
259  else
260  {
261  acc_guid_str[0] = '\0';
262  }
263 
264  gnc_time64_to_iso8601_buff (split->date_reconciled, drecn);
265 
266  guid_to_string_buff (xaccSplitGetGUID(split), split_guid_str);
267  amt = xaccSplitGetAmount (split);
268  val = xaccSplitGetValue (split);
269 
270  /* use tab-separated fields */
271  fprintf (trans_log,
272  "%c\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t"
273  "%s\t%s\t%s\t%s\t%c\t%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT "\t%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT "\t%s\n",
274  flag,
275  trans_guid_str, split_guid_str, /* trans+split make up unique id */
276  /* Note that the next three strings always exist,
277  * so we don't need to test them. */
278  dnow,
279  dent,
280  dpost,
281  acc_guid_str,
282  accname ? accname : "",
283  trans->num ? trans->num : "",
284  trans->description ? trans->description : "",
285  trans_notes ? trans_notes : "",
286  split->memo ? split->memo : "",
287  split->action ? split->action : "",
288  split->reconciled,
289  gnc_numeric_num(amt),
290  gnc_numeric_denom(amt),
291  gnc_numeric_num(val),
292  gnc_numeric_denom(val),
293  /* The next string always exists. No need to test it. */
294  drecn);
295  }
296 
297  fprintf (trans_log, "===== END\n");
298 
299  /* get data out to the disk */
300  fflush (trans_log);
301 }
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
Definition: guid.cpp:174
const char * xaccTransGetNotes(const Transaction *trans)
Gets the transaction Notes.
#define xaccAccountGetGUID(X)
Definition: Account.h:248
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition: guid.h:84
#define xaccSplitGetGUID(X)
Definition: Split.h:554
#define xaccTransGetGUID(X)
Definition: Transaction.h:785
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Definition: gmock-Split.cpp:84
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
time64 gnc_time(time64 *tbuf)
get the current local time
Definition: gnc-date.cpp:273
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition: Account.cpp:3258
char * gnc_time64_to_iso8601_buff(time64 time, char *buff)
The gnc_time64_to_iso8601_buff() routine takes the input UTC time64 value and prints it as an ISO-860...
Definition: gnc-date.cpp:1142
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition: gmock-Split.cpp:69