source: MondoRescue/trunk/mondo/mondo/common/libmondo-msg.c@ 783

Last change on this file since 783 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
RevLine 
[532]1/*
2 * Function to handle mondorescue messages
3 *
4 * $Id: libmondo-msg.c 783 2006-08-31 15:09:20Z bruno $
5 *
[1]6 */
7
8#include "my-stuff.h"
9
[532]10extern int g_main_pid;
11extern int g_buffer_pid;
[1]12
13/**
14 * The default maximum level to log messages at or below.
15 */
[783]16extern int g_loglevel;
[1]17
18/**
19 * The standard log_debug_msg() (log_msg() also due to a macro). Writes some describing
20 * information to the logfile.
21 */
[532]22void 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}
Note: See TracBrowser for help on using the repository browser.