mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 04:50:31 -04:00
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:
parent
3053140e5c
commit
b59a48c2b6
@ -120,7 +120,7 @@ if(WITH_MAN_PAGES)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT STATIC_BUILD_DO_NOT_USE)
|
if(NOT STATIC_BUILD_DO_NOT_USE)
|
||||||
find_package(fmt 8 CONFIG)
|
find_package(fmt 9.1 CONFIG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(STATIC_BUILD_DO_NOT_USE OR NOT fmt_FOUND)
|
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()
|
endif()
|
||||||
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install;${CMAKE_PREFIX_PATH}")
|
set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install;${CMAKE_PREFIX_PATH}")
|
||||||
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install/include")
|
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()
|
endif()
|
||||||
|
|
||||||
list(APPEND DWARFS_BOOST_MODULES date_time filesystem program_options system)
|
list(APPEND DWARFS_BOOST_MODULES date_time filesystem program_options system)
|
||||||
|
@ -8,7 +8,7 @@ ExternalProject_Add(
|
|||||||
fmtlib
|
fmtlib
|
||||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/fmtlib
|
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/fmtlib
|
||||||
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
|
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}
|
CMAKE_ARGS -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
|
||||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install
|
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/fmtlib-install
|
||||||
-DCMAKE_BUILD_TYPE=Release
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
@ -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_logger_context(char const* path, int line);
|
||||||
|
std::string get_current_time_string();
|
||||||
|
|
||||||
} // namespace dwarfs
|
} // namespace dwarfs
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
||||||
|
|
||||||
#include <folly/Conv.h>
|
#include <folly/Conv.h>
|
||||||
|
|
||||||
#include <fmt/format.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))
|
, color_(stream_is_fancy_terminal(os))
|
||||||
, with_context_(with_context)
|
, with_context_(with_context)
|
||||||
, debug_progress_(is_debug_progress()) {
|
, 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) {
|
if (threshold > level_type::INFO) {
|
||||||
set_policy<debug_logger_policy>();
|
set_policy<debug_logger_policy>();
|
||||||
} else {
|
} else {
|
||||||
@ -96,7 +92,7 @@ void console_writer::rewind() {
|
|||||||
void console_writer::write(level_type level, const std::string& output,
|
void console_writer::write(level_type level, const std::string& output,
|
||||||
char const* file, int line) {
|
char const* file, int line) {
|
||||||
if (level <= threshold_) {
|
if (level <= threshold_) {
|
||||||
auto t = boost::posix_time::microsec_clock::local_time();
|
auto t = get_current_time_string();
|
||||||
const char* prefix = "";
|
const char* prefix = "";
|
||||||
const char* suffix = "";
|
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_,
|
fmt::format(" ==> {0:.0f}% done, {1} blocks/{2} written", 100 * frac_,
|
||||||
p.blocks_written, size_with_unit(p.compressed_size));
|
p.blocks_written, size_with_unit(p.compressed_size));
|
||||||
if (tmp != statebuf_) {
|
if (tmp != statebuf_) {
|
||||||
auto t = boost::posix_time::microsec_clock::local_time();
|
auto t = get_current_time_string();
|
||||||
statebuf_ = tmp;
|
statebuf_ = tmp;
|
||||||
std::lock_guard lock(mx_);
|
std::lock_guard lock(mx_);
|
||||||
os_ << "- " << t << statebuf_ << "\n";
|
os_ << "- " << t << statebuf_ << "\n";
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
||||||
|
|
||||||
#include <folly/Conv.h>
|
#include <folly/Conv.h>
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
@ -36,6 +34,7 @@
|
|||||||
#define DWARFS_SYMBOLIZE 0
|
#define DWARFS_SYMBOLIZE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <fmt/chrono.h>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
#include "dwarfs/logger.h"
|
#include "dwarfs/logger.h"
|
||||||
@ -67,15 +66,13 @@ stream_logger::stream_logger(std::ostream& os, level_type threshold,
|
|||||||
: os_(os)
|
: os_(os)
|
||||||
, color_(stream_is_fancy_terminal(os))
|
, color_(stream_is_fancy_terminal(os))
|
||||||
, with_context_(with_context) {
|
, with_context_(with_context) {
|
||||||
os_.imbue(std::locale(os_.getloc(),
|
|
||||||
new boost::posix_time::time_facet("%H:%M:%S.%f")));
|
|
||||||
set_threshold(threshold);
|
set_threshold(threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stream_logger::write(level_type level, const std::string& output,
|
void stream_logger::write(level_type level, const std::string& output,
|
||||||
char const* file, int line) {
|
char const* file, int line) {
|
||||||
if (level <= threshold_) {
|
if (level <= threshold_) {
|
||||||
auto t = boost::posix_time::microsec_clock::local_time();
|
auto t = get_current_time_string();
|
||||||
const char* prefix = "";
|
const char* prefix = "";
|
||||||
const char* suffix = "";
|
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);
|
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
|
} // namespace dwarfs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user