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
2686ae23
Unverified
Commit
2686ae23
authored
Feb 26, 2021
by
Gabi Melman
Committed by
GitHub
Feb 26, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1847 from fawdlstty/v1.x
add daily sink filename format
parents
23dfb4e2
a709e295
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
include/spdlog/sinks/daily_file_sink.h
include/spdlog/sinks/daily_file_sink.h
+30
-0
No files found.
include/spdlog/sinks/daily_file_sink.h
View file @
2686ae23
...
...
@@ -7,6 +7,7 @@
#include <spdlog/details/file_helper.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/fmt/fmt.h>
#include <spdlog/fmt/chrono.h>
#include <spdlog/sinks/base_sink.h>
#include <spdlog/details/os.h>
#include <spdlog/details/circular_q.h>
...
...
@@ -36,6 +37,19 @@ struct daily_filename_calculator
}
};
/*
* Generator of daily log file names by formatting
*/
struct
daily_filename_format_calculator
{
// Create filename by formatting %Y_%m_%d.log
static
filename_t
calc_filename
(
const
filename_t
&
filename
,
const
tm
&
now_tm
)
{
filename_t
fmt_filename
=
fmt
::
format
(
SPDLOG_FILENAME_T
(
"{{:{}}}"
),
filename
);
return
fmt
::
format
(
fmt_filename
,
now_tm
);
}
};
/*
* Rotating file sink based on date.
* If truncate != false , the created file will be truncated.
...
...
@@ -182,6 +196,8 @@ private:
using
daily_file_sink_mt
=
daily_file_sink
<
std
::
mutex
>
;
using
daily_file_sink_st
=
daily_file_sink
<
details
::
null_mutex
>
;
using
daily_file_format_sink_mt
=
daily_file_sink
<
std
::
mutex
,
daily_filename_format_calculator
>
;
using
daily_file_format_sink_st
=
daily_file_sink
<
details
::
null_mutex
,
daily_filename_format_calculator
>
;
}
// namespace sinks
...
...
@@ -195,10 +211,24 @@ inline std::shared_ptr<logger> daily_logger_mt(
return
Factory
::
template
create
<
sinks
::
daily_file_sink_mt
>(
logger_name
,
filename
,
hour
,
minute
,
truncate
,
max_files
);
}
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
inline
std
::
shared_ptr
<
logger
>
daily_logger_format_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
truncate
=
false
,
uint16_t
max_files
=
0
)
{
return
Factory
::
template
create
<
sinks
::
daily_file_format_sink_mt
>(
logger_name
,
filename
,
hour
,
minute
,
truncate
,
max_files
);
}
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
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
,
uint16_t
max_files
=
0
)
{
return
Factory
::
template
create
<
sinks
::
daily_file_sink_st
>(
logger_name
,
filename
,
hour
,
minute
,
truncate
,
max_files
);
}
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
inline
std
::
shared_ptr
<
logger
>
daily_logger_format_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
truncate
=
false
,
uint16_t
max_files
=
0
)
{
return
Factory
::
template
create
<
sinks
::
daily_file_format_sink_st
>(
logger_name
,
filename
,
hour
,
minute
,
truncate
,
max_files
);
}
}
// 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