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
31a011e6
Commit
31a011e6
authored
Mar 12, 2015
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed daily sink syntax error and redundant file close
parent
53830726
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
19 deletions
+9
-19
include/spdlog/sinks/file_sinks.h
include/spdlog/sinks/file_sinks.h
+9
-19
No files found.
include/spdlog/sinks/file_sinks.h
View file @
31a011e6
...
...
@@ -30,21 +30,19 @@
#include "../details/file_helper.h"
#include "../details/format.h"
namespace
spdlog
{
namespace
sinks
{
/*
* Trivial file sink with single file as target
*/
template
<
class
Mutex
>
class
simple_file_sink
:
public
base_sink
<
Mutex
>
class
simple_file_sink
:
public
base_sink
<
Mutex
>
{
public:
explicit
simple_file_sink
(
const
std
::
string
&
filename
,
bool
force_flush
=
false
)
:
bool
force_flush
=
false
)
:
_file_helper
(
force_flush
)
{
_file_helper
.
open
(
filename
);
...
...
@@ -64,14 +62,14 @@ typedef simple_file_sink<details::null_mutex> simple_file_sink_st;
/*
* Rotating file sink based on size
*/
*/
template
<
class
Mutex
>
class
rotating_file_sink
:
public
base_sink
<
Mutex
>
class
rotating_file_sink
:
public
base_sink
<
Mutex
>
{
public:
rotating_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
std
::
size_t
max_size
,
std
::
size_t
max_files
,
bool
force_flush
=
false
)
:
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
_extension
(
extension
),
_max_size
(
max_size
),
...
...
@@ -82,12 +80,11 @@ public:
_file_helper
.
open
(
calc_filename
(
_base_filename
,
0
,
_extension
));
}
protected:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
_current_size
+=
msg
.
formatted
.
size
();
if
(
_current_size
>
_max_size
)
if
(
_current_size
>
_max_size
)
{
_rotate
();
_current_size
=
msg
.
formatted
.
size
();
...
...
@@ -95,7 +92,6 @@ protected:
_file_helper
.
write
(
msg
);
}
private:
static
std
::
string
calc_filename
(
const
std
::
string
&
filename
,
std
::
size_t
index
,
const
std
::
string
&
extension
)
{
...
...
@@ -107,14 +103,12 @@ private:
return
w
.
str
();
}
// Rotate files:
// log.txt -> log.1.txt
// log.1.txt -> log2.txt
// log.2.txt -> log3.txt
// log.3.txt -> delete
void
_rotate
()
{
_file_helper
.
close
();
...
...
@@ -152,7 +146,7 @@ typedef rotating_file_sink<details::null_mutex>rotating_file_sink_st;
* Rotating file sink based on date. rotates at midnight
*/
template
<
class
Mutex
>
class
daily_file_sink
:
public
base_sink
<
Mutex
>
class
daily_file_sink
:
public
base_sink
<
Mutex
>
{
public:
//create daily file sink which rotates on given time
...
...
@@ -161,7 +155,7 @@ public:
const
std
::
string
&
extension
,
int
rotation_hour
,
int
rotation_minute
,
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
_extension
(
extension
),
_rotation_h
(
rotation_hour
),
_rotation_m
(
rotation_minute
),
...
...
@@ -169,17 +163,15 @@ public:
{
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
()
,
_rotation_tp
=
_next_rotation_tp
()
;
_file_helper
.
open
(
calc_filename
(
_base_filename
,
_extension
));
}
protected:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
if
(
std
::
chrono
::
system_clock
::
now
()
>=
_rotation_tp
)
{
_file_helper
.
close
();
_file_helper
.
open
(
calc_filename
(
_base_filename
,
_extension
));
_rotation_tp
=
_next_rotation_tp
();
}
...
...
@@ -218,8 +210,6 @@ private:
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
;
...
...
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