Skip to content

Commit

Permalink
Improve logger, add function: inline void toggle_logging(bool logging) ;
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Jan 22, 2024
1 parent 7de8c1b commit 0d4260f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions proxy/include/proxy/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,11 @@ inline void toggle_logging()
global_logging___ = !global_logging___;
}

inline void toggle_logging(bool logging)
{
global_logging___ = logging;
}

inline void toggle_write_logging(bool disable)
{
auto_logger_file__& file =
Expand Down Expand Up @@ -1364,6 +1369,8 @@ class logger___
inline logger___& operator<<(const std::string& v)
{
#ifdef LOGGING_ENABLE_AUTO_UTF8
if (!global_logging___)
return *this;
if (!logger_aux__::utf8_check_is_valid(v))
{
auto wres = logger_aux__::string_wide(v);
Expand All @@ -1379,10 +1386,14 @@ class logger___
}
inline logger___& operator<<(const std::wstring& v)
{
if (!global_logging___)
return *this;
return strcat_impl(*logger_aux__::utf16_utf8(v));
}
inline logger___& operator<<(const std::u16string& v)
{
if (!global_logging___)
return *this;
return strcat_impl(*logger_aux__::utf16_utf8(
{(const wchar_t*)v.data(), v.size()}));
}
Expand All @@ -1395,6 +1406,8 @@ class logger___
inline logger___& operator<<(const std::string_view& v)
{
#ifdef LOGGING_ENABLE_AUTO_UTF8
if (!global_logging___)
return *this;
if (!logger_aux__::utf8_check_is_valid(v))
{
auto wres = logger_aux__::string_wide(v);
Expand All @@ -1412,6 +1425,8 @@ class logger___
{
std::string_view sv{v.data(), v.length()};
#ifdef LOGGING_ENABLE_AUTO_UTF8
if (!global_logging___)
return *this;
if (!logger_aux__::utf8_check_is_valid(sv))
{
auto wres = logger_aux__::string_wide(sv);
Expand All @@ -1429,6 +1444,8 @@ class logger___
{
std::string_view sv(v);
#ifdef LOGGING_ENABLE_AUTO_UTF8
if (!global_logging___)
return *this;
if (!logger_aux__::utf8_check_is_valid(sv))
{
auto wres = logger_aux__::string_wide(sv);
Expand All @@ -1444,6 +1461,8 @@ class logger___
}
inline logger___& operator<<(const wchar_t* v)
{
if (!global_logging___)
return *this;
return strcat_impl(*logger_aux__::utf16_utf8(v));
}
inline logger___& operator<<(const void *v)
Expand Down Expand Up @@ -1704,6 +1723,8 @@ class logger___
#endif
inline logger___& operator<<(const std::thread::id& id) noexcept
{
if (!global_logging___)
return *this;
std::ostringstream oss;
oss << id;
out_ += oss.str();
Expand Down

0 comments on commit 0d4260f

Please sign in to comment.