1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
3 Copyright (c) 2011 Factor-SPE
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc., 59
17 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 The full GNU General Public License is included in this distribution in the
22 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 Authors: Vitalii Demianets <dvitasgs@gmail.com>
25 ******************************************************************************/
33 #define LOG_LEVEL_NONE 0
34 #define LOG_LEVEL_ERROR 1
35 #define LOG_LEVEL_INFO 2
36 #define LOG_LEVEL_DEBUG 3
37 #define LOG_LEVEL_STATE_MACHINE_TRANSITION 4
40 #define LOG_LEVEL_MAX 100
42 #define LOG_LEVEL_MAX LOG_LEVEL_INFO
45 #define LOG_LEVEL_DEFAULT LOG_LEVEL_ERROR
47 extern void Dprintf(int level
, const char *fmt
, ...);
50 #define PRINT(_level, _fmt, _args...) \
52 if ((_level) <= LOG_LEVEL_MAX) \
53 Dprintf(_level, _fmt, ##_args); \
56 #define TSTM(x, y, _fmt, _args...) \
59 PRINT(LOG_LEVEL_ERROR, "Error in %s at %s:%d verifying %s. " _fmt, \
60 __PRETTY_FUNCTION__, __FILE__, __LINE__, #x, ##_args); \
64 #define TST(x, y) TSTM(x, y, "")
66 #define LOG(_fmt, _args...) \
67 PRINT(LOG_LEVEL_DEBUG, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
69 #define INFO(_fmt, _args...) \
70 PRINT(LOG_LEVEL_INFO, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
72 #define ERROR(_fmt, _args...) \
73 PRINT(LOG_LEVEL_ERROR, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
75 static inline void dump_hex(void *b
, int l
)
77 unsigned char *buf
= b
;
80 for (i
= 0; i
< l
; i
+= 16) {
81 for (j
= 0; j
< 16 && i
+ j
< l
; ++j
)
82 sprintf(logbuf
+ j
* 3, " %02x", buf
[i
+ j
]);
83 PRINT(LOG_LEVEL_INFO
, "%s", logbuf
);
85 PRINT(LOG_LEVEL_INFO
, "\n");