Skip to content

Commit

Permalink
Move util/os.h dependency to the compiled library
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Artsishevsky <polter.rnd@gmail.com>
  • Loading branch information
polter-rnd committed Nov 27, 2024
1 parent 6ea7ded commit 2d75422
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
18 changes: 18 additions & 0 deletions include/slimlog/sink-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
#endif

#include <slimlog/level.h>
#include <slimlog/location.h>
#include <slimlog/pattern.h>
#include <slimlog/policy.h>
#include <slimlog/record.h>
#include <slimlog/util/os.h>

#include <algorithm> // IWYU pragma: keep
#include <cstddef>
#include <initializer_list>
#include <iterator>
#include <memory>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -146,6 +151,19 @@ auto SinkDriver<Logger, ThreadingPolicy>::remove_child(SinkDriver* child) -> voi
m_children.erase(child);
}

template<typename Logger, typename ThreadingPolicy>
auto SinkDriver<Logger, ThreadingPolicy>::create_record(
Level level, StringViewType category, Location location) -> RecordType
{
RecordType record = {
level,
{location.file_name(), location.function_name(), static_cast<std::size_t>(location.line())},
std::move(category),
Util::OS::thread_id()};
std::tie(record.time.local, record.time.nsec) = Util::OS::local_time();
return record;
}

template<typename Logger, typename ThreadingPolicy>
auto SinkDriver<Logger, ThreadingPolicy>::update_effective_sinks(SinkDriver* driver) -> SinkDriver*
{
Expand Down
26 changes: 14 additions & 12 deletions include/slimlog/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
#include <slimlog/pattern.h>
#include <slimlog/policy.h>
#include <slimlog/record.h>
#include <slimlog/util/os.h>

#include <cstddef>
#include <initializer_list>
#include <memory>
#include <tuple>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -259,15 +257,7 @@ class SinkDriver final {
Args&&... args) const -> void
{
FormatBufferType buffer; // NOLINT(misc-const-correctness)
RecordType record
= {level,
{location.file_name(),
location.function_name(),
static_cast<std::size_t>(location.line())},
std::move(category),
Util::OS::thread_id()};
std::tie(record.time.local, record.time.nsec) = Util::OS::local_time();
// MOVE THIS TO SEPARATE INL FUNC?
RecordType record = create_record(level, location, std::move(category));

// Flag to check that message has been evaluated
bool evaluated = false;
Expand Down Expand Up @@ -342,6 +332,18 @@ class SinkDriver final {
*/
auto remove_child(SinkDriver* child) -> void;

/**
* @brief Create a new log record.
*
* This function creates a new log record with the specified log level, category, and location.
*
* @param level The log level of the record.
* @param category The category or module name associated with the log record.
* @param location The source code location where the log record is created.
* @return A new log record of type `RecordType`.
*/
auto create_record(Level level, StringViewType category, Location location) -> RecordType;

private:
/**
* @brief Recursively updates the effective sinks for
Expand Down

0 comments on commit 2d75422

Please sign in to comment.