Skip to content

Commit

Permalink
#678: restore logger code
Browse files Browse the repository at this point in the history
  • Loading branch information
cwschilly committed Sep 23, 2024
1 parent f9facc9 commit 28ca64f
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 59 deletions.
1 change: 0 additions & 1 deletion include/pressio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

#include "./mpl.hpp"
#include <iomanip>
#include <memory>

#include "./utils/utils_static_constants.hpp"
#include "./utils/utils_instance_or_reference_wrapper.hpp"
Expand Down
16 changes: 16 additions & 0 deletions include/pressio/utils/logger/spdlog/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ struct source_loc
int line{0};
const char *funcname{nullptr};
};

namespace details {
// make_unique support for pre c++14

#if __cplusplus >= 201402L // C++14 and beyond
using std::make_unique;
#else
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args &&...args)
{
static_assert(!std::is_array<T>::value, "arrays not supported");
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
#endif

} // namespace details
} // namespace spdlog


Expand Down
2 changes: 1 addition & 1 deletion include/pressio/utils/logger/spdlog/details/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class registry
{
std::lock_guard<std::mutex> lock(flusher_mutex_);
auto clbk = [this]() { this->flush_all(); };
periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
}

void set_error_handler(void (*handler)(const std::string &msg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace details {
// {
// std::lock_guard<std::mutex> lock(flusher_mutex_);
// auto clbk = [this]() { this->flush_all(); };
// periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
// periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
// }

// SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string &msg))
Expand Down
2 changes: 1 addition & 1 deletion include/pressio/utils/logger/spdlog/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class logger

void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local)
{
auto new_formatter = std::make_unique<pattern_formatter>(std::move(pattern), time_type);
auto new_formatter = details::make_unique<pattern_formatter>(std::move(pattern), time_type);
set_formatter(std::move(new_formatter));
}

Expand Down
92 changes: 46 additions & 46 deletions include/pressio/utils/logger/spdlog/pattern_formatter-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ inline pattern_formatter::pattern_formatter(pattern_time_type time_type, std::st
, last_log_secs_(0)
{
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
formatters_.push_back(std::make_unique<details::full_formatter>(details::padding_info{}));
formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info{}));
}

template<typename Padder>
Expand All @@ -1041,178 +1041,178 @@ inline void pattern_formatter::handle_flag_(char /*flag*/, details::padding_info
// switch (flag)
// {
// case ('+'): // default formatter
// formatters_.push_back(std::make_unique<details::full_formatter>(padding));
// formatters_.push_back(details::make_unique<details::full_formatter>(padding));
// break;

// case 'n': // logger name
// formatters_.push_back(std::make_unique<details::name_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::name_formatter<Padder>>(padding));
// break;

// case 'l': // level
// formatters_.push_back(std::make_unique<details::level_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::level_formatter<Padder>>(padding));
// break;

// case 'L': // short level
// formatters_.push_back(std::make_unique<details::short_level_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::short_level_formatter<Padder>>(padding));
// break;

// case ('t'): // thread id
// formatters_.push_back(std::make_unique<details::t_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::t_formatter<Padder>>(padding));
// break;

// case ('v'): // the message text
// formatters_.push_back(std::make_unique<details::v_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::v_formatter<Padder>>(padding));
// break;

// case ('a'): // weekday
// formatters_.push_back(std::make_unique<details::a_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::a_formatter<Padder>>(padding));
// break;

// case ('A'): // short weekday
// formatters_.push_back(std::make_unique<details::A_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::A_formatter<Padder>>(padding));
// break;

// case ('b'):
// case ('h'): // month
// formatters_.push_back(std::make_unique<details::b_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::b_formatter<Padder>>(padding));
// break;

// case ('B'): // short month
// formatters_.push_back(std::make_unique<details::B_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::B_formatter<Padder>>(padding));
// break;

// case ('c'): // datetime
// formatters_.push_back(std::make_unique<details::c_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::c_formatter<Padder>>(padding));
// break;

// case ('C'): // year 2 digits
// formatters_.push_back(std::make_unique<details::C_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::C_formatter<Padder>>(padding));
// break;

// case ('Y'): // year 4 digits
// formatters_.push_back(std::make_unique<details::Y_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::Y_formatter<Padder>>(padding));
// break;

// case ('D'):
// case ('x'): // datetime MM/DD/YY
// formatters_.push_back(std::make_unique<details::D_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::D_formatter<Padder>>(padding));
// break;

// case ('m'): // month 1-12
// formatters_.push_back(std::make_unique<details::m_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::m_formatter<Padder>>(padding));
// break;

// case ('d'): // day of month 1-31
// formatters_.push_back(std::make_unique<details::d_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::d_formatter<Padder>>(padding));
// break;

// case ('H'): // hours 24
// formatters_.push_back(std::make_unique<details::H_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::H_formatter<Padder>>(padding));
// break;

// case ('I'): // hours 12
// formatters_.push_back(std::make_unique<details::I_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::I_formatter<Padder>>(padding));
// break;

// case ('M'): // minutes
// formatters_.push_back(std::make_unique<details::M_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::M_formatter<Padder>>(padding));
// break;

// case ('S'): // seconds
// formatters_.push_back(std::make_unique<details::S_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::S_formatter<Padder>>(padding));
// break;

// case ('e'): // milliseconds
// formatters_.push_back(std::make_unique<details::e_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::e_formatter<Padder>>(padding));
// break;

// case ('f'): // microseconds
// formatters_.push_back(std::make_unique<details::f_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::f_formatter<Padder>>(padding));
// break;

// case ('F'): // nanoseconds
// formatters_.push_back(std::make_unique<details::F_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::F_formatter<Padder>>(padding));
// break;

// case ('E'): // seconds since epoch
// formatters_.push_back(std::make_unique<details::E_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::E_formatter<Padder>>(padding));
// break;

// case ('p'): // am/pm
// formatters_.push_back(std::make_unique<details::p_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::p_formatter<Padder>>(padding));
// break;

// case ('r'): // 12 hour clock 02:55:02 pm
// formatters_.push_back(std::make_unique<details::r_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::r_formatter<Padder>>(padding));
// break;

// case ('R'): // 24-hour HH:MM time
// formatters_.push_back(std::make_unique<details::R_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::R_formatter<Padder>>(padding));
// break;

// case ('T'):
// case ('X'): // ISO 8601 time format (HH:MM:SS)
// formatters_.push_back(std::make_unique<details::T_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::T_formatter<Padder>>(padding));
// break;

// case ('z'): // timezone
// formatters_.push_back(std::make_unique<details::z_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::z_formatter<Padder>>(padding));
// break;

// case ('P'): // pid
// formatters_.push_back(std::make_unique<details::pid_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::pid_formatter<Padder>>(padding));
// break;

// case ('^'): // color range start
// formatters_.push_back(std::make_unique<details::color_start_formatter>(padding));
// formatters_.push_back(details::make_unique<details::color_start_formatter>(padding));
// break;

// case ('$'): // color range end
// formatters_.push_back(std::make_unique<details::color_stop_formatter>(padding));
// formatters_.push_back(details::make_unique<details::color_stop_formatter>(padding));
// break;

// case ('@'): // source location (filename:filenumber)
// formatters_.push_back(std::make_unique<details::source_location_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::source_location_formatter<Padder>>(padding));
// break;

// case ('s'): // short source filename - without directory name
// formatters_.push_back(std::make_unique<details::short_filename_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::short_filename_formatter<Padder>>(padding));
// break;

// case ('g'): // full source filename
// formatters_.push_back(std::make_unique<details::source_filename_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::source_filename_formatter<Padder>>(padding));
// break;

// case ('#'): // source line number
// formatters_.push_back(std::make_unique<details::source_linenum_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::source_linenum_formatter<Padder>>(padding));
// break;

// case ('!'): // source funcname
// formatters_.push_back(std::make_unique<details::source_funcname_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::source_funcname_formatter<Padder>>(padding));
// break;

// case ('%'): // % char
// formatters_.push_back(std::make_unique<details::ch_formatter>('%'));
// formatters_.push_back(details::make_unique<details::ch_formatter>('%'));
// break;

// case ('u'): // elapsed time since last log message in nanos
// formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(padding));
// formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(padding));
// break;

// case ('i'): // elapsed time since last log message in micros
// formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>(padding));
// formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>(padding));
// break;

// case ('o'): // elapsed time since last log message in millis
// formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>(padding));
// formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>(padding));
// break;

// case ('O'): // elapsed time since last log message in seconds
// formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
// formatters_.push_back(details::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
// break;

// default: // Unknown flag appears as is
// auto unknown_flag = std::make_unique<details::aggregate_formatter>();
// auto unknown_flag = details::make_unique<details::aggregate_formatter>();

// if (!padding.truncate_)
// {
Expand All @@ -1226,7 +1226,7 @@ inline void pattern_formatter::handle_flag_(char /*flag*/, details::padding_info
// else
// {
// padding.truncate_ = false;
// formatters_.push_back(std::make_unique<details::source_funcname_formatter<Padder>>(padding));
// formatters_.push_back(details::make_unique<details::source_funcname_formatter<Padder>>(padding));
// unknown_flag->add_ch(flag);
// formatters_.push_back((std::move(unknown_flag)));
// }
Expand Down Expand Up @@ -1328,7 +1328,7 @@ inline void pattern_formatter::compile_pattern_(const std::string &pattern)
{
if (!user_chars)
{
user_chars = std::make_unique<details::aggregate_formatter>();
user_chars = details::make_unique<details::aggregate_formatter>();
}
user_chars->add_ch(*it);
}
Expand Down
4 changes: 2 additions & 2 deletions include/pressio/utils/logger/spdlog/pattern_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class pattern_formatter final : public formatter
{
cloned_custom_formatters[it.first] = it.second->clone();
}
return std::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters));
return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters));
}

void format(const details::log_msg &msg, memory_buf_t &dest) override
Expand All @@ -144,7 +144,7 @@ class pattern_formatter final : public formatter
template<typename T, typename... Args>
pattern_formatter &add_flag(char flag, Args&&...args)
{
custom_handlers_[flag] = std::make_unique<T>(std::forward<Args>(args)...);
custom_handlers_[flag] = details::make_unique<T>(std::forward<Args>(args)...);
return *this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ template<typename ConsoleMutex>
SPDLOG_INLINE ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, color_mode mode)
: target_file_(target_file)
, mutex_(ConsoleMutex::mutex())
, formatter_(std::make_unique<spdlog::pattern_formatter>())
, formatter_(details::make_unique<spdlog::pattern_formatter>())

{
set_color_mode(mode);
Expand Down
4 changes: 2 additions & 2 deletions include/pressio/utils/logger/spdlog/sinks/base_sink-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

template<typename Mutex>
SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink()
: formatter_{std::make_unique<spdlog::pattern_formatter>()}
: formatter_{details::make_unique<spdlog::pattern_formatter>()}
{}

template<typename Mutex>
Expand Down Expand Up @@ -54,7 +54,7 @@ void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_pt
template<typename Mutex>
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
{
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
}

template<typename Mutex>
Expand Down
2 changes: 1 addition & 1 deletion include/pressio/utils/logger/spdlog/sinks/dist_sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class dist_sink : public base_sink<Mutex>

void set_pattern_(const std::string &pattern) override
{
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
}

void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ template<typename ConsoleMutex>
SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
: mutex_(ConsoleMutex::mutex())
, file_(file)
, formatter_(std::make_unique<spdlog::pattern_formatter>())
, formatter_(details::make_unique<spdlog::pattern_formatter>())
{
// #ifdef _WIN32
// // get windows handle from the FILE* object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template<typename ConsoleMutex>
SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(HANDLE out_handle, color_mode mode)
: out_handle_(out_handle)
, mutex_(ConsoleMutex::mutex())
, formatter_(std::make_unique<spdlog::pattern_formatter>())
, formatter_(details::make_unique<spdlog::pattern_formatter>())
{
// check if out_handle is points to the actual console.
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
Expand Down
2 changes: 1 addition & 1 deletion include/pressio/utils/logger/spdlog/unused/logger-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace spdlog {

// SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type)
// {
// auto new_formatter = std::make_unique<pattern_formatter>(std::move(pattern), time_type);
// auto new_formatter = details::make_unique<pattern_formatter>(std::move(pattern), time_type);
// set_formatter(std::move(new_formatter));
// }

Expand Down

0 comments on commit 28ca64f

Please sign in to comment.