bux API Reference
1.12.6
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
include
bux
FileLog.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
SyncLog.h
"
// bux::I_SnapT<>
4
#include <chrono>
// std::chrono::*
5
#include <filesystem>
// std::filesystem::*
6
#include <fstream>
// std::ofstream
7
#include <stdexcept>
// std::runtime_error
8
#include <string>
// std::string
9
#include <vector>
// std::vector<>
10
11
namespace
bux
{
12
13
//
14
// Types
15
//
16
class
C_PathFmtLogSnap
:
public
I_SnapT
<std::ostream*>
19
{
20
public
:
21
22
// Nonvirtuals
23
explicit
C_PathFmtLogSnap
(
T_LocalZone
tz =
local_zone
());
24
#if LOCALZONE_IS_TIMEZONE
25
explicit
C_PathFmtLogSnap
(
bool
use_local_time):
C_PathFmtLogSnap
(use_local_time?
local_zone
():
T_LocalZone
()) {}
26
#endif
27
C_PathFmtLogSnap
&
configPath
(
const
std::string &pathFmt);
28
C_PathFmtLogSnap
&
configPath
(uintmax_t fsize_in_bytes,
const
auto
&fallbackPaths)
35
requires
requires
{
36
std::begin(fallbackPaths);
37
{ *std::begin(fallbackPaths) }-> std::convertible_to<std::string>;
38
std::end(fallbackPaths);
39
}
40
{
41
m_PathFmts.clear();
42
for
(
auto
&i: fallbackPaths)
43
{
44
const
std::string _path = i;
45
if
(_path.empty())
46
throw
std::runtime_error{
"Null path format"
};
47
48
m_PathFmts.emplace_back(std::filesystem::absolute(_path).
string
());
49
}
50
m_FileSizeLimit = fsize_in_bytes;
51
m_CurPathFmt = 0;
52
return
*
this
;
53
}
54
C_PathFmtLogSnap
&
enableAutoMkDir
(
bool
yes =
true
);
55
C_PathFmtLogSnap
&
setBinaryMode
(
bool
enabled);
56
57
// Implement I_SnapT<std::ostream*>
58
std::ostream *
snap
()
override
;
59
60
private
:
61
62
// Data
63
const
T_LocalZone
m_tz;
64
std::ofstream m_Out;
// prior to m_Lock
65
std::string m_CurrPath;
// Path of the currently openned file
66
std::vector<std::string> m_PathFmts;
67
uintmax_t m_FileSizeLimit{};
// in bytes
68
size_t
m_CurPathFmt{};
69
std::chrono::sys_seconds m_OldTime;
70
std::ios_base::openmode m_OpenMode{std::ios_base::out};
71
bool
m_AutoMkDir{
true
};
72
};
73
74
}
// namespace bux
SyncLog.h
bux::C_PathFmtLogSnap
Definition
FileLog.h:19
bux::C_PathFmtLogSnap::enableAutoMkDir
C_PathFmtLogSnap & enableAutoMkDir(bool yes=true)
Definition
FileLog.cpp:33
bux::C_PathFmtLogSnap::C_PathFmtLogSnap
C_PathFmtLogSnap(bool use_local_time)
Definition
FileLog.h:25
bux::C_PathFmtLogSnap::snap
std::ostream * snap() override
Snap the current T value.
Definition
FileLog.cpp:57
bux::C_PathFmtLogSnap::configPath
C_PathFmtLogSnap & configPath(uintmax_t fsize_in_bytes, const auto &fallbackPaths)
Definition
FileLog.h:28
bux::C_PathFmtLogSnap::C_PathFmtLogSnap
C_PathFmtLogSnap(T_LocalZone tz=local_zone())
Definition
FileLog.cpp:11
bux::C_PathFmtLogSnap::setBinaryMode
C_PathFmtLogSnap & setBinaryMode(bool enabled)
Definition
FileLog.cpp:44
bux::C_PathFmtLogSnap::configPath
C_PathFmtLogSnap & configPath(const std::string &pathFmt)
Definition
FileLog.cpp:16
bux
THE common namespace of bux library.
Definition
AtomiX.cpp:3
bux::T_LocalZone
const std::chrono::time_zone * T_LocalZone
Definition
XPlatform.h:18
bux::local_zone
T_LocalZone local_zone()
Definition
XPlatform.h:19
bux::I_SnapT
< Parasitic Type
Definition
SyncLog.h:169
Generated by
1.18.0