0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd: Move smalldate() to date.h from logger unit.

This commit is contained in:
Jason Volk 2019-04-17 19:27:26 -07:00
parent 4d3727a0a1
commit 25680a8ed2
3 changed files with 26 additions and 26 deletions

View file

@ -48,6 +48,10 @@ namespace ircd
string_view timef(const mutable_buffer &out, const char *const &fmt = rfc7231_fmt);
template<size_t max = 128, class... args> std::string timestr(args&&...);
// Other tools
string_view smalldate(const mutable_buffer &buf, const time_t &ltime);
// Interface conveniences.
std::ostream &operator<<(std::ostream &, const microtime_t &);
std::ostream &operator<<(std::ostream &, const system_point &);
template<class rep, class period> std::ostream &operator<<(std::ostream &, const duration<rep, period> &);
@ -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 &ltime)
{
struct tm lt;
localtime_r(&ltime, &lt);
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

View file

@ -16,11 +16,6 @@
#undef ERROR
#endif
namespace ircd
{
const char *smalldate(const time_t &);
}
/// Logging system
namespace ircd::log
{

View file

@ -696,27 +696,6 @@ ircd::log::default_ansi
"\033[1;30;47m"_sv, // DEBUG
}};
const char *
ircd::smalldate(const time_t &ltime)
{
static const size_t MAX_DATE_STRING
{
32 // maximum string length for a date string (ircd_defs.h)
};
struct tm lt;
localtime_r(&ltime, &lt);
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)
{