Asylo
|
#include <cstdint>
#include <cstdlib>
#include <memory>
#include <sstream>
#include <string>
#include "absl/base/attributes.h"
#include "absl/base/optimization.h"
Go to the source code of this file.
Classes | |
class | asylo::CheckOpMessageBuilder |
A helper class for formatting "expr (V1 vs. V2)" in a CHECK_XX statement. More... | |
class | asylo::LogMessage |
Class representing a log message created by a log macro. More... | |
class | asylo::LogMessageVoidify |
This class is used just to take an ostream type and make it a void type to satisify the ternary operator in LOG_IF . More... | |
class | asylo::LogMessageFatal |
A LogSeverity FATAL (or QFATAL) version of LogMessage that the compiler can interpret as noreturn. More... | |
Namespaces | |
asylo | |
Macros | |
#define | LOG(severity) COMPACT_ASYLO_LOG_##severity.stream() |
Creates a message and logs it to file. More... | |
#define | LOG_IF(severity, condition) !(condition) ? (void)0 : asylo::LogMessageVoidify() & LOG(severity) |
A command to LOG only if a condition is true. More... | |
#define | VLOG(level) LOG_IF(INFO, (level) <= get_vlog_level()) |
A LOG command with an associated verbosity level. More... | |
#define | CHECK(condition) LOG_IF(FATAL, !(condition)) << "Check failed: " #condition " " |
Ends the program with a fatal error if the specified condition is false. More... | |
#define | CHECK_OP_LOG(name, op, val1, val2, log) |
Compares val1 and val2 with op , and does log if false. More... | |
#define | CHECK_OP(name, op, val1, val2) CHECK_OP_LOG(name, op, val1, val2, asylo::LogMessageFatal) |
Compares val1 and val2 with op , and produces a LOG(FATAL) if false. More... | |
#define | CHECK_EQ(val1, val2) CHECK_OP(Check_EQ, ==, val1, val2) |
Produces a LOG(FATAL) unless val1 equals val2 . More... | |
#define | CHECK_NE(val1, val2) CHECK_OP(Check_NE, !=, val1, val2) |
Produces a LOG(FATAL) unless val1 does not equal to val2 . More... | |
#define | CHECK_LE(val1, val2) CHECK_OP(Check_LE, <=, val1, val2) |
Produces a LOG(FATAL) unless val1 is less than or equal to val2 . More... | |
#define | CHECK_LT(val1, val2) CHECK_OP(Check_LT, <, val1, val2) |
Produces a LOG(FATAL) unless val1 is less than val2 . More... | |
#define | CHECK_GE(val1, val2) CHECK_OP(Check_GE, >=, val1, val2) |
Produces a LOG(FATAL) unless val1 is greater than or equal to val2 . More... | |
#define | CHECK_GT(val1, val2) CHECK_OP(Check_GT, >, val1, val2) |
Produces a LOG(FATAL) unless val1 is greater than val2 . More... | |
#define | CHECK_NOTNULL(val) asylo::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val)) |
Checks that the argument is not null, and returns it. More... | |
Enumerations | |
enum | LogSeverity { INFO, WARNING, ERROR, FATAL, QFATAL } |
Severity level definitions. More... | |
Functions | |
template<> | |
void | asylo::MakeCheckOpValueString (std::ostream *os, const std::nullptr_t &p) |
void | asylo::set_vlog_level (int level) |
Sets the verbosity threshold for VLOG. More... | |
int | asylo::get_vlog_level () |
Gets the verbosity threshold for VLOG. More... | |
bool | asylo::set_log_directory (const std::string &log_directory) |
Sets the log directory, as specified when this enclave is initialized. More... | |
const std::string | asylo::get_log_directory () |
Gets the log directory that was specified when this enclave is initialized. More... | |
bool | asylo::EnsureDirectory (const char *path) |
Checks the log directory to make sure it's accessible, and creates it if it does not exist. More... | |
bool | asylo::InitLogging (const char *directory, const char *file_name, int level) |
Initializes minimal logging library. More... | |
template<typename T > | |
T | asylo::CheckNotNull (const char *file, int line, const char *exprtext, T &&t) |
Logs a message if the given value of type T is null, and then forwards the value. More... | |
Ends the program with a fatal error if the specified condition is false.
Example:
Might produce a message like:
Check_failed: !cheese.empty() Out of Cheese
#define CHECK_EQ | ( | val1, | |
val2 | |||
) | CHECK_OP(Check_EQ, ==, val1, val2) |
Produces a LOG(FATAL) unless val1
equals val2
.
#define CHECK_GE | ( | val1, | |
val2 | |||
) | CHECK_OP(Check_GE, >=, val1, val2) |
Produces a LOG(FATAL) unless val1
is greater than or equal to val2
.
#define CHECK_GT | ( | val1, | |
val2 | |||
) | CHECK_OP(Check_GT, >, val1, val2) |
Produces a LOG(FATAL) unless val1
is greater than val2
.
#define CHECK_LE | ( | val1, | |
val2 | |||
) | CHECK_OP(Check_LE, <=, val1, val2) |
Produces a LOG(FATAL) unless val1
is less than or equal to val2
.
#define CHECK_LT | ( | val1, | |
val2 | |||
) | CHECK_OP(Check_LT, <, val1, val2) |
Produces a LOG(FATAL) unless val1
is less than val2
.
#define CHECK_NE | ( | val1, | |
val2 | |||
) | CHECK_OP(Check_NE, !=, val1, val2) |
Produces a LOG(FATAL) unless val1
does not equal to val2
.
#define CHECK_NOTNULL | ( | val | ) | asylo::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val)) |
Checks that the argument is not null, and returns it.
Unlike other CHECK
macros, this one returns its input, so it can be used in initializers. Outside initializers, prefer CHECK
.
CHECK_NOTNULL
works for both raw pointers and (compatible) smart pointers including std::unique_ptr
and std::shared_ptr
.
For smart pointers CHECK_NOTNULL
returns a reference to its argument, preserving the value category (i.e., an rvalue reference for an rvalue argument, and an lvalue reference otherwise). For pre-C++11 compilers that's not possible, so as a best available approximation a reference-to-const will be returned if the argument is an rvalue.
val | The value being compared. |
#define CHECK_OP | ( | name, | |
op, | |||
val1, | |||
val2 | |||
) | CHECK_OP_LOG(name, op, val1, val2, asylo::LogMessageFatal) |
Compares val1
and val2
with op
, and produces a LOG(FATAL) if false.
name | An identifier that is the name of the comparison, such as Check_EQ or Check_NE. |
op | The comparison operator, such as == or !=. |
val1 | The first variable to be compared. |
val2 | The second variable to be compared. |
#define CHECK_OP_LOG | ( | name, | |
op, | |||
val1, | |||
val2, | |||
log | |||
) |
Compares val1
and val2
with op
, and does log
if false.
name | An identifier that is the name of the comparison, such as Check_EQ or Check_NE. |
op | The comparison operator, such as == or !=. |
val1 | The first variable to be compared. |
val2 | The second variable to be compared. |
log | The log action to be performed if the comparison returns false. |
#define LOG | ( | severity | ) | COMPACT_ASYLO_LOG_##severity.stream() |
Creates a message and logs it to file.
LOG(severity)
returns a stream object that can be written to with the <<
operator. Log messages are emitted with terminating newlines. Example:
severity | The severity of the log message, one of LogSeverity . The FATAL severity will end the program after the log is emitted. |
#define LOG_IF | ( | severity, | |
condition | |||
) | !(condition) ? (void)0 : asylo::LogMessageVoidify() & LOG(severity) |
A command to LOG only if a condition is true.
If the condition is false, nothing is logged. Example:
severity | The severity of the log message, one of LogSeverity . The FATAL severity will end the program after the log is emitted. |
condition | The condition that determines whether to log the message. |
A LOG
command with an associated verbosity level.
The verbosity threshold may be configured at runtime with set_vlog_level
and InitLogging
.
VLOG
statements are logged at INFO
severity if they are logged at all. The numeric levels are on a different scale than the severity levels. Example:
level | The numeric level that determines whether to log the message. |
enum LogSeverity |