]>
git.ipfire.org Git - people/ms/rstp.git/blob - log.h
1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
21 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 ******************************************************************************/
31 #define LOG_LEVEL_NONE 0
32 #define LOG_LEVEL_ERROR 1
33 #define LOG_LEVEL_INFO 2
34 #define LOG_LEVEL_DEBUG 3
35 #define LOG_LEVEL_RSTPLIB 4
36 #define LOG_LEVEL_MAX 100
38 #define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
40 extern void Dprintf(int level
, const char *fmt
, ...);
41 extern void vDprintf(int level
, const char *fmt
, va_list ap
);
44 #define PRINT(_level, _fmt, _args...) Dprintf(_level, _fmt, ##_args)
46 #define TSTM(x,y, _fmt, _args...) do if (!(x)) { PRINT(LOG_LEVEL_ERROR, "Error in %s at %s:%d verifying %s. " _fmt, __PRETTY_FUNCTION__, __FILE__, __LINE__, #x, ##_args); return y; } while (0)
48 #define TST(x,y) TSTM(x,y,"")
50 #define LOG(_fmt, _args...) PRINT(LOG_LEVEL_DEBUG, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
52 #define INFO(_fmt, _args...) PRINT(LOG_LEVEL_INFO, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
54 #define ERROR(_fmt, _args...) PRINT(LOG_LEVEL_ERROR, "error, %s: " _fmt, __PRETTY_FUNCTION__, ##_args)
56 static inline void dump_hex(void *b
, int l
)
58 unsigned char *buf
= b
;
61 for (i
= 0; i
< l
; i
+= 16) {
62 for (j
= 0; j
< 16 && i
+j
< l
; j
++)
63 sprintf(logbuf
+ j
* 3, " %02x", buf
[i
+j
]);
64 PRINT(LOG_LEVEL_INFO
, "%s", logbuf
);
66 PRINT(LOG_LEVEL_INFO
, "\n");