71 static const char*
ampm(
const tm& t)
73 return t.tm_hour >= 12 ?
"PM" :
"AM";
78 return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour;
85 static const days_array arr{ {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" } };
106 static const days_array arr{ {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday" } };
121 static const months_array arr{ {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"June",
"July",
"Aug",
"Sept",
"Oct",
"Nov",
"Dec" } };
135 static const months_array arr{ {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" } };
167 msg.
formatted <<
days()[tm_time.tm_wday] <<
' ' <<
months()[tm_time.tm_mon] <<
' ' << tm_time.tm_mday <<
' ';
168 pad_n_join(msg.
formatted, tm_time.tm_hour, tm_time.tm_min, tm_time.tm_sec,
':') <<
' ' << tm_time.tm_year + 1900;
189 pad_n_join(msg.
formatted, tm_time.tm_mon + 1, tm_time.tm_mday, tm_time.tm_year % 100,
'/');
262 auto duration = msg.
time.time_since_epoch();
263 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).
count() % 1000;
273 auto duration = msg.
time.time_since_epoch();
274 auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration).
count() % 1000000;
284 auto duration = msg.
time.time_since_epoch();
285 auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).
count() % 1000000000;
331 const std::chrono::seconds cache_refresh = std::chrono::seconds(5);
335 z_formatter(
const z_formatter&) =
delete;
336 z_formatter& operator=(
const z_formatter&) =
delete;
341 int total_minutes = get_cached_offset(msg, tm_time);
351 total_minutes = -total_minutes;
359 int h = total_minutes / 60;
360 int m = total_minutes % 60;
371 using namespace std::chrono;
372 std::lock_guard<std::mutex> l(_mutex);
373 if (msg.
time - _last_update >= cache_refresh)
376 _last_update = msg.
time;
378 return _offset_minutes;
449 #ifndef SPDLOG_NO_DATETIME 450 auto duration = msg.
time.time_since_epoch();
451 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).
count() % 1000;
468 msg.
formatted <<
'[' <<
static_cast<unsigned int>(tm_time.tm_year + 1900) <<
'-' 469 <<
fmt::pad(static_cast<unsigned int>(tm_time.tm_mon + 1), 2,
'0') <<
'-' 470 <<
fmt::pad(static_cast<unsigned int>(tm_time.tm_mday), 2,
'0') <<
' ' 471 <<
fmt::pad(static_cast<unsigned int>(tm_time.tm_hour), 2,
'0') <<
':' 472 <<
fmt::pad(static_cast<unsigned int>(tm_time.tm_min), 2,
'0') <<
':' 473 <<
fmt::pad(static_cast<unsigned int>(tm_time.tm_sec), 2,
'0') <<
'.' 474 <<
fmt::pad(static_cast<unsigned int>(millis), 3,
'0') <<
"] ";
481 #ifndef SPDLOG_NO_NAME 498 : _pattern_time(pattern_time)
500 compile_pattern(pattern);
503 inline void spdlog::pattern_formatter::compile_pattern(
const std::string& pattern)
505 auto end = pattern.end();
506 std::unique_ptr<details::aggregate_formatter> user_chars;
507 for (
auto it = pattern.begin(); it !=
end; ++it)
512 _formatters.push_back(
std::move(user_chars));
522 user_chars = std::unique_ptr<details::aggregate_formatter>(
new details::aggregate_formatter());
523 user_chars->add_ch(*it);
528 _formatters.push_back(
std::move(user_chars));
532 inline void spdlog::pattern_formatter::handle_flag(
char flag)
538 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::name_formatter()));
550 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::t_formatter()));
554 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::v_formatter()));
562 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::A_formatter()));
571 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::B_formatter()));
574 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::c_formatter()));
578 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::C_formatter()));
582 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::Y_formatter()));
588 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::D_formatter()));
592 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::m_formatter()));
596 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::d_formatter()));
600 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::H_formatter()));
604 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::I_formatter()));
608 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::M_formatter()));
612 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::S_formatter()));
616 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::e_formatter()));
620 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::f_formatter()));
623 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::F_formatter()));
627 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::p_formatter()));
631 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::r_formatter()));
635 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::R_formatter()));
640 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::T_formatter()));
644 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::z_formatter()));
648 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::full_formatter()));
652 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::pid_formatter()));
655 #if defined(SPDLOG_ENABLE_MESSAGE_COUNTER) 657 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::i_formatter()));
662 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::ch_formatter(
'%')));
663 _formatters.push_back(std::unique_ptr<details::flag_formatter>(
new details::ch_formatter(flag)));
679 #ifndef SPDLOG_NO_DATETIME 680 auto tm_time = get_time(msg);
684 for (
auto &
f : _formatters)
686 f->format(msg, tm_time);
static const months_array & full_months()
bool is_negative(T value)
static int to12h(const tm &t)
const std::string * logger_name
IntFormatSpec< int, AlignTypeSpec< TYPE_CODE >, Char > pad(int value, unsigned width, Char fill= ' ')
static fmt::MemoryWriter & pad_n_join(fmt::MemoryWriter &w, int v1, int v2, char sep)
static SPDLOG_CONSTEXPR int eol_size
void write(BasicCStringRef< Char > format, ArgList args)
std::string format(CStringRef format_str, ArgList args)
static const char * ampm(const tm &t)
const Char * data() const FMT_NOEXCEPT
log_clock::time_point _last_update
int utc_minutes_offset(const std::tm &tm=details::os::localtime())
void format(details::log_msg &msg, const std::tm &tm_time) override
BasicStringRef< char > StringRef
fmt::BufferedFile & move(fmt::BufferedFile &f)
std::array< std::string, 12 > months_array
std::tm localtime(const std::time_t &time_tt)
const char * to_short_str(spdlog::level::level_enum l)
fmt::MemoryWriter formatted
std::tm gmtime(const std::time_t &time_tt)
static const months_array & months()
static const days_array & full_days()
static SPDLOG_CONSTEXPR const char * eol
static const days_array & days()
void format(details::log_msg &msg, const std::tm &) override
std::array< std::string, 7 > days_array
const char * to_str(spdlog::level::level_enum l)
int get_cached_offset(const log_msg &msg, const std::tm &tm_time)
log_clock::time_point time