Last change
on this file since 1047 was 900, checked in by Bruno Cornec, 18 years ago |
Huge patch to introduce low level functions that will bw used everywhere (mr_free, mr_asprintf, ...)
Nearly linking now due to that.
|
-
Property svn:eol-style
set to
native
|
File size:
1.1 KB
|
Rev | Line | |
---|
[900] | 1 | /*
|
---|
| 2 | * $Id$
|
---|
| 3 | *
|
---|
| 4 | * Code (c)2006 Bruno Cornec <bruno@mondorescue.org>
|
---|
| 5 | *
|
---|
| 6 | * Main file of mr_msg : a very small and simple
|
---|
| 7 | * library for messages management
|
---|
| 8 | *
|
---|
| 9 | * Provided under the GPLv2
|
---|
| 10 | */
|
---|
| 11 |
|
---|
| 12 | #include <stdio.h>
|
---|
| 13 | #include <stdarg.h>
|
---|
| 14 |
|
---|
| 15 | static int mr_loglevel = 0;
|
---|
| 16 | static char *mr_logfile = NULL;
|
---|
| 17 |
|
---|
| 18 | /* Initialization function for messages */
|
---|
| 19 | void mr_msg_init(void) {
|
---|
| 20 |
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * Function that log a message. Not called directly
|
---|
| 25 | * but through macros in mr_msg.h
|
---|
| 26 | */
|
---|
| 27 | void _mr_msg(int debug, const char *file, const char *function, int line, const char *fmt, ...) {
|
---|
| 28 |
|
---|
| 29 | va_list args;
|
---|
| 30 | int i = 0;
|
---|
| 31 | int res = 0;
|
---|
| 32 | FILE *fout = NULL;
|
---|
| 33 |
|
---|
| 34 | if (debug <= mr_loglevel) {
|
---|
| 35 | va_start(args, fmt);
|
---|
| 36 | if (!(fout = fopen(mr_logfile, "a"))) {
|
---|
| 37 | fprintf(stderr,"Unable to append to %s\n",mr_logfile);
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | // add 2 spaces to distinguish log levels
|
---|
| 42 | if (debug > 0) {
|
---|
| 43 | for (i = 1; i < debug; i++)
|
---|
| 44 | fprintf(fout, " ");
|
---|
| 45 | fprintf(fout, "%s->%s#%d: ", file, function, line);
|
---|
| 46 | }
|
---|
| 47 | vfprintf(fout, fmt, args);
|
---|
| 48 |
|
---|
| 49 | va_end(args);
|
---|
| 50 | fprintf(fout, "\n");
|
---|
| 51 | if ((res = fclose(fout)) != 0) {
|
---|
| 52 | fprintf(stderr,"Unable to close %s\n",mr_logfile);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.