Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
68ee9a7a
Commit
68ee9a7a
authored
Nov 24, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replaced flush_interval with auto_flush boolean
parent
c948f158
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
43 deletions
+40
-43
bench.cpp
example/bench.cpp
+14
-15
file_helper.h
include/spdlog/details/file_helper.h
+8
-10
spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+8
-8
file_sinks.h
include/spdlog/sinks/file_sinks.h
+6
-6
spdlog.h
include/spdlog/spdlog.h
+4
-4
No files found.
example/bench.cpp
View file @
68ee9a7a
...
...
@@ -52,7 +52,7 @@ int main(int argc, char* argv[])
int
howmany
=
1000000
;
int
threads
=
10
;
int
flush_interval
=
0
;
bool
auto_flush
=
true
;
int
file_size
=
30
*
1024
*
1024
;
int
rotating_files
=
5
;
...
...
@@ -63,39 +63,38 @@ int main(int argc, char* argv[])
howmany
=
atoi
(
argv
[
1
]);
if
(
argc
>
2
)
threads
=
atoi
(
argv
[
2
]);
/*
cout
<<
"*******************************************************************************
\n
"
;
cout << "Single thread, " << format(howmany) << " iterations,
flush every " << flush_interval << " lines"
<< endl;
cout
<<
"Single thread, "
<<
format
(
howmany
)
<<
" iterations,
auto flush="
<<
auto_flush
<<
endl
;
cout
<<
"*******************************************************************************
\n
"
;
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st", file_size, rotating_files,
flush_interval
);
auto
rotating_st
=
spdlog
::
rotating_logger_st
(
"rotating_st"
,
"logs/rotating_st"
,
file_size
,
rotating_files
,
auto_flush
);
bench
(
howmany
,
rotating_st
);
auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st",
flush_interval
);
auto
daily_st
=
spdlog
::
daily_logger_st
(
"daily_st"
,
"logs/daily_st"
,
auto_flush
);
bench
(
howmany
,
daily_st
);
bench
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_st"
));
cout
<<
"
\n
*******************************************************************************
\n
"
;
cout << threads << " threads sharing same logger, " << format(howmany) << " iterations,
flush every " << flush_interval << " lines"
<< endl;
cout
<<
threads
<<
" threads sharing same logger, "
<<
format
(
howmany
)
<<
" iterations,
auto_flush="
<<
auto_flush
<<
endl
;
cout
<<
"*******************************************************************************
\n
"
;
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt", file_size, rotating_files,
flush_interval
);
auto
rotating_mt
=
spdlog
::
rotating_logger_mt
(
"rotating_mt"
,
"logs/rotating_mt"
,
file_size
,
rotating_files
,
auto_flush
);
bench_mt
(
howmany
,
rotating_mt
,
threads
);
auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt",
flush_interval
);
auto
daily_mt
=
spdlog
::
daily_logger_mt
(
"daily_mt"
,
"logs/daily_mt"
,
auto_flush
);
bench_mt
(
howmany
,
daily_mt
,
threads
);
bench
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_mt"
));
cout
<<
"
\n
*******************************************************************************
\n
"
;
cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations,
flush every " << flush_interval << " lines"
<< endl;
e
cout << "*******************************************************************************\n";
*/
cout
<<
"async logging.. "
<<
threads
<<
" threads sharing same logger, "
<<
format
(
howmany
)
<<
" iterations,
auto_flush="
<<
auto_flush
<<
endl
;
cout
<<
"*******************************************************************************
\n
"
;
spdlog
::
set_async_mode
(
2500
);
auto
daily_st_async
=
spdlog
::
daily_logger_st
(
"daily_async"
,
"logs/daily_async"
,
flush_interval
);
bench_mt
(
howmany
,
daily_st_async
,
threads
);
auto
daily_st_async
=
spdlog
::
daily_logger_st
(
"daily_async"
,
"logs/daily_async"
,
auto_flush
);
bench_mt
(
howmany
,
daily_st_async
,
threads
);
spdlog
::
stop
();
}
...
...
include/spdlog/details/file_helper.h
View file @
68ee9a7a
...
...
@@ -26,7 +26,7 @@
// Helper class for file sink
// When failing to open a file, retry several times(5) with small delay between the tries(10 ms)
//
Flush to file every X writes (or never if X==0)
//
Can be set to auto flush on every line
// Throw spdlog_ex exception on errors
#include <cstdio>
...
...
@@ -49,10 +49,10 @@ public:
const
int
open_tries
=
5
;
const
int
open_interval
=
10
;
explicit
file_helper
(
const
std
::
size_t
flush_inverval
)
:
explicit
file_helper
(
bool
auto_flush
)
:
_fd
(
nullptr
),
_
flush_inverval
(
flush_inverval
),
_flush_countdown
(
flush_inverval
)
{};
_
auto_flush
(
auto_flush
)
{};
file_helper
(
const
file_helper
&
)
=
delete
;
file_helper
&
operator
=
(
const
file_helper
&
)
=
delete
;
...
...
@@ -104,11 +104,9 @@ public:
if
(
std
::
fwrite
(
buf
.
data
(),
sizeof
(
char
),
size
,
_fd
)
!=
size
)
throw
spdlog_ex
(
"Failed writing to file "
+
_filename
);
if
(
--
_flush_countdown
==
0
)
{
if
(
_auto_flush
)
std
::
fflush
(
_fd
);
_flush_countdown
=
_flush_inverval
;
}
}
const
std
::
string
&
filename
()
const
...
...
@@ -133,8 +131,8 @@ public:
private
:
FILE
*
_fd
;
std
::
string
_filename
;
const
std
::
size_t
_flush_inverval
;
std
::
size_t
_flush_countdown
;
bool
_auto_flush
;
};
}
...
...
include/spdlog/details/spdlog_impl.h
View file @
68ee9a7a
...
...
@@ -39,24 +39,24 @@ inline std::shared_ptr<spdlog::logger> spdlog::get(const std::string& name)
// Create multi/single threaded rotating file logger
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
auto_flush
)
{
return
create
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
flush_inverval
);
return
create
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
auto_flush
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
auto_flush
)
{
return
create
<
spdlog
::
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
flush_inverval
);
return
create
<
spdlog
::
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
auto_flush
);
}
// 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
,
size_t
flush_inverval
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
auto_flush
)
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
flush_inverval
);
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
auto_flush
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
auto_flush
)
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
flush_inverval
);
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
auto_flush
);
}
...
...
include/spdlog/sinks/file_sinks.h
View file @
68ee9a7a
...
...
@@ -45,8 +45,8 @@ class simple_file_sink : public base_sink<Mutex>
{
public
:
explicit
simple_file_sink
(
const
std
::
string
&
filename
,
const
std
::
size_t
flush_inverval
=
0
)
:
_file_helper
(
flush_inverval
)
bool
auto_flush
=
false
)
:
_file_helper
(
auto_flush
)
{
_file_helper
.
open
(
filename
);
}
...
...
@@ -72,13 +72,13 @@ 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
,
std
::
size_t
flush_inverval
=
0
)
:
bool
auto_flush
=
false
)
:
_base_filename
(
base_filename
),
_extension
(
extension
),
_max_size
(
max_size
),
_max_files
(
max_files
),
_current_size
(
0
),
_file_helper
(
flush_inverval
)
_file_helper
(
auto_flush
)
{
_file_helper
.
open
(
calc_filename
(
_base_filename
,
0
,
_extension
));
}
...
...
@@ -158,11 +158,11 @@ class daily_file_sink:public base_sink<Mutex>
public
:
explicit
daily_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
const
std
::
size_t
flush_inverval
=
0
)
:
bool
auto_flush
=
false
)
:
_base_filename
(
base_filename
),
_extension
(
extension
),
_midnight_tp
(
_calc_midnight_tp
()
),
_file_helper
(
flush_inverval
)
_file_helper
(
auto_flush
)
{
_file_helper
.
open
(
calc_filename
(
_base_filename
,
_extension
));
}
...
...
include/spdlog/spdlog.h
View file @
68ee9a7a
...
...
@@ -70,14 +70,14 @@ void set_sync_mode();
//
// Create multi/single threaded rotating file logger
//
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
size_t
flush_inverval
=
0
);
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
,
size_t
flush_inverval
=
0
);
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
auto_fush
=
false
);
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
auto_fush
=
false
);
//
// Create file logger which creates new file at midnight):
//
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
=
0
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
flush_inverval
=
0
);
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
auto_fush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
bool
auto_fush
=
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