summaryrefslogtreecommitdiff
path: root/src/libcamera/include/log.h
blob: cc3f9404a3d45554067df5d209721396a54d1087 (plain)
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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2018, Google Inc.
 *
 * log.h - Logging infrastructure
 */
#ifndef __LIBCAMERA_LOG_H__
#define __LIBCAMERA_LOG_H__

#include <sstream>

namespace libcamera {

enum LogSeverity {
	LogDebug,
	LogInfo,
	LogWarning,
	LogError,
	LogFatal,
};

class LogMessage
{
public:
	LogMessage(const char *fileName, unsigned int line,
		   LogSeverity severity);
	LogMessage(const LogMessage &) = delete;
	~LogMessage();

	std::ostream &stream() { return msgStream; }

private:
	std::ostringstream msgStream;
	LogSeverity severity_;
};

#define LOG(severity) LogMessage(__FILE__, __LINE__, Log##severity).stream()

#ifndef NDEBUG
#define ASSERT(condition) static_cast<void>(({				\
	if (!(condition))							\
		LOG(Fatal) << "assertion \"" #condition "\" failed";	\
}))
#else
#define ASSERT(condition) static_cast<void>(false && (condition))
#endif

} /* namespace libcamera */

#endif /* __LIBCAMERA_LOG_H__ */