[532] | 1 | /*
|
---|
| 2 | * Function to handle mondorescue messages
|
---|
| 3 | *
|
---|
| 4 | * $Id: libmondo-msg.c 1086 2007-02-02 22:21:27Z bruno $
|
---|
| 5 | *
|
---|
[1] | 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "my-stuff.h"
|
---|
| 9 |
|
---|
[532] | 10 | extern int g_main_pid;
|
---|
| 11 | extern int g_buffer_pid;
|
---|
[1] | 12 |
|
---|
| 13 | /**
|
---|
| 14 | * The default maximum level to log messages at or below.
|
---|
| 15 | */
|
---|
[783] | 16 | extern int g_loglevel;
|
---|
[1] | 17 |
|
---|
| 18 | /**
|
---|
[1086] | 19 | * The standard log_debug_msg() (mr_msg() also due to a macro). Writes some describing
|
---|
[1] | 20 | * information to the logfile.
|
---|
| 21 | */
|
---|
[532] | 22 | void log_debug_msg(int debug_level, const char *szFile,
|
---|
[128] | 23 | const char *szFunction, int nLine,
|
---|
| 24 | const char *fmt, ...)
|
---|
[1] | 25 | {
|
---|
[128] | 26 | va_list args;
|
---|
| 27 | int i;
|
---|
| 28 | static int depth = 0;
|
---|
| 29 | FILE *fout;
|
---|
[1] | 30 |
|
---|
[128] | 31 | if (depth > 5) {
|
---|
| 32 | depth--;
|
---|
| 33 | return;
|
---|
| 34 | }
|
---|
| 35 | depth++;
|
---|
[1] | 36 |
|
---|
[128] | 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..."); }
|
---|
[1] | 42 |
|
---|
[128] | 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);
|
---|
[1] | 58 |
|
---|
[128] | 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)
|
---|
[1] | 63 |
|
---|
[128] | 64 | va_end(args);
|
---|
| 65 | fprintf(fout, "\n");
|
---|
| 66 | paranoid_fclose(fout);
|
---|
| 67 | }
|
---|
| 68 | depth--;
|
---|
[1] | 69 | }
|
---|