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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Public headers are installed from `src/aether-objects`, and the library target i
lifetime contracts.
- Keep serialization formats, object IDs, ownership and reference tracking,
persistence behavior, and threading behavior compatible.
- Use `LOG_` macros for local debug logging.
- Use `AE_LOG_MACRO` macros for local debug logging.
- Manage dependencies through CPM; do not vendor, edit, or copy dependency
sources without explicit approval.

Expand Down Expand Up @@ -52,7 +52,7 @@ Preserve their serialized representation and error behavior.

### Logging (`log.h`)

`LOG_` is the local debug logging boundary. It writes formatted messages in
`AE_LOG_MACRO` is the local debug logging boundary. It writes formatted messages in
debug builds unless `AE_NO_DEBUG_LOG` disables it, and compiles away in release
builds. Preserve this behavior.

Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ endif()
option(AE_BUILD_TESTS "Build tests" ${IS_ROOT_PROJECT} )
option(AE_INSTALL "Install aether-objects library" ${IS_ROOT_PROJECT} )
option(AE_NO_DEBUG_LOG "Do not print debug logs" !${IS_ROOT_PROJECT} )
set(AE_LOGGER_INCLUDE "" CACHE STRING "Custom header for logger")

include(cmake/CPM.cmake)

Expand Down Expand Up @@ -66,6 +67,9 @@ target_include_directories(${PROJECT_NAME} PUBLIC

target_link_libraries(${PROJECT_NAME} PUBLIC aether::miscpp)

if(NOT "${AE_LOGGER_INCLUDE}" STREQUAL "")
target_compile_definitions(${PROJECT_NAME} PUBLIC "AE_LOGGER_INCLUDE=${AE_LOGGER_INCLUDE}")
endif()
if(AE_NO_DEBUG_LOG)
target_compile_definitions(${PROJECT_NAME} PUBLIC "AE_NO_DEBUG_LOG=1")
endif()
Expand Down
29 changes: 15 additions & 14 deletions src/aether-objects/domain_storage/file_system_std_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class FstreamStorageWriter final : public IDomainStorageWriter {

~FstreamStorageWriter() override {
file.close();
LOG_("Saved object id={}, class id={}, version={}, size={}", query.id,
query.class_id, static_cast<int>(query.version), written_size);
AE_LOG_MACRO("Saved object id={}, class id={}, version={}, size={}",
query.id, query.class_id, static_cast<int>(query.version),
written_size);
}

seri::SeriResult Write(seri::SizeWriteTag data) override {
Expand Down Expand Up @@ -123,10 +124,10 @@ ClassList FileSystemStdStorage::Enumerate(const ae::ObjId& obj_id) {
auto file_name = class_dir.path().filename().string();
classes.insert(static_cast<std::uint32_t>(std::stoul(file_name)));
}
LOG_("Enumerated classes {}", classes);
AE_LOG_MACRO("Enumerated classes {}", classes);

if (ec) {
LOG_("Unable to open directory with error {}", ec.message());
AE_LOG_MACRO("Unable to open directory with error {}", ec.message());
}

return ClassList{classes.begin(), classes.end()};
Expand All @@ -152,12 +153,12 @@ DomainLoad FileSystemStdStorage::Load(DomainQuery const& query) {
auto version_data_path = class_dir / std::to_string(query.version);
std::ifstream f(version_data_path, std::ios::in | std::ios::binary);
if (!f.good()) {
LOG_("Unable to open file {}", version_data_path.string());
AE_LOG_MACRO("Unable to open file {}", version_data_path.string());
return DomainLoad{DomainLoadResult::kEmpty, {}};
}

LOG_("Loaded object id={}, class id={}, version={}", query.id, query.class_id,
static_cast<int>(query.version));
AE_LOG_MACRO("Loaded object id={}, class id={}, version={}", query.id,
query.class_id, static_cast<int>(query.version));

return {DomainLoadResult::kLoaded,
std::make_unique<FstreamStorageReader>(std::move(f))};
Expand All @@ -172,8 +173,8 @@ void FileSystemStdStorage::Remove(ae::ObjId const& obj_id) {
return;
}
if (ec) {
LOG_("Unable to check if dir exists {} error {}", object_dir.string(),
ec.message());
AE_LOG_MACRO("Unable to check if dir exists {} error {}",
object_dir.string(), ec.message());
return;
}

Expand All @@ -182,20 +183,20 @@ void FileSystemStdStorage::Remove(ae::ObjId const& obj_id) {
auto ec2 = std::error_code{};
std::filesystem::remove_all(class_dir.path(), ec2);
if (ec2) {
LOG_("Unable to remove dir {}, error {}", class_dir.path().string(),
ec2.message());
AE_LOG_MACRO("Unable to remove dir {}, error {}",
class_dir.path().string(), ec2.message());
continue;
}
LOG_("Object removed {}", obj_id);
AE_LOG_MACRO("Object removed {}", obj_id);
}
if (ec) {
LOG_("Unable to open directory with error {}", ec.message());
AE_LOG_MACRO("Unable to open directory with error {}", ec.message());
}
}

void FileSystemStdStorage::CleanUp() {
std::filesystem::remove_all("state");
LOG_("Removed all!", 0);
AE_LOG_MACRO("Removed all!", 0);
}
} // namespace ae

Expand Down
28 changes: 14 additions & 14 deletions src/aether-objects/domain_storage/ram_domain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ std::unique_ptr<IDomainStorageWriter> RamDomainStorage::Store(
ClassList RamDomainStorage::Enumerate(ObjId const& obj_id) {
auto obj_map_it = state.find(obj_id);
if (obj_map_it == std::end(state)) {
LOG_("Obj not found {}", obj_id);
AE_LOG_MACRO("Obj not found {}", obj_id);
return {};
}
if (!obj_map_it->second) {
Expand All @@ -103,15 +103,15 @@ ClassList RamDomainStorage::Enumerate(ObjId const& obj_id) {
for (auto& [cls, _] : *obj_map_it->second) {
classes.emplace_back(cls);
}
LOG_("Enumerated for obj {} classes {}", obj_id, classes);
AE_LOG_MACRO("Enumerated for obj {} classes {}", obj_id, classes);
return classes;
}

DomainLoad RamDomainStorage::Load(DomainQuery const& query) {
auto obj_map_it = state.find(query.id);
if (obj_map_it == std::end(state)) {
LOG_("Unable to find object id={}, class id={}, version={}", query.id,
query.class_id, static_cast<int>(query.version));
AE_LOG_MACRO("Unable to find object id={}, class id={}, version={}",
query.id, query.class_id, static_cast<int>(query.version));
return {DomainLoadResult::kEmpty, {}};
}
if (!obj_map_it->second) {
Expand All @@ -120,20 +120,20 @@ DomainLoad RamDomainStorage::Load(DomainQuery const& query) {

auto class_map_it = obj_map_it->second->find(query.class_id);
if (class_map_it == std::end(*obj_map_it->second)) {
LOG_("Unable to find object id={}, class id={}, version={}", query.id,
query.class_id, static_cast<int>(query.version));
AE_LOG_MACRO("Unable to find object id={}, class id={}, version={}",
query.id, query.class_id, static_cast<int>(query.version));
return {DomainLoadResult::kEmpty, {}};
}
auto version_it = class_map_it->second.find(query.version);
if (version_it == std::end(class_map_it->second)) {
LOG_("Unable to find object id={}, class id={}, version={}", query.id,
query.class_id, static_cast<int>(query.version));
AE_LOG_MACRO("Unable to find object id={}, class id={}, version={}",
query.id, query.class_id, static_cast<int>(query.version));
return {DomainLoadResult::kEmpty, {}};
}

LOG_("Loaded object id={}, class id={}, version={}, size={}", query.id,
query.class_id, static_cast<int>(query.version),
version_it->second.size());
AE_LOG_MACRO("Loaded object id={}, class id={}, version={}, size={}",
query.id, query.class_id, static_cast<int>(query.version),
version_it->second.size());

return {DomainLoadResult::kLoaded,
std::make_unique<RamDomainStorageReader>(version_it->second, *this)};
Expand All @@ -147,7 +147,7 @@ void RamDomainStorage::Remove(ObjId const& obj_id) {
}

obj_map_it->second.reset();
LOG_("Removed object {}", obj_id);
AE_LOG_MACRO("Removed object {}", obj_id);
}

void RamDomainStorage::CleanUp() { state.clear(); }
Expand All @@ -159,8 +159,8 @@ void RamDomainStorage::SaveData(DomainQuery const& query, ObjectData&& data) {
}
auto& saved = (*objcect_classes)[query.class_id][query.version];
saved = std::move(data);
LOG_("Saved object id={}, class id={}, version={}, size={}", query.id,
query.class_id, std::to_string(query.version), saved.size());
AE_LOG_MACRO("Saved object id={}, class id={}, version={}, size={}", query.id,
query.class_id, std::to_string(query.version), saved.size());
}

} // namespace ae
30 changes: 18 additions & 12 deletions src/aether-objects/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@
#ifndef AETHER_OBJECTS_LOG_H_
#define AETHER_OBJECTS_LOG_H_

#ifdef AE_LOGGER_INCLUDE
# include AE_LOGGER_INCLUDE
#endif

// IWYU pragma: begin_exports
#include <iostream>
#include "aether-miscpp/format/format.h"
// IWYU pragma: end_exports

#ifndef AE_NO_DEBUG_LOG
# define AE_NO_DEBUG_LOG 0
#ifndef AE_LOG_MACRO
# ifndef AE_NO_DEBUG_LOG
# define AE_NO_DEBUG_LOG 0
# endif
# if !defined NDEBUG && !AE_NO_DEBUG_LOG
# define AE_LOG_MACRO(FORMAT_STR, ...) \
do { \
::ae::Format(std::cout, "OBJ_SYS:[{:time}]:" FORMAT_STR "\n", \
std::chrono::system_clock::now() __VA_OPT__(, ) \
__VA_ARGS__); \
} while (false)
# else
# define AE_LOG_MACRO(FORMAT_STR, ...)
# endif
#endif

#if !defined NDEBUG && !AE_NO_DEBUG_LOG
# define LOG_(FORMAT_STR, ...) \
do { \
::ae::Format(std::cout, FORMAT_STR "\n" __VA_OPT__(, ) __VA_ARGS__); \
} while (false)
#else
# define LOG_(FORMAT_STR, ...)
#endif

#endif // AETHER_OBJECTS_LOG_H_
4 changes: 2 additions & 2 deletions src/aether-objects/obj/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ Factory* Domain::GetMostRelatedFactory(ObjId id) {
class_names.emplace_back(registry_->ClassName(cid));
}

LOG_("For obj {} enumerated classes [{}]", id.id(), class_names);
AE_LOG_MACRO("For obj {} enumerated classes [{}]", id.id(), class_names);
#else
LOG_("For obj {} enumerated classes [{}]", id.id(), classes);
AE_LOG_MACRO("For obj {} enumerated classes [{}]", id.id(), classes);
#endif

// Remove all unsupported classes.
Expand Down
4 changes: 2 additions & 2 deletions src/aether-objects/obj/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ std::string_view Registry::ClassName(std::uint32_t class_id) {
void Registry::Log() {
#ifndef NDEBUG
for (const auto& c : factories) {
LOG_("name {}, id {}, base_id {}", c.second.class_name, c.second.cls_id,
c.second.base_id);
AE_LOG_MACRO("name {}, id {}, base_id {}", c.second.class_name,
c.second.cls_id, c.second.base_id);
}
#endif // !NDEBUG
}
Expand Down
Loading