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
c401e830
Commit
c401e830
authored
Feb 15, 2015
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added option for setting rotation time in daily file ctor
parent
9e54057a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
25 deletions
+37
-25
include/spdlog/details/format.cc
include/spdlog/details/format.cc
+2
-4
include/spdlog/details/spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+4
-4
include/spdlog/sinks/file_sinks.h
include/spdlog/sinks/file_sinks.h
+28
-14
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+3
-3
No files found.
include/spdlog/details/format.cc
View file @
c401e830
...
...
@@ -642,11 +642,9 @@ FMT_FUNC void spdlog::details::fmt::BasicWriter<Char>::write_str(
template
<
typename
Char
>
inline
Arg
spdlog
::
details
::
fmt
::
BasicFormatter
<
Char
>::
parse_arg_index
(
const
Char
*&
s
)
{
const
char
*
error
=
0
;
Arg
arg
=
*
s
<
'0'
||
*
s
>
'9'
?
next_arg
(
error
)
:
get_arg
(
parse_nonnegative_int
(
s
),
error
);
Arg
arg
=
*
s
<
'0'
||
*
s
>
'9'
?
next_arg
(
error
)
:
get_arg
(
parse_nonnegative_int
(
s
),
error
);
if
(
error
)
{
FMT_THROW
(
FormatError
(
*
s
!=
'}'
&&
*
s
!=
':'
?
"invalid format string"
:
error
));
FMT_THROW
(
FormatError
(
*
s
!=
'}'
&&
*
s
!=
':'
?
"invalid format string"
:
error
));
}
return
arg
;
}
...
...
include/spdlog/details/spdlog_impl.h
View file @
c401e830
...
...
@@ -54,13 +54,13 @@ inline std::shared_ptr<spdlog::logger> spdlog::rotating_logger_st(const std::str
}
// Create file logger which creates new file at midnight):
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
force_flush
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
,
int
minute
,
bool
force_flush
)
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
force_flush
);
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
hour
,
minute
,
force_flush
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
force_flush
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
,
int
minute
,
bool
force_flush
)
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
force_flush
);
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
hour
,
minute
,
force_flush
);
}
...
...
include/spdlog/sinks/file_sinks.h
View file @
c401e830
...
...
@@ -155,14 +155,21 @@ template<class Mutex>
class
daily_file_sink
:
public
base_sink
<
Mutex
>
{
public:
explicit
daily_file_sink
(
const
std
::
string
&
base_filename
,
//create daily file sink which rotates on given time
daily_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
int
rotation_hour
,
int
rotation_minute
,
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
_extension
(
extension
),
_midnight_tp
(
_calc_midnight_tp
()
),
_rotation_h
(
rotation_hour
),
_rotation_m
(
rotation_minute
),
_file_helper
(
force_flush
)
{
if
(
rotation_hour
<
0
||
rotation_hour
>
23
||
rotation_minute
<
0
||
rotation_minute
>
59
)
throw
spdlog_ex
(
"daily_file_sink: Invalid rotation time in ctor"
);
_rotation_tp
=
_next_rotation_tp
(),
_file_helper
.
open
(
calc_filename
(
_base_filename
,
_extension
));
}
...
...
@@ -170,26 +177,30 @@ public:
protected:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
if
(
std
::
chrono
::
system_clock
::
now
()
>=
_
midnight
_tp
)
if
(
std
::
chrono
::
system_clock
::
now
()
>=
_
rotation
_tp
)
{
_file_helper
.
close
();
_file_helper
.
open
(
calc_filename
(
_base_filename
,
_extension
));
_
midnight_tp
=
_calc_midnight
_tp
();
_
rotation_tp
=
_next_rotation
_tp
();
}
_file_helper
.
write
(
msg
);
}
private:
// Return next midnight's time_point
static
std
::
chrono
::
system_clock
::
time_point
_calc_midnight_tp
()
std
::
chrono
::
system_clock
::
time_point
_next_rotation_tp
()
{
using
namespace
std
::
chrono
;
auto
now
=
system_clock
::
now
();
time_t
tnow
=
std
::
chrono
::
system_clock
::
to_time_t
(
now
);
tm
date
=
spdlog
::
details
::
os
::
localtime
(
tnow
);
date
.
tm_hour
=
date
.
tm_min
=
date
.
tm_sec
=
0
;
auto
midnight
=
std
::
chrono
::
system_clock
::
from_time_t
(
std
::
mktime
(
&
date
));
return
system_clock
::
time_point
(
midnight
+
hours
(
24
));
date
.
tm_hour
=
_rotation_h
;
date
.
tm_min
=
_rotation_m
;
date
.
tm_sec
=
0
;
auto
rotation_time
=
std
::
chrono
::
system_clock
::
from_time_t
(
std
::
mktime
(
&
date
));
if
(
rotation_time
>
now
)
return
rotation_time
;
else
return
system_clock
::
time_point
(
rotation_time
+
hours
(
24
));
}
//Create filename for the form basename.YYYY-MM-DD.extension
...
...
@@ -197,15 +208,18 @@ private:
{
std
::
tm
tm
=
spdlog
::
details
::
os
::
localtime
();
details
::
fmt
::
MemoryWriter
w
;
w
.
write
(
"{}
.{:04d}-{:02d}-{:02d}.{}"
,
basename
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
extension
);
w
.
write
(
"{}
_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.{}"
,
basename
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
extension
);
return
w
.
str
();
}
std
::
string
_base_filename
;
std
::
string
_extension
;
std
::
chrono
::
system_clock
::
time_point
_midnight_tp
;
int
_rotation_h
;
int
_rotation_m
;
std
::
chrono
::
system_clock
::
time_point
_rotation_tp
;
details
::
file_helper
_file_helper
;
};
typedef
daily_file_sink
<
std
::
mutex
>
daily_file_sink_mt
;
...
...
include/spdlog/spdlog.h
View file @
c401e830
...
...
@@ -84,10 +84,10 @@ std::shared_ptr<logger> rotating_logger_mt(const std::string& logger_name, const
std
::
shared_ptr
<
logger
>
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
=
false
);
//
// Create file logger which creates new file
at
midnight):
// Create file logger which creates new file
on the given time (default in
midnight):
//
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
force_flush
=
false
);
//
...
...
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