wimax-tools  1.4.4
log.h
Go to the documentation of this file.
1 /*
2  * Linux WiMax
3  * Simple log helpers
4  *
5  *
6  * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7  * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  * * Neither the name of Intel Corporation nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /**
36  *
37  * \defgroup helper_log Set of simple log helpers
38  *
39  * Log messages to stdout/stderr, with simple log level management.
40  *
41  * If the log level is W_PRINT, we assume is a normal message that the
42  * user wants to see and send it to stdout. If it is any other,
43  * evaluate if it should be printed based on the current level and
44  * then print it to stderr.
45  *
46  * Before including, W_VERBOSITY must be defined to something that
47  * yields a numeric value out of of \e { enum w_levels }. When any of
48  * the w_*() functions/macros is called, if the level it is called
49  * with is less or equal than the current level defied by W_VERBOSITY,
50  * it'll be ran, if not, it'll be ignored:
51  *
52  * @code
53  *
54  * #define W_VERBOSITY W_INFO (or myglobalstruct.verbosity)
55  * #include <wimaxll/log.h>
56  *
57  * somefunc()
58  * {
59  * ...
60  * w_d1("debug message\n");
61  * ...
62  * }
63  *
64  * @endcode
65  *
66  * To control where the log/progress messages go and how they are
67  * formatted, the client can set a couple of function pointers
68  * wimaxll_msg_hdr_cb() (which controls how a header/prefix for the
69  * message is created) and wimaxll_vlmsg_cb(), which takes the message
70  * and delivers it to whichever destination.
71  *
72  * The default implementations are wimaxll_msg_hdr_default() and
73  * wimaxll_vlmsg_default(), which add a
74  * "libwimall[DEVICENAME]:" header (with an optional "(@
75  * FUNCTION:LINE)") and deliver the message to \e stdout if it is a
76  * normal message (\e W_PRINT) or else if it is an error, warning,
77  * info or debug message, it is sent to \e stderr.
78  */
79 
80 #ifndef __wimaxll__log_h__
81 #define __wimaxll__log_h__
82 
83 #include <stdio.h>
84 #include <stdarg.h>
85 
86 #ifndef W_VERBOSITY
87 #error Please #define W_VERBOSITY before including this file
88 #endif
89 
90 /* Logging / printing */
91 enum w_levels {
104 };
105 
106 struct wimaxll_handle;
107 
108 void wimaxll_msg(struct wimaxll_handle *, const char *fmt, ...)
109  __attribute__ ((format(printf, 2, 3)));
110 
111 void wimaxll_lmsg(unsigned level, unsigned current_level,
112  const char *origin_str, unsigned origin_line,
113  struct wimaxll_handle *wmx, const char *fmt, ...)
114  __attribute__ ((format(printf, 6, 7)));
115 
116 extern void (*wimaxll_vlmsg_cb)(struct wimaxll_handle *, unsigned,
117  const char *, const char *, va_list);
118 void wimaxll_vlmsg_stderr(struct wimaxll_handle *, unsigned,
119  const char *, const char *, va_list);
120 
121 extern void (*wimaxll_msg_hdr_cb)(char *, size_t, struct wimaxll_handle *,
122  enum w_levels, const char *, unsigned);
123 void wimaxll_msg_hdr_default(char *, size_t, struct wimaxll_handle *,
124  enum w_levels, const char *, unsigned);
125 
126 void w_abort(int result, const char *fmt, ...);
127 
128 #define w_error(fmt...) wimaxll_lmsg(W_ERROR, W_VERBOSITY, __func__, __LINE__, NULL, "E: " fmt)
129 #define w_warn(fmt...) wimaxll_lmsg(W_WARN, W_VERBOSITY, __func__, __LINE__, NULL, "W: " fmt)
130 #define w_info(fmt...) wimaxll_lmsg(W_INFO, W_VERBOSITY, __func__, __LINE__, NULL, "I: " fmt)
131 #define w_print(fmt...) wimaxll_lmsg(W_PRINT, W_VERBOSITY, __func__, __LINE__, NULL, fmt)
132 #define w_d0(fmt...) wimaxll_lmsg(W_D0, W_VERBOSITY, __func__, __LINE__, NULL, "D0: " fmt)
133 #define w_d1(fmt...) wimaxll_lmsg(W_D1, W_VERBOSITY, __func__, __LINE__, NULL, "D1: " fmt)
134 #define w_d2(fmt...) wimaxll_lmsg(W_D2, W_VERBOSITY, __func__, __LINE__, NULL, "D2: " fmt)
135 #define w_d3(fmt...) wimaxll_lmsg(W_D3, W_VERBOSITY, __func__, __LINE__, NULL, "D3: " fmt)
136 #define w_d4(fmt...) wimaxll_lmsg(W_D4, W_VERBOSITY, __func__, __LINE__, NULL, "D4: " fmt)
137 #define w_d5(fmt...) wimaxll_lmsg(W_D5, W_VERBOSITY, __func__, __LINE__, NULL, "D5: " fmt)
138 #define w_d6(fmt...) wimaxll_lmsg(W_D6, W_VERBOSITY, __func__, __LINE__, NULL, "D6: " fmt)
139 #define w_d7(fmt...) wimaxll_lmsg(W_D7, W_VERBOSITY, __func__, __LINE__, NULL, "D7: " fmt)
140 
141 #endif /* #define __wimaxll__log_h__ */
A WiMax control pipe handle.
Definition: internal.h:219
void wimaxll_msg(struct wimaxll_handle *, const char *fmt,...) __attribute__((format(printf
void void void(* wimaxll_vlmsg_cb)(struct wimaxll_handle *, unsigned, const char *, const char *, va_list)
Print library diagnostics messages [backend].
Definition: log.c:118
Definition: log.h:96
Definition: cmd.h:90
void wimaxll_vlmsg_stderr(struct wimaxll_handle *, unsigned, const char *, const char *, va_list)
void w_abort(int result, const char *fmt,...)
Definition: wimaxll.c:101
w_levels
Definition: log.h:91
Definition: cmd.h:93
Definition: log.h:102
void(* wimaxll_msg_hdr_cb)(char *, size_t, struct wimaxll_handle *, enum w_levels, const char *, unsigned)
Create a header for library diagnostic messages [backend].
Definition: log.c:190
Definition: log.h:101
Definition: log.h:100
Definition: cmd.h:94
Definition: log.h:103
void wimaxll_msg_hdr_default(char *, size_t, struct wimaxll_handle *, enum w_levels, const char *, unsigned)
Default header for diagnostic messages.
Definition: log.c:133
Definition: cmd.h:96
Definition: cmd.h:92
void void wimaxll_lmsg(unsigned level, unsigned current_level, const char *origin_str, unsigned origin_line, struct wimaxll_handle *wmx, const char *fmt,...) __attribute__((format(printf
Definition: cmd.h:91
Definition: cmd.h:95