]> git.ipfire.org Git - people/ms/mstpd.git/blame - log.h
driver hooks for creating/deleting new MSTI
[people/ms/mstpd.git] / log.h
CommitLineData
1e6d2d09
VD
1/*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
3 Copyright (c) 2011 Factor-SPE
4
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)
8 any later version.
9
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
13 more details.
14
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.
18
19 The full GNU General Public License is included in this distribution in the
20 file called LICENSE.
21
22 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 Authors: Vitalii Demianets <vitas@nppfactor.kiev.ua>
24
25******************************************************************************/
26
27#ifndef LOG_H
28#define LOG_H
29
30#include <stdio.h>
31#include <stdarg.h>
32
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
38#define LOG_LEVEL_MAX 100
39
40#define LOG_LEVEL_DEFAULT LOG_LEVEL_INFO
41
42extern void Dprintf(int level, const char *fmt, ...);
43extern void vDprintf(int level, const char *fmt, va_list ap);
44extern int log_level;
45
46#define PRINT(_level, _fmt, _args...) Dprintf(_level, _fmt, ##_args)
47
48#define TSTM(x, y, _fmt, _args...) \
49 do if(!(x)) \
50 { \
51 PRINT(LOG_LEVEL_ERROR, "Error in %s at %s:%d verifying %s. " _fmt, \
52 __PRETTY_FUNCTION__, __FILE__, __LINE__, #x, ##_args); \
53 return y; \
54 } while (0)
55
56#define TST(x, y) TSTM(x, y, "")
57
58#define LOG(_fmt, _args...) \
59 PRINT(LOG_LEVEL_DEBUG, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
60
61#define INFO(_fmt, _args...) \
62 PRINT(LOG_LEVEL_INFO, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
63
64#ifdef NO_DAEMON
65#define ERROR(_fmt, _args...) \
66 PRINT(LOG_LEVEL_ERROR, "%s: " _fmt, __PRETTY_FUNCTION__, ##_args)
67
68#else
69#include "ctl_socket_server.h"
70#define ERROR(_fmt, _args...) \
71 ({ \
72 PRINT(LOG_LEVEL_ERROR, "error, %s: " _fmt, __PRETTY_FUNCTION__, \
73 ##_args); \
74 ctl_err_log(_fmt "\n", ##_args); \
75 })
76#endif
77
78static inline void dump_hex(void *b, int l)
79{
80 unsigned char *buf = b;
81 char logbuf[80];
82 int i, j;
83 for (i = 0; i < l; i += 16) {
84 for (j = 0; j < 16 && i + j < l; ++j)
85 sprintf(logbuf + j * 3, " %02x", buf[i + j]);
86 PRINT(LOG_LEVEL_INFO, "%s", logbuf);
87 }
88 PRINT(LOG_LEVEL_INFO, "\n");
89}
90
91#endif /* LOG_H */