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
b7209810
Commit
b7209810
authored
May 06, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackbuf move ctor
parent
3463dcd1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
32 deletions
+44
-32
example.cpp
example/example.cpp
+4
-6
line_logger.h
include/c11log/details/line_logger.h
+16
-6
log_msg.h
include/c11log/details/log_msg.h
+0
-7
stack_buf.h
include/c11log/details/stack_buf.h
+5
-6
stack_oss.h
include/c11log/details/stack_oss.h
+17
-5
async_sink.h
include/c11log/sinks/async_sink.h
+2
-2
No files found.
example/example.cpp
View file @
b7209810
...
...
@@ -23,7 +23,7 @@ int main(int argc, char* argv[])
logger
cout_logger
(
""
,
sinks
::
stdout_sink
());
cout_logger
.
set_min_level
(
c11log
::
level
::
TRACE
);
cout_logger
.
info
()
<<
"Hello "
<<
"man"
<<
123
;
cout_logger
.
trace
(
"This is very nice! "
)
<<
"Yes gabi.."
<<
":)"
;
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink
>
(
"log"
,
"txt"
,
1024
*
1024
*
50
,
5
,
0
);
auto
nullsink
=
sinks
::
null_sink
::
get
();
...
...
@@ -35,16 +35,14 @@ int main(int argc, char* argv[])
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
1
;
i
<=
howmany
;
++
i
)
my_logger
.
info
(
"Hello logger: "
)
<<
4.5
<<
123
<<
"asdasd
"
<<
123
<<
'f'
;
my_logger
.
info
(
"Hello logger: "
)
<<
4.5
<<
'\t'
<<
i
<<
"
\t
asdasd:
"
<<
123
<<
'f'
;
//auto s = howmany - as->q().size();
auto
s
=
howmany
;
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout_logger
.
info
(
"Total:"
)
<<
format
(
s
);
cout_logger
.
info
(
"Total:"
)
<<
format
(
howmany
);
cout_logger
.
info
(
"Delta:"
)
<<
format
(
delta_d
);
cout_logger
.
info
(
"Rate:"
)
<<
format
(
s
/
delta_d
)
<<
"/sec"
;
cout_logger
.
info
(
"Rate:"
)
<<
format
(
howmany
/
delta_d
)
<<
"/sec"
;
return
0
;
}
include/c11log/details/line_logger.h
View file @
b7209810
...
...
@@ -39,18 +39,23 @@ public:
line_logger
&
operator
=
(
const
line_logger
&
)
=
delete
;
line_logger
&
operator
=
(
line_logger
&&
)
=
delete
;
line_logger
(
line_logger
&&
other
)
:
_callback_logger
(
other
.
_callback_logger
),
_log_msg
(
other
.
_log_msg
),
// The move ctor should only be called on start of logging line,
// where no logging happened yet for this line so no need to copy the oss from the other
_oss
(),
_enabled
(
other
.
_enabled
)
{}
_log_msg
(
std
::
move
(
other
.
_log_msg
)),
_oss
(
std
::
move
(
other
.
_oss
)),
_enabled
(
other
.
_enabled
),
_empty
(
other
.
_empty
)
{
other
.
disable
();
}
~
line_logger
()
{
//only if enabled and not empty
if
(
!
_empty
)
if
(
_enabled
&&
!
_empty
)
{
_oss
<<
os
::
eol
();
_log_msg
.
msg_buf
=
_oss
.
buf
();
...
...
@@ -75,6 +80,11 @@ public:
return
*
this
;
}
void
disable
()
{
_enabled
=
false
;
}
private
:
...
...
include/c11log/details/log_msg.h
View file @
b7209810
...
...
@@ -8,13 +8,6 @@ struct log_msg
{
log_msg
()
=
default
;
log_msg
(
level
::
level_enum
l
)
:
msg_level
(
l
)
{};
log_msg
(
const
log_msg
&
other
)
{
msg_buf
=
other
.
msg_buf
;
msg_time
=
other
.
msg_time
;
msg_header_size
=
other
.
msg_header_size
;
msg_level
=
other
.
msg_level
;
}
bufpair_t
msg_buf
;
log_clock
::
time_point
msg_time
;
...
...
include/c11log/details/stack_buf.h
View file @
b7209810
...
...
@@ -8,7 +8,6 @@
// Fast memory storage
// stores its contents on the stack when possible, in vector<char> otherwise
// NOTE: User should be remember that returned buffer might be on the stack!!
namespace
c11log
{
namespace
details
...
...
@@ -18,9 +17,12 @@ template<std::size_t STACK_SIZE=128>
class
stack_buf
{
public
:
stack_buf
()
:
_stack_size
(
0
)
{}
stack_buf
()
:
_
v
(),
_stack_buf
(),
_
stack_size
(
0
)
{}
~
stack_buf
()
{};
stack_buf
&
operator
=
(
const
stack_buf
other
)
=
delete
;
stack_buf
&
operator
=
(
stack_buf
&&
other
)
=
delete
;
stack_buf
(
const
bufpair_t
&
buf_to_copy
)
:
stack_buf
()
{
append
(
buf_to_copy
);
...
...
@@ -39,15 +41,12 @@ public:
{
_stack_size
=
other
.
_stack_size
;
if
(
!
other
.
_v
.
empty
())
_v
=
other
.
_v
;
_v
=
std
::
move
(
other
.
_v
)
;
else
if
(
_stack_size
)
std
::
copy
(
other
.
_stack_buf
.
begin
(),
other
.
_stack_buf
.
begin
()
+
_stack_size
,
_stack_buf
.
begin
());
other
.
clear
();
}
stack_buf
&
operator
=
(
const
stack_buf
&
other
)
=
delete
;
stack_buf
&
operator
=
(
stack_buf
&&
other
)
=
delete
;
void
append
(
const
char
*
buf
,
std
::
size_t
buf_size
)
{
//If we are aleady using _v, forget about the stack
...
...
include/c11log/details/stack_oss.h
View file @
b7209810
...
...
@@ -16,10 +16,15 @@ public:
stack_devicebuf
()
=
default
;
~
stack_devicebuf
()
=
default
;
stack_devicebuf
(
const
stack_devicebuf
&
other
)
=
delete
;
stack_devicebuf
(
stack_devicebuf
&&
other
)
=
delete
;
stack_devicebuf
&
operator
=
(
const
stack_devicebuf
&
)
=
delete
;
stack_devicebuf
&
operator
=
(
stack_devicebuf
&&
)
=
delete
;
stack_devicebuf
(
const
stack_devicebuf
&
other
)
:
std
::
basic_streambuf
<
char
>
(),
_stackbuf
(
other
.
_stackbuf
)
{}
stack_devicebuf
(
stack_devicebuf
&&
other
)
:
std
::
basic_streambuf
<
char
>
(),
_stackbuf
(
std
::
move
(
other
.
_stackbuf
))
{
other
.
clear
();
}
bufpair_t
buf
()
const
{
...
...
@@ -63,9 +68,16 @@ public:
stack_oss
()
:
std
::
ostream
(
&
_dev
)
{}
~
stack_oss
()
=
default
;
stack_oss
(
const
stack_oss
&
other
)
=
delete
;
stack_oss
(
stack_oss
&&
other
)
=
delete
;
stack_oss
&
operator
=
(
const
stack_oss
&
other
)
=
delete
;
stack_oss
&
operator
=
(
const
stack_oss
&&
other
)
=
delete
;
stack_oss
(
const
stack_oss
&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
other
.
_dev
)
{}
stack_oss
(
stack_oss
&&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
std
::
move
(
other
.
_dev
))
{
other
.
clear
();
}
bufpair_t
buf
()
const
{
...
...
include/c11log/sinks/async_sink.h
View file @
b7209810
...
...
@@ -29,7 +29,7 @@ class async_sink : public base_sink
public
:
using
queue_type
=
c11log
::
details
::
blocking_queue
<
std
::
unique_ptr
<
details
::
log_msg
,
std
::
function
<
void
(
details
::
log_msg
*
)
>>>
;
using
queue_type
=
details
::
blocking_queue
<
std
::
unique_ptr
<
details
::
log_msg
,
std
::
function
<
void
(
details
::
log_msg
*
)
>>>
;
explicit
async_sink
(
const
queue_type
::
size_type
max_queue_size
);
...
...
@@ -82,7 +82,7 @@ inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
if
(
!
_active
||
!
msg_size
)
return
;
//re allocate on the heap the (stack based) message
auto
new_msg
=
new
details
::
log_msg
(
msg
);
details
::
log_msg
*
new_msg
=
new
details
::
log_msg
(
msg
);
char
*
buf
=
new
char
[
msg_size
];
std
::
memcpy
(
buf
,
msg
.
msg_buf
.
first
,
msg_size
);
...
...
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