source: MondoRescue/trunk/mondo/mondo/src/libmondo-msg.c@ 795

Last change on this file since 795 was 783, checked in by Bruno Cornec, 18 years ago
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1/*
2 * Function to handle mondorescue messages
3 *
4 * $Id: libmondo-msg.c 783 2006-08-31 15:09:20Z bruno $
5 *
6 */
7
8#include "my-stuff.h"
9
10extern int g_main_pid;
11extern int g_buffer_pid;
12
13/**
14 * The default maximum level to log messages at or below.
15 */
16extern int g_loglevel;
17
18/**
19 * The standard log_debug_msg() (log_msg() also due to a macro). Writes some describing
20 * information to the logfile.
21 */
22void log_debug_msg(int debug_level, const char *szFile,
23 const char *szFunction, int nLine,
24 const char *fmt, ...)
25{
26 va_list args;
27 int i;
28 static int depth = 0;
29 FILE *fout;
30
31 if (depth > 5) {
32 depth--;
33 return;
34 }
35 depth++;
36
37 if (debug_level <= g_loglevel) {
38 va_start(args, fmt);
39 if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
40 return;
41 } // fatal_error("Failed to openout to logfile - sheesh..."); }
42
43 // add tabs to distinguish log levels
44 if (debug_level > 0) {
45 for (i = 1; i < debug_level; i++)
46 fprintf(fout, "\t");
47 if (getpid() == g_main_pid)
48 fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction,
49 nLine);
50 else if (getpid() == g_buffer_pid && g_buffer_pid > 0)
51 fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction,
52 nLine);
53 else
54 fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile,
55 szFunction, nLine);
56 }
57 vfprintf(fout, fmt, args);
58
59 // do not slow down the progran if standard debug level
60 // must be enabled: if no flush, the log won't be up-to-date if there
61 // is a segfault
62 //if (g_dwDebugLevel != 1)
63
64 va_end(args);
65 fprintf(fout, "\n");
66 paranoid_fclose(fout);
67 }
68 depth--;
69}
Note: See TracBrowser for help on using the repository browser.