59 const auto t = time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now());
60 const auto get_new_path = [t,
this](
auto indFmt) {
61 std::string_view pathFmt = m_PathFmts.at(indFmt);
64#if LOCALZONE_IS_TIMEZONE
65 auto ltm = m_tz->to_local(t);
67 auto sys_t = std::chrono::system_clock::to_time_t(t);
68 std::chrono::local_time<std::chrono::seconds> ltm(t.time_since_epoch() + std::chrono::seconds(localtime(&sys_t)->tm_gmtoff));
70 return std::vformat(pathFmt, make_format_args(ltm));
72 return std::vformat(pathFmt, make_format_args(t));
76 nextPath = m_CurrPath;
80 nextPath = get_new_path(m_CurPathFmt);
86 if (m_CurrPath != nextPath)
89 if (m_CurrPath.empty())
93 while (m_CurPathFmt + 1 < m_PathFmts.size() &&
94 fs::is_regular_file(nextPath) &&
95 fs::file_size(nextPath) >= m_FileSizeLimit)
96 nextPath = get_new_path(++m_CurPathFmt);
102 auto s2 = get_new_path(m_CurPathFmt - 1);
107 nextPath = std::move(s2);
112 (void)create_directories(fs::path(nextPath).parent_path());
115 if (m_CurrPath.empty())
117 m_Out.open(nextPath, m_OpenMode|std::ios::ate|std::ios::in);
122 if (!m_Out.is_open())
126 m_Out.open(nextPath, m_OpenMode);
128 if (!m_Out.is_open())
131 m_CurrPath = nextPath;
135 m_CurPathFmt + 1 < m_PathFmts.size() &&
136 m_Out.tellp() >= std::streamoff(m_FileSizeLimit))
139 nextPath = get_new_path(++m_CurPathFmt);