class Date
{
public:
Date(int year, int month, int day) : _year(year), _month(month), _day(day) {}
int year() const { return _year; }
int month() const { return _month; }
int day() const { return _day; }
private:
int _year, _month, _day;
};
template <>
struct fmt::formatter<Date>
{
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.begin(); }
auto format(const Date& date, format_context& ctx) const -> decltype(ctx.out())
{
fmt::format_to(ctx.out(), "{}-{}-{}", date.year(), date.month(), date.day());
return ctx.out();
}
};
class DateTime
{
public:
DateTime(Date date, int hours, int minutes, int seconds) : _date(date), _hours(hours), _minutes(minutes), _seconds(seconds) {}
Date date() const { return _date; }
int hours() const { return _hours; }
int minutes() const { return _minutes; }
int seconds() const { return _seconds; }
{
}
private:
Date _date;
int _hours, _minutes, _seconds;
};
template <>
struct fmt::formatter<DateTime>
{
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.begin(); }
auto format(const DateTime& datetime, format_context& ctx) const -> decltype(ctx.out())
{
fmt::format_to(ctx.out(), "{} {}:{}:{}", datetime.date(), datetime.hours(), datetime.minutes(), datetime.seconds());
return ctx.out();
}
};
int main(int argc, char** argv)
{
logger.
Info(
"argc: {}, argv: {}", argc, (
void*)argv);
logger.
Info(
"no arguments");
logger.
Info(
"{0}, {1}, {2}", -1, 0, 1);
logger.
Info(
"{0}, {1}, {2}",
'a',
'b',
'c');
logger.
Info(
"{}, {}, {}",
'a',
'b',
'c');
logger.
Info(
"{2}, {1}, {0}",
'a',
'b',
'c');
logger.
Info(
"{0}{1}{0}",
"abra",
"cad");
logger.
Info(
"{:<30}",
"left aligned");
logger.
Info(
"{:>30}",
"right aligned");
logger.
Info(
"{:^30}",
"centered");
logger.
Info(
"{:*^30}",
"centered");
logger.
Info(
"{:+f}; {:+f}", 3.14, -3.14);
logger.
Info(
"{: f}; {: f}", 3.14, -3.14);
logger.
Info(
"{:-f}; {:-f}", 3.14, -3.14);
logger.
Info(
"int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
logger.
Info(
"int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42);
logger.
Info(
"The date is {}", Date(2012, 12, 9));
logger.
Info(
"The datetime is {}", DateTime(Date(2012, 12, 9), 13, 15, 57));
logger.
Info(
"Elapsed time: {s:.2f} seconds",
"s"_a = 1.23);
return 0;
}
void Info(std::string_view message) const
Log information message.
Record & StoreListEnd(size_t begin)
Record & StoreCustomFormat(std::string_view pattern, Args &&... args)
size_t StoreListBegin()
Store list format message.
Record & StoreList(Args &&... args)
Logger interface definition.
TOutputStream & operator<<(TOutputStream &stream, TimeRollingPolicy policy)
Stream output: Time rolling policy.