Replace use of boost posix_time with {fmt}

Only issue is that in order to properly format fractional seconds,
we need a bleeding edge version of {fmt}.
This commit is contained in:
Marcus Holland-Moritz 2022-10-26 12:40:57 +02:00
parent 3053140e5c
commit b59a48c2b6
5 changed files with 14 additions and 14 deletions

View File

@ -120,7 +120,7 @@ if(WITH_MAN_PAGES)
endif()
if(NOT STATIC_BUILD_DO_NOT_USE)
find_package(fmt 8 CONFIG)
find_package(fmt 9.1 CONFIG)
endif()
if(STATIC_BUILD_DO_NOT_USE OR NOT fmt_FOUND)
@ -141,7 +141,7 @@ if(STATIC_BUILD_DO_NOT_USE OR NOT fmt_FOUND)
endif()
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install;${CMAKE_PREFIX_PATH}")
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install/include")
find_package(fmt 8 REQUIRED CONFIG PATHS "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install" NO_DEFAULT_PATH)
find_package(fmt 9.1 REQUIRED CONFIG PATHS "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install" NO_DEFAULT_PATH)
endif()
list(APPEND DWARFS_BOOST_MODULES date_time filesystem program_options system)

View File

@ -8,7 +8,7 @@ ExternalProject_Add(
fmtlib
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/fmtlib
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 8.1.1
GIT_TAG 80f8d34427d40ec5e7ce3b10ededc46bd4bd5759
CMAKE_ARGS -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install
-DCMAKE_BUILD_TYPE=Release

View File

@ -412,5 +412,6 @@ std::shared_ptr<Base> make_shared_logging_object(logger& lgr, Args&&... args) {
}
std::string get_logger_context(char const* path, int line);
std::string get_current_time_string();
} // namespace dwarfs

View File

@ -24,8 +24,6 @@
#include <locale>
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <folly/Conv.h>
#include <fmt/format.h>
@ -71,8 +69,6 @@ console_writer::console_writer(std::ostream& os, progress_mode pg_mode,
, color_(stream_is_fancy_terminal(os))
, with_context_(with_context)
, debug_progress_(is_debug_progress()) {
os_.imbue(std::locale(os_.getloc(),
new boost::posix_time::time_facet("%H:%M:%S.%f")));
if (threshold > level_type::INFO) {
set_policy<debug_logger_policy>();
} else {
@ -96,7 +92,7 @@ void console_writer::rewind() {
void console_writer::write(level_type level, const std::string& output,
char const* file, int line) {
if (level <= threshold_) {
auto t = boost::posix_time::microsec_clock::local_time();
auto t = get_current_time_string();
const char* prefix = "";
const char* suffix = "";
@ -248,7 +244,7 @@ void console_writer::update(const progress& p, bool last) {
fmt::format(" ==> {0:.0f}% done, {1} blocks/{2} written", 100 * frac_,
p.blocks_written, size_with_unit(p.compressed_size));
if (tmp != statebuf_) {
auto t = boost::posix_time::microsec_clock::local_time();
auto t = get_current_time_string();
statebuf_ = tmp;
std::lock_guard lock(mx_);
os_ << "- " << t << statebuf_ << "\n";

View File

@ -25,8 +25,6 @@
#include <locale>
#include <stdexcept>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <folly/Conv.h>
#ifndef NDEBUG
@ -36,6 +34,7 @@
#define DWARFS_SYMBOLIZE 0
#endif
#include <fmt/chrono.h>
#include <fmt/format.h>
#include "dwarfs/logger.h"
@ -67,15 +66,13 @@ stream_logger::stream_logger(std::ostream& os, level_type threshold,
: os_(os)
, color_(stream_is_fancy_terminal(os))
, with_context_(with_context) {
os_.imbue(std::locale(os_.getloc(),
new boost::posix_time::time_facet("%H:%M:%S.%f")));
set_threshold(threshold);
}
void stream_logger::write(level_type level, const std::string& output,
char const* file, int line) {
if (level <= threshold_) {
auto t = boost::posix_time::microsec_clock::local_time();
auto t = get_current_time_string();
const char* prefix = "";
const char* suffix = "";
@ -149,4 +146,10 @@ std::string get_logger_context(char const* path, int line) {
return fmt::format("[{0}:{1}] ", base ? base + 1 : path, line);
}
std::string get_current_time_string() {
using namespace std::chrono;
auto now = floor<microseconds>(system_clock::now());
return fmt::format("{:%H:%M:%S}", now);
}
} // namespace dwarfs