Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
64521005
Commit
64521005
authored
Aug 01, 2018
by
slapenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
We can control should daily_file_sink truncate an underlying file or not
parent
16b18f79
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
include/spdlog/sinks/daily_file_sink.h
include/spdlog/sinks/daily_file_sink.h
+14
-7
No files found.
include/spdlog/sinks/daily_file_sink.h
View file @
64521005
...
@@ -44,17 +44,18 @@ class daily_file_sink SPDLOG_FINAL : public base_sink<Mutex>
...
@@ -44,17 +44,18 @@ class daily_file_sink SPDLOG_FINAL : public base_sink<Mutex>
{
{
public:
public:
// create daily file sink which rotates on given time
// create daily file sink which rotates on given time
daily_file_sink
(
filename_t
base_filename
,
int
rotation_hour
,
int
rotation_minute
)
daily_file_sink
(
filename_t
base_filename
,
int
rotation_hour
,
int
rotation_minute
,
bool
truncate
=
false
)
:
base_filename_
(
std
::
move
(
base_filename
))
:
base_filename_
(
std
::
move
(
base_filename
))
,
rotation_h_
(
rotation_hour
)
,
rotation_h_
(
rotation_hour
)
,
rotation_m_
(
rotation_minute
)
,
rotation_m_
(
rotation_minute
)
,
truncate_
(
truncate
)
{
{
if
(
rotation_hour
<
0
||
rotation_hour
>
23
||
rotation_minute
<
0
||
rotation_minute
>
59
)
if
(
rotation_hour
<
0
||
rotation_hour
>
23
||
rotation_minute
<
0
||
rotation_minute
>
59
)
{
{
throw
spdlog_ex
(
"daily_file_sink: Invalid rotation time in ctor"
);
throw
spdlog_ex
(
"daily_file_sink: Invalid rotation time in ctor"
);
}
}
auto
now
=
log_clock
::
now
();
auto
now
=
log_clock
::
now
();
file_helper_
.
open
(
FileNameCalc
::
calc_filename
(
base_filename_
,
now_tm
(
now
))
);
open_file
(
now
);
rotation_tp_
=
next_rotation_tp_
();
rotation_tp_
=
next_rotation_tp_
();
}
}
...
@@ -64,7 +65,7 @@ protected:
...
@@ -64,7 +65,7 @@ protected:
if
(
msg
.
time
>=
rotation_tp_
)
if
(
msg
.
time
>=
rotation_tp_
)
{
{
file_helper_
.
open
(
FileNameCalc
::
calc_filename
(
base_filename_
,
now_tm
(
msg
.
time
))
);
open_file
(
msg
.
time
);
rotation_tp_
=
next_rotation_tp_
();
rotation_tp_
=
next_rotation_tp_
();
}
}
fmt
::
memory_buffer
formatted
;
fmt
::
memory_buffer
formatted
;
...
@@ -78,6 +79,11 @@ protected:
...
@@ -78,6 +79,11 @@ protected:
}
}
private:
private:
void
open_file
(
log_clock
::
time_point
tp
)
{
file_helper_
.
open
(
FileNameCalc
::
calc_filename
(
base_filename_
,
now_tm
(
tp
)),
truncate_
);
}
tm
now_tm
(
log_clock
::
time_point
tp
)
tm
now_tm
(
log_clock
::
time_point
tp
)
{
{
time_t
tnow
=
log_clock
::
to_time_t
(
tp
);
time_t
tnow
=
log_clock
::
to_time_t
(
tp
);
...
@@ -104,6 +110,7 @@ private:
...
@@ -104,6 +110,7 @@ private:
int
rotation_m_
;
int
rotation_m_
;
log_clock
::
time_point
rotation_tp_
;
log_clock
::
time_point
rotation_tp_
;
details
::
file_helper
file_helper_
;
details
::
file_helper
file_helper_
;
bool
truncate_
;
};
};
using
daily_file_sink_mt
=
daily_file_sink
<
std
::
mutex
>
;
using
daily_file_sink_mt
=
daily_file_sink
<
std
::
mutex
>
;
...
@@ -115,14 +122,14 @@ using daily_file_sink_st = daily_file_sink<details::null_mutex>;
...
@@ -115,14 +122,14 @@ using daily_file_sink_st = daily_file_sink<details::null_mutex>;
// factory functions
// factory functions
//
//
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
)
inline
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
truncate
=
false
)
{
{
return
Factory
::
template
create
<
sinks
::
daily_file_sink_mt
>(
logger_name
,
filename
,
hour
,
minute
);
return
Factory
::
template
create
<
sinks
::
daily_file_sink_mt
>(
logger_name
,
filename
,
hour
,
minute
,
truncate
);
}
}
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
)
inline
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
truncate
=
false
)
{
{
return
Factory
::
template
create
<
sinks
::
daily_file_sink_st
>(
logger_name
,
filename
,
hour
,
minute
);
return
Factory
::
template
create
<
sinks
::
daily_file_sink_st
>(
logger_name
,
filename
,
hour
,
minute
,
truncate
);
}
}
}
// namespace spdlog
}
// namespace spdlog
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment