Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Start nodes now confirm that read-only ledger directories are empty on startup (#7355).
- In the C++ API, the method `get_txid()` on `ccf::kv::ReadOnlyStore` has been renamed to `current_txid()`. This may affect historical query code which works directly with the returned `StorePtr` (#7477).
- The C++ API for installing endpoints with local commit handlers has changed. These handlers should now be added to an `Endpoint` with `.set_locally_committed_function(handler)`, and the `make_[read_only_]endpoint_with_local_commit_handler` methods on `EndpointRegistry` have been removed (#7487).
- The format of CCF's stdout logging has changed. Each line previously tried to align host logs with enclave logs containing a timestamp offset. Since enclave logs no longer exist, this timestamp is never present, so the padding whitespace has been removed (#7491).

## [7.0.0-dev5]

Expand Down
86 changes: 16 additions & 70 deletions include/ccf/ds/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,13 @@ namespace ccf::logger
std::cout.flush();
}

virtual void write(
const LogLine& ll,
const std::optional<double>& enclave_offset = std::nullopt) = 0;
virtual void write(const LogLine& ll) = 0;
};

class JsonConsoleLogger : public AbstractLogger
{
public:
void write(
const LogLine& ll,
const std::optional<double>& enclave_offset = std::nullopt) override
void write(const LogLine& ll) override
{
// Fetch time
::timespec host_ts{};
Expand All @@ -139,55 +135,22 @@ namespace ccf::logger
#endif

std::string s;
if (enclave_offset.has_value())
{
::timespec enc_ts = host_ts;
enc_ts.tv_sec += (size_t)enclave_offset.value();
enc_ts.tv_nsec +=
(long long)(enclave_offset.value() * ns_per_s) % ns_per_s;

if (enc_ts.tv_nsec > ns_per_s)
{
enc_ts.tv_sec += 1;
enc_ts.tv_nsec -= ns_per_s;
}

std::tm enclave_tm{};
gmtime_r(&enc_ts.tv_sec, &enclave_tm);

s = fmt::format(
"{{\"h_ts\":\"{}\",\"e_ts\":\"{}\",\"thread_id\":\"{}\",\"level\":\"{"
"}\",\"tag\":\"{}\",\"file\":\"{}\",\"number\":\"{}\",\"msg\":{}}}\n",
get_timestamp(host_tm, host_ts),
get_timestamp(enclave_tm, enc_ts),
ll.thread_id,
to_string(ll.log_level),
ll.tag,
ll.file_name,
ll.line_number,
escaped_msg);
}
else
{
s = fmt::format(
"{{\"h_ts\":\"{}\",\"thread_id\":\"{}\",\"level\":\"{}\",\"tag\":\"{}"
"\",\"file\":\"{}\",\"number\":\"{}\",\"msg\":{}}}\n",
get_timestamp(host_tm, host_ts),
ll.thread_id,
to_string(ll.log_level),
ll.tag,
ll.file_name,
ll.line_number,
escaped_msg);
}
s = fmt::format(
"{{\"h_ts\":\"{}\",\"thread_id\":\"{}\",\"level\":\"{}\",\"tag\":\"{}"
"\",\"file\":\"{}\",\"number\":\"{}\",\"msg\":{}}}\n",
get_timestamp(host_tm, host_ts),
ll.thread_id,
to_string(ll.log_level),
ll.tag,
ll.file_name,
ll.line_number,
escaped_msg);

emit(s);
}
};

static std::string format_to_text(
const LogLine& ll,
const std::optional<double>& enclave_offset = std::nullopt)
static std::string format_to_text(const LogLine& ll)
{
// Fetch time
::timespec host_ts{};
Expand Down Expand Up @@ -218,23 +181,8 @@ namespace ccf::logger

preamble += file_line_data;

if (enclave_offset.has_value())
{
// Sample: "2019-07-19 18:53:25.690183 -0.130 " where -0.130 indicates
// that the time inside the enclave was 130 milliseconds earlier than
// the host timestamp printed on the line
return fmt::format(
"{} {:+01.3f} {:<3} {:<45}| {}\n",
get_timestamp(host_tm, host_ts),
enclave_offset.value(),
ll.thread_id,
preamble,
ll.msg);
}
// Padding on the right to align the rest of the message
// with lines that contain enclave time offsets
return fmt::format(
"{} {:<3} {:<45}| {}\n",
"{} {:<3} {:<45}| {}\n",
get_timestamp(host_tm, host_ts),
ll.thread_id,
preamble,
Expand All @@ -244,11 +192,9 @@ namespace ccf::logger
class TextConsoleLogger : public AbstractLogger
{
public:
void write(
const LogLine& ll,
const std::optional<double>& enclave_offset = std::nullopt) override
void write(const LogLine& ll) override
{
emit(format_to_text(ll, enclave_offset));
emit(format_to_text(ll));
}
};

Expand Down