• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* uniklog.h
2  *
3  * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4  * All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or (at
9  * your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14  * NON INFRINGEMENT.  See the GNU General Public License for more
15  * details.
16  */
17 
18 /* This module contains macros to aid developers in logging messages.
19  *
20  * This module is affected by the DEBUG compiletime option.
21  *
22  */
23 #ifndef __UNIKLOG_H__
24 #define __UNIKLOG_H__
25 
26 #include <linux/printk.h>
27 
28 /*
29  * # DBGINF
30  *
31  * \brief Log debug informational message - log a LOG_INFO message only
32  *        if DEBUG compiletime option enabled
33  *
34  * \param devname the device name of the device reporting this message, or
35  *                NULL if this message is NOT device-related.
36  * \param fmt printf()-style format string containing the message to log.
37  * \param args Optional arguments to be formatted and inserted into the
38  *             format string.
39  * \return nothing
40  *
41  * Log a message at the LOG_INFO level, but only if DEBUG is enabled.  If
42  * DEBUG is disabled, this expands to a no-op.
43  */
44 
45 /*
46  * # DBGVER
47  *
48  * \brief Log debug verbose message - log a LOG_DEBUG message only if
49  *        DEBUG compiletime option enabled
50  *
51  * \param devname the device name of the device reporting this message, or
52  *                NULL if this message is NOT device-related.
53  * \param fmt printf()-style format string containing the message to log.
54  * \param args Optional arguments to be formatted and inserted into the
55  *             format string.
56  * \return nothing
57  *
58  * Log a message at the LOG_DEBUG level, but only if DEBUG is enabled.  If
59  * DEBUG is disabled, this expands to a no-op.  Note also that LOG_DEBUG
60  * messages can be enabled/disabled at runtime as well.
61  */
62 #define DBGINFDEV(devname, fmt, args...)        do { } while (0)
63 #define DBGVERDEV(devname, fmt, args...)        do { } while (0)
64 #define DBGINF(fmt, args...)                    do { } while (0)
65 #define DBGVER(fmt, args...)                    do { } while (0)
66 
67 /*
68  * # LOGINF
69  *
70  * \brief Log informational message - logs a message at the LOG_INFO level
71  *
72  * \param devname the device name of the device reporting this message, or
73  *                NULL if this message is NOT device-related.
74  * \param fmt printf()-style format string containing the message to log.
75  * \param args Optional arguments to be formatted and inserted into the
76  *             format string.
77  * \return nothing
78  *
79  * Logs the specified message at the LOG_INFO level.
80  */
81 
82 #define LOGINF(fmt, args...) pr_info(fmt, ## args)
83 #define LOGINFDEV(devname, fmt, args...) \
84 	pr_info("%s " fmt, devname, ## args)
85 #define LOGINFDEVX(devno, fmt, args...) \
86 	pr_info("dev%d " fmt, devno, ## args)
87 #define LOGINFNAME(vnic, fmt, args...)				\
88 	do {								\
89 		if (vnic != NULL) {					\
90 			pr_info("%s " fmt, vnic->name, ## args);	\
91 		} else {						\
92 			pr_info(fmt, ## args);				\
93 		}							\
94 	} while (0)
95 
96 /*
97  * # LOGVER
98  *
99  * \brief Log verbose message - logs a message at the LOG_DEBUG level,
100  *        which can be disabled at runtime
101  *
102  * \param devname the device name of the device reporting this message, or
103  *                NULL if this message is NOT device-related.
104  * \param fmt printf()-style format string containing the message to log.
105  * \param args Optional arguments to be formatted and inserted into the format
106  * \param string.
107  * \return nothing
108  *
109  * Logs the specified message at the LOG_DEBUG level.  Note also that
110  * LOG_DEBUG messages can be enabled/disabled at runtime as well.
111  */
112 #define LOGVER(fmt, args...) pr_debug(fmt, ## args)
113 #define LOGVERDEV(devname, fmt, args...) \
114 	pr_debug("%s " fmt, devname, ## args)
115 #define LOGVERNAME(vnic, fmt, args...)					\
116 	do {								\
117 		if (vnic != NULL) {					\
118 			pr_debug("%s " fmt, vnic->name, ## args);	\
119 		} else {						\
120 			pr_debug(fmt, ## args);				\
121 		}							\
122 	} while (0)
123 
124 /*
125  * # LOGERR
126  *
127  * \brief Log error message - logs a message at the LOG_ERR level,
128  *        including source line number information
129  *
130  * \param devname the device name of the device reporting this message, or
131  *                NULL if this message is NOT device-related.
132  * \param fmt printf()-style format string containing the message to log.
133  * \param args Optional arguments to be formatted and inserted into the format
134  * \param string.
135  * \return nothing
136  *
137  * Logs the specified error message at the LOG_ERR level.  It will also
138  * include the file, line number, and function name of where the error
139  * originated in the log message.
140  */
141 #define LOGERR(fmt, args...) pr_err(fmt, ## args)
142 #define LOGERRDEV(devname, fmt, args...) \
143 	pr_err("%s " fmt, devname, ## args)
144 #define LOGERRDEVX(devno, fmt, args...) \
145 	pr_err("dev%d " fmt, devno, ## args)
146 #define LOGERRNAME(vnic, fmt, args...)				\
147 	do {								\
148 		if (vnic != NULL) {					\
149 			pr_err("%s " fmt, vnic->name, ## args);	\
150 		} else {						\
151 			pr_err(fmt, ## args);				\
152 		}							\
153 	} while (0)
154 #define LOGORDUMPERR(seqfile, fmt, args...) do {		\
155 		if (seqfile) {					\
156 			seq_printf(seqfile, fmt, ## args);	\
157 		} else {					\
158 			LOGERR(fmt, ## args);			\
159 		}						\
160 	} while (0)
161 
162 /*
163  * # LOGWRN
164  *
165  * \brief Log warning message - Logs a message at the LOG_WARNING level,
166  *        including source line number information
167  *
168  * \param devname the device name of the device reporting this message, or
169  *                NULL if this message is NOT device-related.
170  * \param fmt printf()-style format string containing the message to log.
171  * \param args Optional arguments to be formatted and inserted into the format
172  * \param string.
173  * \return nothing
174  *
175  * Logs the specified error message at the LOG_WARNING level.  It will also
176  * include the file, line number, and function name of where the error
177  * originated in the log message.
178  */
179 #define LOGWRN(fmt, args...) pr_warn(fmt, ## args)
180 #define LOGWRNDEV(devname, fmt, args...) \
181 	pr_warn("%s " fmt, devname, ## args)
182 #define LOGWRNNAME(vnic, fmt, args...) \
183 	do {								\
184 		if (vnic != NULL) {					\
185 			pr_warn("%s " fmt, vnic->name, ## args);	\
186 		} else {						\
187 			pr_warn(fmt, ## args);				\
188 		}							\
189 	} while (0)
190 
191 #endif /* __UNIKLOG_H__ */
192