Skip to content

Commit

Permalink
Adapt to fmt's deprecation of format_to memory buffer overload
Browse files Browse the repository at this point in the history
  • Loading branch information
rbx committed Nov 26, 2021
1 parent 27040ea commit 9a6644c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions logger/Logger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <cstdio> // printf
#include <iostream>
#include <iterator> // std::back_inserter

using namespace std;

Expand Down Expand Up @@ -160,71 +161,71 @@ Logger::Logger(Severity severity, Verbosity verbosity, const string& file, const
for (const auto info : spec.fInfos) {
switch (info) {
case VSpec::Info::process_name:
fmt::format_to(fBWPrefix, "[{}]", fInfos.process_name);
fmt::format_to(std::back_inserter(fBWPrefix), "[{}]", fInfos.process_name);
break;
case VSpec::Info::timestamp_us:
FillTimeInfos();
fmt::format_to(fBWPrefix, "[{:%H:%M:%S}.{:06}]", fmt::localtime(fInfos.timestamp), fInfos.us.count());
fmt::format_to(std::back_inserter(fBWPrefix), "[{:%H:%M:%S}.{:06}]", fmt::localtime(fInfos.timestamp), fInfos.us.count());
break;
case VSpec::Info::timestamp_s:
FillTimeInfos();
fmt::format_to(fBWPrefix, "[{:%H:%M:%S}]", fmt::localtime(fInfos.timestamp));
fmt::format_to(std::back_inserter(fBWPrefix), "[{:%H:%M:%S}]", fmt::localtime(fInfos.timestamp));
break;
case VSpec::Info::severity:
fmt::format_to(fBWPrefix, "[{}]", fInfos.severity_name);
fmt::format_to(std::back_inserter(fBWPrefix), "[{}]", fInfos.severity_name);
break;
case VSpec::Info::file_line_function:
fmt::format_to(fBWPrefix, "[{}:{}:{}]", fInfos.file, fInfos.line, fInfos.func);
fmt::format_to(std::back_inserter(fBWPrefix), "[{}:{}:{}]", fInfos.file, fInfos.line, fInfos.func);
break;
case VSpec::Info::file_line:
fmt::format_to(fBWPrefix, "[{}:{}]", fInfos.file, fInfos.line);
fmt::format_to(std::back_inserter(fBWPrefix), "[{}:{}]", fInfos.file, fInfos.line);
break;
case VSpec::Info::file:
fmt::format_to(fBWPrefix, "[{}]", fInfos.file);
fmt::format_to(std::back_inserter(fBWPrefix), "[{}]", fInfos.file);
break;
default:
break;
}
}

if (spec.fSize > 0) {
fmt::format_to(fBWPrefix, " ");
fmt::format_to(std::back_inserter(fBWPrefix), " ");
}
}

if (fColored && LoggingToConsole()) {
for (const auto info : spec.fInfos) {
switch (info) {
case VSpec::Info::process_name:
fmt::format_to(fColorPrefix, "[{}]", ColorOut(Color::fgBlue, fInfos.process_name));
fmt::format_to(std::back_inserter(fColorPrefix), "[{}]", ColorOut(Color::fgBlue, fInfos.process_name));
break;
case VSpec::Info::timestamp_us:
FillTimeInfos();
fmt::format_to(fColorPrefix, "[{}{:%H:%M:%S}.{:06}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), fInfos.us.count(), endColor());
fmt::format_to(std::back_inserter(fColorPrefix), "[{}{:%H:%M:%S}.{:06}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), fInfos.us.count(), endColor());
break;
case VSpec::Info::timestamp_s:
FillTimeInfos();
fmt::format_to(fColorPrefix, "[{}{:%H:%M:%S}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), endColor());
fmt::format_to(std::back_inserter(fColorPrefix), "[{}{:%H:%M:%S}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), endColor());
break;
case VSpec::Info::severity:
fmt::format_to(fColorPrefix, "[{}]", GetColoredSeverityString(fInfos.severity));
fmt::format_to(std::back_inserter(fColorPrefix), "[{}]", GetColoredSeverityString(fInfos.severity));
break;
case VSpec::Info::file_line_function:
fmt::format_to(fColorPrefix, "[{}:{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line), ColorOut(Color::fgBlue, fInfos.func));
fmt::format_to(std::back_inserter(fColorPrefix), "[{}:{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line), ColorOut(Color::fgBlue, fInfos.func));
break;
case VSpec::Info::file_line:
fmt::format_to(fColorPrefix, "[{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line));
fmt::format_to(std::back_inserter(fColorPrefix), "[{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line));
break;
case VSpec::Info::file:
fmt::format_to(fColorPrefix, "[{}]", ColorOut(Color::fgBlue, fInfos.file));
fmt::format_to(std::back_inserter(fColorPrefix), "[{}]", ColorOut(Color::fgBlue, fInfos.file));
break;
default:
break;
}
}

if (spec.fSize > 0) {
fmt::format_to(fColorPrefix, " ");
fmt::format_to(std::back_inserter(fColorPrefix), " ");
}
}

Expand Down

0 comments on commit 9a6644c

Please sign in to comment.