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#include "pedigree/kernel/process/Process.h"
23#include "pedigree/kernel/process/Thread.h"
24#include "pedigree/kernel/processor/Processor.h"
25
26#include <config.h>
27
28// Logs to the kernel log with the current PID.
29#if THREADS
30#define POSIX_VERBOSE_LOG(f, x) \
31 do { \
32 auto ____tid = Processor::information().getCurrentThread()->getId(); \
33 auto ____level = Processor::information().getCurrentThread()->getStateLevel(); \
34 auto ____pid = Processor::information().getCurrentThread()->getParent()->getId(); \
35 NOTICE("[" << f << ":\t" << Dec << ____pid << ":" << ____tid << "." << ____level << Hex \
36 << "]\t" << x); \
37 } while (0)
38#else
39#define POSIX_VERBOSE_LOG(f, x) \
40 do { \
41 NOTICE("[" << f << "]\t" << x); \
42 } while (0)
43#endif
44
45// Each facility is one bit in the build's verbose logging mask.
46#ifndef POSIX_LOG_FACILITIES
47#define POSIX_LOG_FACILITIES 0
48#endif
49
50#define POSIX_LOG_IF(mask, facility, text) \
51 do { \
52 EMIT_IF((POSIX_LOG_FACILITIES & (mask)) == (mask)) { \
53 POSIX_VERBOSE_LOG(facility, text); \
54 } \
55 } while (0)
56
57#define SC_NOTICE(x) POSIX_LOG_IF(2, "sys", x)
58#define F_NOTICE(x) POSIX_LOG_IF(1, "io", x)
59#define PT_NOTICE(x) POSIX_LOG_IF(4, "thr", x)
60#define N_NOTICE(x) POSIX_LOG_IF(8, "net", x)
61#define SG_NOTICE(x) POSIX_LOG_IF(32, "sig", x)
62#define PS_NOTICE(x) POSIX_LOG_IF(16, "sub", x)
63#define SG_VERBOSE_NOTICE(x) POSIX_LOG_IF(32 | 64, "sig", x)
64#define POLL_NOTICE(x) POSIX_LOG_IF(256, "poll", x)
65
66#endif // _POSIX_KERNEL_LOGGING_H