mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
nearby: snapshot of cl/317978613
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I4bf367877a986910bb03e1c54aa972b4bcd59942
This commit is contained in:
@@ -1,6 +1,60 @@
|
||||
#ifndef PLATFORM_V2_BASE_LOGGING_H_
|
||||
#define PLATFORM_V2_BASE_LOGGING_H_
|
||||
|
||||
#include "platform/logging.h"
|
||||
#include "platform_v2/api/log_message.h"
|
||||
#include "platform_v2/api/platform.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
// This class is used to explicitly ignore values in the conditional
|
||||
// logging macros. This avoids compiler warnings like "value computed
|
||||
// is not used" and "statement has no effect".
|
||||
class LogMessageVoidify {
|
||||
public:
|
||||
LogMessageVoidify() = default;
|
||||
// This has to be an operator with a precedence lower than << but
|
||||
// higher than ?:
|
||||
void operator&(std::ostream&) {}
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
// Severity enum conversion
|
||||
#define NEARBY_SEVERITY_INFO location::nearby::api::LogMessage::Severity::kInfo
|
||||
#define NEARBY_SEVERITY_WARNING \
|
||||
location::nearby::api::LogMessage::Severity::kWarning
|
||||
#define NEARBY_SEVERITY_ERROR \
|
||||
location::nearby::api::LogMessage::Severity::kError
|
||||
#define NEARBY_SEVERITY_FATAL \
|
||||
location::nearby::api::LogMessage::Severity::kFatal
|
||||
|
||||
#define NEARBY_SEVERITY(severity) NEARBY_SEVERITY_##severity
|
||||
|
||||
// Log enabling
|
||||
#define NEARBY_LOG_IS_ON(severity) \
|
||||
location::nearby::api::LogMessage::ShouldCreateLogMessage( \
|
||||
NEARBY_SEVERITY(severity))
|
||||
|
||||
#define NEARBY_LOG_SET_SEVERITY(severity) \
|
||||
location::nearby::api::LogMessage::SetMinLogSeverity( \
|
||||
NEARBY_SEVERITY(severity))
|
||||
|
||||
// Log message creation
|
||||
#define NEARBY_LOG_MESSAGE(severity) \
|
||||
location::nearby::api::ImplementationPlatform::CreateLogMessage( \
|
||||
__FILE__, __LINE__, NEARBY_SEVERITY(severity))
|
||||
|
||||
// Public APIs
|
||||
// The stream statement must come last or otherwise it won't compile.
|
||||
#define NEARBY_LOGS(severity) \
|
||||
!(NEARBY_LOG_IS_ON(severity)) ? (void)0 \
|
||||
: location::nearby::LogMessageVoidify() & \
|
||||
NEARBY_LOG_MESSAGE(severity)->Stream()
|
||||
|
||||
#define NEARBY_LOG(severity, ...) \
|
||||
NEARBY_LOG_IS_ON(severity) \
|
||||
? NEARBY_LOG_MESSAGE(severity)->Print(__VA_ARGS__) : (void)0
|
||||
|
||||
#endif // PLATFORM_V2_BASE_LOGGING_H_
|
||||
|
||||
Reference in New Issue
Block a user