The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
log.h
Go to the documentation of this file.
1 /* This file is part of Netsukuku system
2  * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3  *
4  * This source code is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * This source code is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * Please refer to the GNU Public License for more details.
13  *
14  * You should have received a copy of the GNU Public License along with
15  * this source code; if not, write to:
16  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef LOG_H
20 #define LOG_H
21 
22 #include <stdarg.h>
23 
24 /*
25  * Use ERROR_MSG and ERROR_POS in this way:
26  * printf(ERROR_MSG "damn! damn! damn!", ERROR_POS);
27  * printf(ERROR_MSG "damn! damn! damn!", ERROR_FUNC);
28  */
29 #define ERROR_MSG "%s:%d: "
30 #define ERROR_POS __FILE__, __LINE__
31 #define ERROR_FUNC __FUNCTION__, __LINE__
32 
33 /*Debug levels*/
34 #define DBG_NORMAL 1
35 #define DBG_SOFT 2
36 #define DBG_NOISE 3
37 #define DBG_INSANE 4
38 
39 /*
40  * ERROR_FINISH:
41  * A kind way to say all was messed up, take this example:
42  *
43  * int func(void) // returns -1 on errors
44  * {
45  * int ret=0;
46  *
47  * ,,,BLA BLA...
48  *
49  * if(error_condition)
50  * ERROR_FINISH(ret, -1, finish);
51  *
52  * error_condition &&
53  * ERROR_FINISH(ret, -1, finish);
54  *
55  * ,,,BLA BLA...
56  *
57  * finish:
58  * return ret;
59  * }
60  */
61 #define ERROR_FINISH(ret, err, label_finish) \
62 ({ \
63  void *_label_finish=&&label_finish; \
64  (ret)=(err); \
65  goto *_label_finish; \
66  \
67  (ret); /* in this way gcc thinks this macro returns
68  an integer */ \
69 })
70 
71 #ifdef DEBUG
72 /* Colors used to highlights things while debugging ;) */
73 #define DEFCOL "\033[0m"
74 #define BLACK(x) "\033[0;30m" x DEFCOL
75 #define RED(x) "\033[0;31m" x DEFCOL
76 #define GREEN(x) "\033[0;32m" x DEFCOL
77 #define BROWN(x) "\033[0;33m" x DEFCOL
78 #define BLUE(x) "\033[0;34m" x DEFCOL
79 #define PURPLE(x) "\033[0;35m" x DEFCOL
80 #define CYAN(x) "\033[0;36m" x DEFCOL
81 #define LIGHTGRAY(x) "\033[0;37m" x DEFCOL
82 #define DARKGRAY(x) "\033[1;30m" x DEFCOL
83 #define LIGHTRED(x) "\033[1;31m" x DEFCOL
84 #define LIGHTGREEN(x) "\033[1;32m" x DEFCOL
85 #define YELLOW(x) "\033[1;33m" x DEFCOL
86 #define LIGHTBLUE(x) "\033[1;34m" x DEFCOL
87 #define MAGENTA(x) "\033[1;35m" x DEFCOL
88 #define LIGHTCYAN(x) "\033[1;36m" x DEFCOL
89 #define WHITE(x) "\033[1;37m" x DEFCOL
90 #else
91 #define BLACK(x) x
92 #define RED(x) x
93 #define GREEN(x) x
94 #define BROWN(x) x
95 #define BLUE(x) x
96 #define PURPLE(x) x
97 #define CYAN(x) x
98 #define LIGHTGRAY(x) x
99 #define DARKGRAY(x) x
100 #define LIGHTRED(x) x
101 #define LIGHTGREEN(x) x
102 #define YELLOW(x) x
103 #define LIGHTBLUE(x) x
104 #define MAGENTA(x) x
105 #define LIGHTCYAN(x) x
106 #define WHITE(x) x
107 #endif
108 
109 /* functions declaration */
110 void log_init(char *, int, int );
111 int log_to_file(char *filename);
112 void close_log_file(void);
113 
114 void fatal(const char *, ...) __attribute__ ((noreturn));
115 void error(const char *, ...);
116 void loginfo(const char *, ...);
117 void debug(int lvl, const char *, ...);
118 
119 void print_log(int level, const char *fmt, va_list args);
120 
121 #endif /*LOG_H*/
void print_log(int level, const char *fmt, va_list args)
Definition: log.c:179
void fatal(const char *,...) __attribute__((noreturn))
Definition: log.c:94
void close_log_file(void)
Definition: log.c:85
void debug(int lvl, const char *,...)
Definition: log.c:162
void log_init(char *, int, int)
Definition: log.c:40
int log_to_file(char *filename)
Definition: log.c:62
void loginfo(const char *,...)
Definition: log.c:141
void error(const char *,...)
Definition: log.c:125