Skip to content
Snippets Groups Projects
debug.h 1.41 KiB
/*
 * debug.h - defines macros for debugging.
 *
 * Copyright (C) 2020 iopsys Software Solutions AB. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */
#ifndef DEBUG_H
#define DEBUG_H

#define ERR_LEVEL   (3)
#define WARN_LEVEL  (4)
#define INFO_LEVEL  (6)
#define DBG_LEVEL   (7)

#ifdef __cplusplus
extern "C" {
#endif

extern void log_stderr(int level, const char *fmt, ...);

#define pr_error(...)	log_stderr(ERR_LEVEL, __VA_ARGS__)
#define pr_warn(...)	log_stderr(WARN_LEVEL, __VA_ARGS__)
#define pr_info(...)	log_stderr(INFO_LEVEL, __VA_ARGS__)
#define pr_debug(...)	log_stderr(DBG_LEVEL, __VA_ARGS__)

#define WARN_ON(cond) \
({ \
	typeof(cond) __c = (cond); \
	if (__c) \
		pr_warn("%sL%d@%s: [%s] failed\n", __FILE__, __LINE__, __func__, #cond); \
	__c; \
})

#ifdef __cplusplus
}
#endif
#endif /* DEBUG_H */