GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Functions

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)
 
void xaccLogDisable (void)
 
void xaccLogSetBaseName (const char *)
 
gboolean xaccFileIsCurrentLog (const gchar *name)
 

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

gboolean xaccFileIsCurrentLog ( const gchar *  name)

Test a filename to see if it is the name of the current logfile

Definition at line 139 of file TransLog.c.

140 {
141  gchar *base;
142  gint result;
143 
144  if (!name || !trans_log_name)
145  return FALSE;
146 
147  base = g_path_get_basename(name);
148  result = (strcmp(base, trans_log_name) == 0);
149  g_free(base);
150  return result;
151 }
void xaccLogDisable ( void  )

document me

Definition at line 93 of file TransLog.c.

94 {
95  gen_logs = 0;
96 }
void xaccLogEnable ( void  )

document me

Definition at line 97 of file TransLog.c.

98 {
99  gen_logs = 1;
100 }
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 117 of file TransLog.c.

118 {
119  if (!basepath) return;
120 
121  g_free (log_base_name);
122  log_base_name = g_strdup (basepath);
123 
124  if (trans_log)
125  {
126  xaccCloseLog();
127  xaccOpenLog();
128  }
129 }
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 221 of file TransLog.c.

222 {
223  GList *node;
224  char trans_guid_str[GUID_ENCODING_LENGTH + 1];
225  char split_guid_str[GUID_ENCODING_LENGTH + 1];
226  const char *trans_notes;
227  char dnow[100], dent[100], dpost[100], drecn[100];
228  Timespec ts;
229 
230  if (!gen_logs)
231  {
232  PINFO ("Attempt to write disabled transaction log");
233  return;
234  }
235  if (!trans_log) return;
236 
237  timespecFromTime64(&ts, gnc_time (NULL));
238  gnc_timespec_to_iso8601_buff (ts, dnow);
239 
240  timespecFromTime64(&ts, trans->date_entered.tv_sec);
241  gnc_timespec_to_iso8601_buff (ts, dent);
242 
243  timespecFromTime64(&ts, trans->date_posted.tv_sec);
244  gnc_timespec_to_iso8601_buff (ts, dpost);
245 
246  guid_to_string_buff (xaccTransGetGUID(trans), trans_guid_str);
247  trans_notes = xaccTransGetNotes(trans);
248  fprintf (trans_log, "===== START\n");
249 
250  for (node = trans->splits; node; node = node->next)
251  {
252  Split *split = node->data;
253  const char * accname = "";
254  char acc_guid_str[GUID_ENCODING_LENGTH + 1];
255  gnc_numeric amt, val;
256 
257  if (xaccSplitGetAccount(split))
258  {
259  accname = xaccAccountGetName (xaccSplitGetAccount(split));
261  acc_guid_str);
262  }
263  else
264  {
265  acc_guid_str[0] = '\0';
266  }
267 
268  timespecFromTime64(&ts, split->date_reconciled.tv_sec);
269  gnc_timespec_to_iso8601_buff (ts, drecn);
270 
271  guid_to_string_buff (xaccSplitGetGUID(split), split_guid_str);
272  amt = xaccSplitGetAmount (split);
273  val = xaccSplitGetValue (split);
274 
275  /* use tab-separated fields */
276  fprintf (trans_log,
277  "%c\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t"
278  "%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",
279  flag,
280  trans_guid_str, split_guid_str, /* trans+split make up unique id */
281  /* Note that the next three strings always exist,
282  * so we don't need to test them. */
283  dnow,
284  dent,
285  dpost,
286  acc_guid_str,
287  accname ? accname : "",
288  trans->num ? trans->num : "",
289  trans->description ? trans->description : "",
290  trans_notes ? trans_notes : "",
291  split->memo ? split->memo : "",
292  split->action ? split->action : "",
293  split->reconciled,
294  gnc_numeric_num(amt),
295  gnc_numeric_denom(amt),
296  gnc_numeric_num(val),
297  gnc_numeric_denom(val),
298  /* The next string always exists. No need to test it. */
299  drecn);
300  }
301 
302  fprintf (trans_log, "===== END\n");
303 
304  /* get data out to the disk */
305  fflush (trans_log);
306 }
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
#define PINFO(format, args...)
Definition: qoflog.h:249
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
const char * xaccTransGetNotes(const Transaction *trans)
Definition: Transaction.c:2197
#define xaccAccountGetGUID(X)
Definition: Account.h:239
#define GUID_ENCODING_LENGTH
Definition: guid.h:74
#define xaccSplitGetGUID(X)
Definition: Split.h:521
#define xaccTransGetGUID(X)
Definition: Transaction.h:755
Definition: SplitP.h:71
gnc_numeric xaccSplitGetValue(const Split *split)
Definition: Split.c:1993
Account * xaccSplitGetAccount(const Split *s)
Definition: Split.c:968
time64 gnc_time(time64 *tbuf)
get the current local time
const char * xaccAccountGetName(const Account *acc)
Definition: Account.c:3031
gnc_numeric xaccSplitGetAmount(const Split *split)
Definition: Split.c:1987
void timespecFromTime64(Timespec *ts, time64 t)