From 25680a8ed2d1c321bcd2d6d5c90588c9fd07d73d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 17 Apr 2019 19:27:26 -0700 Subject: [PATCH] ircd: Move smalldate() to date.h from logger unit. --- include/ircd/date.h | 26 ++++++++++++++++++++++++++ include/ircd/logger.h | 5 ----- ircd/logger.cc | 21 --------------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/ircd/date.h b/include/ircd/date.h index 4b9feb809..7adeaac8d 100644 --- a/include/ircd/date.h +++ b/include/ircd/date.h @@ -48,6 +48,10 @@ namespace ircd string_view timef(const mutable_buffer &out, const char *const &fmt = rfc7231_fmt); template std::string timestr(args&&...); + // Other tools + string_view smalldate(const mutable_buffer &buf, const time_t <ime); + + // Interface conveniences. std::ostream &operator<<(std::ostream &, const microtime_t &); std::ostream &operator<<(std::ostream &, const system_point &); template std::ostream &operator<<(std::ostream &, const duration &); @@ -78,6 +82,28 @@ ircd::operator<<(std::ostream &s, const microtime_t &t) return s; } +inline ircd::string_view +ircd::smalldate(const mutable_buffer &buf, + const time_t <ime) +{ + struct tm lt; + localtime_r(<ime, <); + const auto len + { + ::snprintf(data(buf), size(buf), "%d/%d/%d %02d.%02d", + lt.tm_year + 1900, + lt.tm_mon + 1, + lt.tm_mday, + lt.tm_hour, + lt.tm_min) + }; + + return + { + data(buf), size_t(len) + }; +} + /// timestr() is a passthru to timef() where you don't give the first argument /// (the mutable_buffer). Instead of supplying a buffer an allocated /// std::string is returned with the result. By default this string's buffer diff --git a/include/ircd/logger.h b/include/ircd/logger.h index cd3fb9198..89dffb2ca 100644 --- a/include/ircd/logger.h +++ b/include/ircd/logger.h @@ -16,11 +16,6 @@ #undef ERROR #endif -namespace ircd -{ - const char *smalldate(const time_t &); -} - /// Logging system namespace ircd::log { diff --git a/ircd/logger.cc b/ircd/logger.cc index b1eff7f5f..1d79ff44e 100644 --- a/ircd/logger.cc +++ b/ircd/logger.cc @@ -696,27 +696,6 @@ ircd::log::default_ansi "\033[1;30;47m"_sv, // DEBUG }}; -const char * -ircd::smalldate(const time_t <ime) -{ - static const size_t MAX_DATE_STRING - { - 32 // maximum string length for a date string (ircd_defs.h) - }; - - struct tm lt; - localtime_r(<ime, <); - thread_local char buf[MAX_DATE_STRING]; - snprintf(buf, sizeof(buf), "%d/%d/%d %02d.%02d", - lt.tm_year + 1900, - lt.tm_mon + 1, - lt.tm_mday, - lt.tm_hour, - lt.tm_min); - - return buf; -} - bool ircd::log::is_conf_mask_console(const string_view &name) {