Compare commits

..

No commits in common. "311b20bdf2bc0dd18af882abcc42a08efe0fc69d" and "4534ed11d2a00c7e0f2bd3bb8446667597b4a4e0" have entirely different histories.

17 changed files with 79 additions and 219 deletions

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <app/application.hpp> #include <app/application.hpp>
#include <logger/logger.hpp>
#include <memory/scope.hpp> #include <memory/scope.hpp>
auto main(int argc, char *argv[]) -> int32_t auto main(int argc, char *argv[]) -> int32_t
@ -22,7 +21,7 @@ try
} }
catch (const std::exception &exp) catch (const std::exception &exp)
{ {
lt::log::critical("Terminating due to uncaught exception:"); log_crt("Terminating due to uncaught exception:");
lt::log::critical("\texception.what(): {}", exp.what()); log_crt("\texception.what(): {}", exp.what());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <chrono> #include <chrono>
#include <logger/logger.hpp>
namespace lt::app { namespace lt::app {
@ -73,7 +72,7 @@ public:
{ {
auto diag = m_diagnosis.emplace_back(std::move(diagnosis)); auto diag = m_diagnosis.emplace_back(std::move(diagnosis));
log::debug("message: {}", diag.message); log_dbg("message: {}", diag.message);
} }
[[nodiscard]] auto empty_diagnosis() const -> bool [[nodiscard]] auto empty_diagnosis() const -> bool

View file

@ -1,6 +1,5 @@
#include <asset_baker/bakers.hpp> #include <asset_baker/bakers.hpp>
#include <assets/shader.hpp> #include <assets/shader.hpp>
#include <logger/logger.hpp>
auto main(int argc, char *argv[]) -> int32_t auto main(int argc, char *argv[]) -> int32_t
try try
@ -35,8 +34,8 @@ try
} }
catch (const std::exception &exp) catch (const std::exception &exp)
{ {
lt::log::critical("Terminating due to uncaught exception:"); log_crt("Terminating due to uncaught exception:");
lt::log::critical("\texception.what: {}:", exp.what()); log_crt("\texception.what: {}:", exp.what());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <assets/shader.hpp> #include <assets/shader.hpp>
#include <logger/logger.hpp>
inline void bake_shader( inline void bake_shader(
const std::filesystem::path &in_path, const std::filesystem::path &in_path,
@ -14,7 +13,7 @@ inline void bake_shader(
auto glsl_path = in_path.string(); auto glsl_path = in_path.string();
auto spv_path = std::format("{}.spv", glsl_path); auto spv_path = std::format("{}.spv", glsl_path);
lt::log::trace( log_trc(
"Compiling {} shader {} -> {}", "Compiling {} shader {} -> {}",
type == vertex ? "vertex" : "fragment", type == vertex ? "vertex" : "fragment",
glsl_path, glsl_path,
@ -47,7 +46,7 @@ inline void bake_shader(
auto bytes = std::vector<std::byte>(size); auto bytes = std::vector<std::byte>(size);
stream.seekg(0, std::ios::beg); stream.seekg(0, std::ios::beg);
stream.read((char *)bytes.data(), size); // NOLINT stream.read((char *)bytes.data(), size); // NOLINT
lt::log::debug("BYTES: {}", bytes.size()); log_dbg("BYTES: {}", bytes.size());
stream.close(); stream.close();
std::filesystem::remove(spv_path); std::filesystem::remove(spv_path);

View file

@ -15,7 +15,7 @@ void Instrumentor::end_session_impl()
{ {
if (m_current_session_count == 0u) if (m_current_session_count == 0u)
{ {
log::warn("0 profiling for the ended session"); log_wrn("0 profiling for the ended session");
} }
m_current_session_count = 0u; m_current_session_count = 0u;

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <format> #include <format>
#include <logger/logger.hpp>
#include <source_location> #include <source_location>
namespace lt { namespace lt {
@ -27,6 +28,7 @@ struct ensure
} }
}; };
template<typename Expression_T, typename... Args_T> template<typename Expression_T, typename... Args_T>
ensure(Expression_T, std::format_string<Args_T...>, Args_T &&...) ensure(Expression_T, std::format_string<Args_T...>, Args_T &&...)
-> ensure<Expression_T, Args_T...>; -> ensure<Expression_T, Args_T...>;

View file

@ -55,10 +55,10 @@ public:
auto new_capacity = std::max(static_cast<size_t>(identifier + 1), m_sparse.size() * 2); auto new_capacity = std::max(static_cast<size_t>(identifier + 1), m_sparse.size() * 2);
new_capacity = std::min(new_capacity, max_capacity); new_capacity = std::min(new_capacity, max_capacity);
// log::debug("Increasing sparse vector size:", m_dead_count); // log_dbg("Increasing sparse vector size:", m_dead_count);
// log::debug("\tdead_count: {}", m_dead_count); // log_dbg("\tdead_count: {}", m_dead_count);
// log::debug("\talive_count: {}", m_alive_count); // log_dbg("\talive_count: {}", m_alive_count);
// log::debug("\tsparse.size: {} -> {}", m_sparse.size(), new_capacity); // log_dbg("\tsparse.size: {} -> {}", m_sparse.size(), new_capacity);
m_sparse.resize(new_capacity, null_identifier); m_sparse.resize(new_capacity, null_identifier);
} }

View file

@ -101,7 +101,7 @@ void System::on_key_press(const lt::surface::KeyPressedEvent &event)
{ {
if (event.get_key() > m_keys.size()) if (event.get_key() > m_keys.size())
{ {
log::debug( log_dbg(
"Key code larger than key container size, implement platform-dependant " "Key code larger than key container size, implement platform-dependant "
"key-code-mapping!" "key-code-mapping!"
); );
@ -116,7 +116,7 @@ void System::on_key_release(const lt::surface::KeyReleasedEvent &event)
{ {
if (event.get_key() > m_keys.size()) if (event.get_key() > m_keys.size())
{ {
log::debug( log_dbg(
"Key code larger than key container size, implement platform-dependant " "Key code larger than key container size, implement platform-dependant "
"key-code-mapping!" "key-code-mapping!"
); );

View file

@ -1,2 +1 @@
add_library_module(logger) add_library_module(logger logger.cpp)
add_test_module(logger logger.test.cpp)

View file

@ -0,0 +1 @@
#include <logger/logger.hpp>

View file

@ -1,25 +0,0 @@
#include <logger/logger.hpp>
#include <test/test.hpp>
using ::lt::test::Case;
using ::lt::test::Suite;
Suite suite = [] {
Case { "no format" } = [] {
lt::log::trace("trace");
lt::log::debug("debug");
lt::log::info("info");
lt::log::warn("warn");
lt::log::error("error");
lt::log::critical("critical");
};
Case { "formatted" } = [] {
lt::log::trace("trace {}", 69);
lt::log::debug("debug {}", 69);
lt::log::info("info {}", 69);
lt::log::warn("warn {}", 69);
lt::log::error("error {}", 69);
lt::log::critical("critical {}", 69);
};
};

View file

@ -1,17 +1,10 @@
#pragma once #pragma once
#include <cstdint> #include <format>
#include <filesystem> #include <print>
#include <fmt/chrono.h>
#include <fmt/format.h>
#include <source_location>
#include <thread>
#include <utility>
namespace lt::log {
/** Severity of a log message. */ /** Severity of a log message. */
enum class Level : uint8_t enum class LogLvl : uint8_t
{ {
/** Lowest and most vebose log level, for tracing execution paths and events */ /** Lowest and most vebose log level, for tracing execution paths and events */
trace = 0, trace = 0,
@ -35,152 +28,62 @@ enum class Level : uint8_t
off = 6, off = 6,
}; };
namespace details { /** Simple console logger */
class Logger
inline auto thread_hash_id() noexcept -> std::uint64_t
{ {
return static_cast<std::uint64_t>(std::hash<std::thread::id> {}(std::this_thread::get_id())); public:
} void static show_imgui_window();
} // namespace details
template<typename... Args> template<typename... Args>
struct [[maybe_unused]] print void static log(LogLvl lvl, std::format_string<Args...> fmt, Args &&...args) noexcept
{ {
[[maybe_unused]] print( std::ignore = lvl;
Level level, std::println(fmt, std::forward<Args>(args)...);
const std::source_location &location,
std::format_string<Args...> format,
Args &&...arguments
) noexcept
{
constexpr auto to_string = [](Level level, auto location) {
// clang-format off
switch (level)
{
using enum Level;
case trace : return "\033[1;37m| trc |\033[0m";
case debug : return "\033[1;36m| dbg |\033[0m";
case info : return "\033[1;32m| inf |\033[0m";
case warn : return "\033[1;33m| wrn |\033[0m";
case error : return "\033[1;31m| err |\033[0m";
case critical: return "\033[1;41m| crt |\033[0m";
case off: return "off";
} }
// clang-format on
std::unreachable(); void static log(LogLvl lvl, const char *message) noexcept
}; {
std::ignore = lvl;
const auto path = std::filesystem::path { location.file_name() }; std::println("{}", message);
std::println(
"{} {} ==> {}",
to_string(level, location),
std::format("{}:{}", path.filename().c_str(), location.line()),
std::format(format, std::forward<Args>(arguments)...)
);
} }
private:
Logger() = default;
}; };
template<typename... Args> template<typename... Args>
print(Level, const std::source_location &, std::format_string<Args...>, Args &&...) noexcept void log_trc(std::format_string<Args...> fmt, Args &&...args) noexcept
-> print<Args...>;
template<typename... Args>
struct [[maybe_unused]] trace
{ {
[[maybe_unused]] trace( Logger::log(LogLvl::trace, fmt, std::forward<Args>(args)...);
std::format_string<Args...> format,
Args &&...arguments,
const std::source_location &location = std::source_location::current()
) noexcept
{
print(Level::trace, location, format, std::forward<Args>(arguments)...);
} }
};
template<typename... Args> template<typename... Args>
trace(std::format_string<Args...>, Args &&...) noexcept -> trace<Args...>; void log_dbg(std::format_string<Args...> fmt, Args &&...args) noexcept
template<typename... Args>
struct [[maybe_unused]] debug
{ {
[[maybe_unused]] debug( Logger::log(LogLvl::debug, fmt, std::forward<Args>(args)...);
std::format_string<Args...> format,
Args &&...arguments,
const std::source_location &location = std::source_location::current()
) noexcept
{
print(Level::debug, location, format, std::forward<Args>(arguments)...);
} }
};
template<typename... Args> template<typename... Args>
debug(std::format_string<Args...>, Args &&...) noexcept -> debug<Args...>; void log_inf(std::format_string<Args...> fmt, Args &&...args) noexcept
template<typename... Args>
struct [[maybe_unused]] info
{ {
[[maybe_unused]] info( Logger::log(LogLvl::info, fmt, std::forward<Args>(args)...);
std::format_string<Args...> format,
Args &&...arguments,
const std::source_location &location = std::source_location::current()
) noexcept
{
print(Level::info, location, format, std::forward<Args>(arguments)...);
} }
};
template<typename... Args> template<typename... Args>
info(std::format_string<Args...>, Args &&...) noexcept -> info<Args...>; void log_wrn(std::format_string<Args...> fmt, Args &&...args) noexcept
template<typename... Args>
struct [[maybe_unused]] warn
{ {
[[maybe_unused]] warn( Logger::log(LogLvl::warn, fmt, std::forward<Args>(args)...);
std::format_string<Args...> format,
Args &&...arguments,
const std::source_location &location = std::source_location::current()
) noexcept
{
print(Level::warn, location, format, std::forward<Args>(arguments)...);
} }
};
template<typename... Args> template<typename... Args>
warn(std::format_string<Args...>, Args &&...) noexcept -> warn<Args...>; void log_err(std::format_string<Args...> fmt, Args &&...args) noexcept
template<typename... Args>
struct [[maybe_unused]] error
{ {
[[maybe_unused]] error( Logger::log(LogLvl::error, fmt, std::forward<Args>(args)...);
std::format_string<Args...> format,
Args &&...arguments,
const std::source_location &location = std::source_location::current()
) noexcept
{
print(Level::error, location, format, std::forward<Args>(arguments)...);
} }
};
template<typename... Args> template<typename... Args>
error(std::format_string<Args...>, Args &&...) noexcept -> error<Args...>; void log_crt(std::format_string<Args...> fmt, Args &&...args) noexcept
template<typename... Args>
struct [[maybe_unused]] critical
{ {
[[maybe_unused]] critical( Logger::log(LogLvl::critical, fmt, std::forward<Args>(args)...);
std::format_string<Args...> format,
Args &&...arguments,
const std::source_location &location = std::source_location::current()
) noexcept
{
print(Level::critical, location, format, std::forward<Args>(arguments)...);
} }
};
template<typename... Args>
critical(std::format_string<Args...>, Args &&...) noexcept -> critical<Args...>;
} // namespace lt::log

View file

@ -1,16 +0,0 @@
#pragma once
#include <math/vec3.hpp>
namespace lt::math::components {
struct Transform
{
math::vec3 translation;
math::vec3 scale;
math::vec3 rotation;
};
} // namespace lt::math::components

View file

@ -91,8 +91,8 @@ System::~System()
} }
catch (const std::exception &exp) catch (const std::exception &exp)
{ {
log::error("Uncaught exception in surface::~System:"); log_err("Uncaught exception in surface::~System:");
log::error("\twhat: {}", exp.what()); log_err("\twhat: {}", exp.what());
} }
} }
@ -189,9 +189,9 @@ try
} }
catch (const std::exception &exp) catch (const std::exception &exp)
{ {
log::error("Exception thrown when on_constructing surface component"); log_err("Exception thrown when on_constructing surface component");
log::error("\tentity: {}", entity); log_err("\tentity: {}", entity);
log::error("\twhat: {}", exp.what()); log_err("\twhat: {}", exp.what());
m_registry->remove<SurfaceComponent>(entity); m_registry->remove<SurfaceComponent>(entity);
} }
@ -200,7 +200,7 @@ void System::on_surface_destruct(ecs::Registry &registry, ecs::EntityId entity)
const auto &[display, window, _] = registry.get<SurfaceComponent>(entity).get_native_data(); const auto &[display, window, _] = registry.get<SurfaceComponent>(entity).get_native_data();
if (!display) if (!display)
{ {
log::warn("Surface component destroyed with null display"); log_wrn("Surface component destroyed with null display");
return; return;
} }
@ -316,7 +316,7 @@ void System::handle_requests(SurfaceComponent &surface)
[&](const ModifyResolutionRequest &request) { modify_resolution(surface, request); }, [&](const ModifyResolutionRequest &request) { modify_resolution(surface, request); },
[&](const ModifyPositionRequest &request) { modify_position(surface, request); }, [&](const ModifyPositionRequest &request) { modify_position(surface, request); },
[&](const ModifyVisibilityRequest &request) { modify_visiblity(surface, request); }, [&](const ModifyVisibilityRequest &request) { modify_visiblity(surface, request); },
[&](const auto &) { log::error("Unknown surface request"); }, [&](const auto &) { log_err("Unknown surface request"); },
}; };
for (const auto &request : surface.peek_requests()) for (const auto &request : surface.peek_requests())
@ -380,7 +380,7 @@ void System::modify_resolution(SurfaceComponent &surface, const ModifyResolution
std::this_thread::sleep_for(std::chrono::microseconds { 100 }); std::this_thread::sleep_for(std::chrono::microseconds { 100 });
if (timer.elapsed_time() > lifespan) if (timer.elapsed_time() > lifespan)
{ {
log::error("Timed out waiting for XResizeWindow's event"); log_err("Timed out waiting for XResizeWindow's event");
return; return;
} }
} }
@ -419,7 +419,7 @@ void System::modify_position(SurfaceComponent &surface, const ModifyPositionRequ
std::this_thread::sleep_for(std::chrono::microseconds { 100 }); std::this_thread::sleep_for(std::chrono::microseconds { 100 });
if (timer.elapsed_time() > lifespan) if (timer.elapsed_time() > lifespan)
{ {
log::error("Timed out waiting for XMoveWindow's event"); log_err("Timed out waiting for XMoveWindow's event");
return; return;
} }
} }

View file

@ -268,11 +268,11 @@ Suite tick_handles_requests = "tick_handles_requests"_suite = [] {
expect_eq(surface.get_position(), position); expect_eq(surface.get_position(), position);
expect_eq(surface.get_resolution(), resolution); expect_eq(surface.get_resolution(), resolution);
log::debug("EVENT COUNT: {}", surface.peek_events().size()); log_dbg("EVENT COUNT: {}", surface.peek_events().size());
for (const auto &event : surface.peek_events()) for (const auto &event : surface.peek_events())
{ {
const auto visitor = overloads { const auto visitor = overloads {
[&](auto event) { log::debug("event: {}", event.to_string()); }, [&](auto event) { log_dbg("event: {}", event.to_string()); },
}; };
std::visit(visitor, event); std::visit(visitor, event);

View file

@ -1,7 +1,7 @@
add_library_module(test test.cpp entrypoint.cpp) add_library_module(test test.cpp entrypoint.cpp)
add_library_module(fuzz_test test.cpp fuzz.cpp) add_library_module(fuzz_test test.cpp fuzz.cpp)
target_link_libraries(test PUBLIC logger) target_link_libraries(test PUBLIC tbb logger)
target_link_libraries(fuzz_test PUBLIC logger) target_link_libraries(fuzz_test PUBLIC tbb logger)
add_test_module(test test.test.cpp) add_test_module(test test.test.cpp)

View file

@ -85,14 +85,14 @@ try
} }
catch (const std::exception &exp) catch (const std::exception &exp)
{ {
lt::log::critical("Terminated due to uncaught exception:"); log_crt("Terminated due to uncaught exception:");
lt::log::critical("\twhat: {}", exp.what()); log_crt("\twhat: {}", exp.what());
return EXIT_FAILURE; return EXIT_FAILURE;
} }
catch (...) catch (...)
{ {
lt::log::critical("Terminated due to uncaught non-std exception!"); log_crt("Terminated due to uncaught non-std exception!");
return EXIT_FAILURE; return EXIT_FAILURE;
} }