mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-14 17:52:05 +08:00
Some cleanup
This commit is contained in:
parent
d4ab3a0c69
commit
afea332bbd
@ -48,14 +48,15 @@ namespace sinks {
|
|||||||
class sink;
|
class sink;
|
||||||
}
|
}
|
||||||
|
|
||||||
using filename_t = std::filesystem::path;
|
#ifdef _WIN32
|
||||||
#ifdef _WIN32 // Add L prefix to string literals on Windows when dealing with filenames
|
// In windows, add L prefix for filename literals (e.g. L"filename.txt")
|
||||||
#define SPDLOG_FILENAME_T_INNER(s) L##s
|
#define SPDLOG_FILENAME_T_INNER(s) L##s
|
||||||
#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
|
#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_FILENAME_T(s) s
|
#define SPDLOG_FILENAME_T(s) s
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using filename_t = std::filesystem::path;
|
||||||
using log_clock = std::chrono::system_clock;
|
using log_clock = std::chrono::system_clock;
|
||||||
using sink_ptr = std::shared_ptr<sinks::sink>;
|
using sink_ptr = std::shared_ptr<sinks::sink>;
|
||||||
using sinks_init_list = std::initializer_list<sink_ptr>;
|
using sinks_init_list = std::initializer_list<sink_ptr>;
|
||||||
|
@ -30,10 +30,8 @@ struct daily_filename_calculator {
|
|||||||
filename_t basename, ext;
|
filename_t basename, ext;
|
||||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||||
std::basic_ostringstream<filename_t::value_type> oss;
|
std::basic_ostringstream<filename_t::value_type> oss;
|
||||||
auto sep = SPDLOG_FILENAME_T('-');
|
oss << basename.native() << '_' << std::setfill(SPDLOG_FILENAME_T('0')) << std::setw(4) << now_tm.tm_year + 1900 << '-'
|
||||||
oss << basename.native() << SPDLOG_FILENAME_T('_') << std::setfill(SPDLOG_FILENAME_T('0')) << std::setw(4)
|
<< std::setw(2) << now_tm.tm_mon + 1 << '-' << std::setw(2) << now_tm.tm_mday << ext.native();
|
||||||
<< now_tm.tm_year + 1900 << sep
|
|
||||||
<< std::setw(2) << now_tm.tm_mon + 1 << sep << std::setw(2) << now_tm.tm_mday << ext.native();
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -30,9 +30,8 @@ struct hourly_filename_calculator {
|
|||||||
filename_t basename, ext;
|
filename_t basename, ext;
|
||||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||||
std::basic_ostringstream<filename_t::value_type> oss;
|
std::basic_ostringstream<filename_t::value_type> oss;
|
||||||
auto sep = SPDLOG_FILENAME_T('-');
|
oss << basename.native() << '-' << std::setfill(SPDLOG_FILENAME_T('0')) << std::setw(4) << now_tm.tm_year + 1900 << '-'
|
||||||
oss << basename.native() << sep << std::setfill(SPDLOG_FILENAME_T('0')) << std::setw(4) << now_tm.tm_year + 1900 << sep
|
<< std::setw(2) << now_tm.tm_mon + 1 << '-' << std::setw(2) << now_tm.tm_mday << '-' << std::setw(2) << now_tm.tm_hour
|
||||||
<< std::setw(2) << now_tm.tm_mon + 1 << sep << std::setw(2) << now_tm.tm_mday << sep << std::setw(2) << now_tm.tm_hour
|
|
||||||
<< ext.native();
|
<< ext.native();
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename,
|
|||||||
filename_t ext;
|
filename_t ext;
|
||||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||||
std::basic_ostringstream<filename_t::value_type> oss;
|
std::basic_ostringstream<filename_t::value_type> oss;
|
||||||
oss << basename.native() << "." << index << ext.native();
|
oss << basename.native() << '.' << index << ext.native();
|
||||||
return oss.str();
|
return oss.str();
|
||||||
//return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}.{}{}")), basename, index, ext);
|
//return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}.{}{}")), basename, index, ext);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user