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