The Pedigree Project  0.1
logging.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _POSIX_KERNEL_LOGGING_H
21 #define _POSIX_KERNEL_LOGGING_H
22 
23 #include "pedigree/kernel/process/Process.h"
24 #include "pedigree/kernel/process/Thread.h"
25 #include "pedigree/kernel/processor/Processor.h"
26 
27 // Logs to the kernel log with the current PID.
28 #ifdef THREADS
29 #define POSIX_VERBOSE_LOG(f, x) \
30  do \
31  { \
32  auto ____tid = Processor::information().getCurrentThread()->getId(); \
33  auto ____level = \
34  Processor::information().getCurrentThread()->getStateLevel(); \
35  auto ____pid = \
36  Processor::information().getCurrentThread()->getParent()->getId(); \
37  NOTICE( \
38  "[" << f << ":\t" << Dec << ____pid << ":" << ____tid << "." \
39  << ____level << Hex << "]\t" << x); \
40  } while (0)
41 #else
42 #define POSIX_VERBOSE_LOG(f, x) \
43  do \
44  { \
45  NOTICE("[" << f << "]\t" << x); \
46  } while (0)
47 #endif
48 
49 // POSIX_LOG_FACILITIES is an integer for which each bit indicates a particular
50 // category to enable verbose logging for.
51 #ifdef POSIX_LOG_FACILITIES
52 
53 #if POSIX_LOG_FACILITIES & 1
54 #define POSIX_VERBOSE_FILE_SYSCALLS
55 #endif
56 
57 #if POSIX_LOG_FACILITIES & 2
58 #define POSIX_VERBOSE_SYSTEM_SYSCALLS
59 #endif
60 
61 #if POSIX_LOG_FACILITIES & 4
62 #define POSIX_VERBOSE_PTHREAD_SYSCALLS
63 #endif
64 
65 #if POSIX_LOG_FACILITIES & 8
66 #define POSIX_VERBOSE_NET_SYSCALLS
67 #endif
68 
69 #if POSIX_LOG_FACILITIES & 16
70 #define POSIX_VERBOSE_SIGNAL_SYSCALLS
71 #endif
72 
73 #if POSIX_LOG_FACILITIES & 32
74 #define POSIX_VERBOSE_SUBSYSTEM
75 #endif
76 
77 #if POSIX_LOG_FACILITIES & 64
78 #define POSIX_ULTRA_VERBOSE_SIGNAL_SYSCALLS
79 #endif
80 
81 #if POSIX_LOG_FACILITIES & 128
82 #define POSIX_VERBOSE_SYSCALLS
83 #endif
84 
85 #if POSIX_LOG_FACILITIES & 256
86 #define POSIX_VERBOSE_POLL_SYSCALLS
87 #endif
88 
89 #endif
90 
91 #ifdef POSIX_VERBOSE_SYSTEM_SYSCALLS
92 #define SC_NOTICE(x) POSIX_VERBOSE_LOG("sys", x)
93 #else
94 #define SC_NOTICE(x)
95 #endif
96 
97 #ifdef POSIX_VERBOSE_FILE_SYSCALLS
98 #define F_NOTICE(x) POSIX_VERBOSE_LOG("io", x)
99 #else
100 #define F_NOTICE(x)
101 #endif
102 
103 #ifdef POSIX_VERBOSE_PTHREAD_SYSCALLS
104 #define PT_NOTICE(x) POSIX_VERBOSE_LOG("thr", x)
105 #else
106 #define PT_NOTICE(x)
107 #endif
108 
109 #ifdef POSIX_VERBOSE_NET_SYSCALLS
110 #define N_NOTICE(x) POSIX_VERBOSE_LOG("net", x)
111 #else
112 #define N_NOTICE(x)
113 #endif
114 
115 #ifdef POSIX_VERBOSE_SIGNAL_SYSCALLS
116 #define SG_NOTICE(x) POSIX_VERBOSE_LOG("sig", x)
117 #else
118 #define SG_NOTICE(x)
119 #endif
120 
121 #ifdef POSIX_VERBOSE_SUBSYSTEM
122 #define PS_NOTICE(x) POSIX_VERBOSE_LOG("sub", x)
123 #else
124 #define PS_NOTICE(x)
125 #endif
126 
127 #ifdef POSIX_ULTRA_VERBOSE_SIGNAL_SYSCALLS
128 #define SG_VERBOSE_NOTICE(x) SG_NOTICE(x)
129 #else
130 #define SG_VERBOSE_NOTICE(x)
131 #endif
132 
133 #ifdef POSIX_VERBOSE_POLL_SYSCALLS
134 #define POLL_NOTICE(x) POSIX_VERBOSE_LOG("poll", x)
135 #else
136 #define POLL_NOTICE(x)
137 #endif
138 
139 #endif // _POSIX_KERNEL_LOGGING_H