logging.h 2.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Copyright (C) 2014 Jens Korinth, TU Darmstadt
//
// This file is part of Tapasco (TPC).
//
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco.  If not, see <http://www.gnu.org/licenses/>.
//
//! @file	logging.h
//! @brief	Kernel logging helper functions:
//!		Declares module parameter 'logging_level' which determines the
//!		amount of printk output; errors are signaled using level 0 and
//!		are always output, warnings are level 1, the other levels are
//!		bitfield indicators and can be defined by the user.
//! @authors	J. Korinth, TU Darmstadt (jk@esa.cs.tu-darmstadt.de)
//!
#ifndef __TAPASCO_PLATFORM_LOGGING_H__
#define __TAPASCO_PLATFORM_LOGGING_H__

#include <linux/printk.h>

#ifdef LOGGING_MODULE_INCLUDE
unsigned int logging_level = 0x7fffffff;
module_param(logging_level, uint, S_IRUGO|S_IWUSR|S_IWGRP);
#else
extern int logging_level;
#endif

#ifndef NDEBUG
#define ERR(msg, ...)		tapasco_platform_log(0, msg, ##__VA_ARGS__)
#define WRN(msg, ...)		tapasco_platform_log(1, msg, ##__VA_ARGS__)
#define LOG(l, msg, ...)	tapasco_platform_log((l), msg, ##__VA_ARGS__)

#define tapasco_platform_log(level, fmt, ...) do { \
		switch ((int)level) { \
		case 0: \
			printk(KERN_ERR "tapasco-platform-zynq: [%s] " \
					fmt "\n", __func__, \
					##__VA_ARGS__); \
			break; \
		case 1: \
			printk(KERN_WARNING "tapasco-platform-zynq: [%s] " \
					fmt "\n", __func__, \
					##__VA_ARGS__); \
			break; \
		default: \
			if (logging_level & level) \
				printk(KERN_NOTICE "tapasco_platform_zynq: [%s] " \
						fmt "\n", __func__, \
						##__VA_ARGS__); \
			break; \
		} \
	} while(0)
#else
/* only errors and warnings, no other messages */
#define ERR(fmt, ...)		printk(KERN_ERR "tapasco-platform-zynq: [%s] " \
					fmt "\n", __func__, \
					##__VA_ARGS__)

#define WRN(fmt, ...)		printk(KERN_WARNING "tapasco-platform-zynq: [%s] " \
					fmt "\n", __func__, \
					##__VA_ARGS__)

#define LOG(l, msg, ...)
#define tapasco_platform_log(level, fmt, ...)
#endif

#endif /* __TAPASCO_PLATFORM_LOGGING_H__ */