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
6f0cb636
Commit
6f0cb636
authored
Nov 08, 2019
by
Václav Šmilauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ringbuffer_sink to spdlog::details::circular_q, enhance its API: size(), at(i)
parent
acf32be8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
9 deletions
+20
-9
include/spdlog/details/circular_q.h
include/spdlog/details/circular_q.h
+14
-0
include/spdlog/sinks/ringbuffer_sink-inl.h
include/spdlog/sinks/ringbuffer_sink-inl.h
+4
-6
include/spdlog/sinks/ringbuffer_sink.h
include/spdlog/sinks/ringbuffer_sink.h
+2
-3
No files found.
include/spdlog/details/circular_q.h
View file @
6f0cb636
...
@@ -72,6 +72,20 @@ public:
...
@@ -72,6 +72,20 @@ public:
return
v_
[
head_
];
return
v_
[
head_
];
}
}
// Return number of elements actually stored
size_t
size
()
const
{
return
(
tail_
-
head_
)
%
max_items_
;
}
// Return const reference to item by index.
// If index is out of range 0…size()-1, the behavior is undefined.
const
T
&
at
(
size_t
i
)
const
{
assert
(
i
<
size
());
return
v_
[(
head_
+
i
)
%
max_items_
];
}
// Pop item from front.
// Pop item from front.
// If there are no elements in the container, the behavior is undefined.
// If there are no elements in the container, the behavior is undefined.
void
pop_front
()
void
pop_front
()
...
...
include/spdlog/sinks/ringbuffer_sink-inl.h
View file @
6f0cb636
...
@@ -10,15 +10,13 @@
...
@@ -10,15 +10,13 @@
#include "spdlog/common.h"
#include "spdlog/common.h"
#include "spdlog/details/os.h"
#include "spdlog/details/os.h"
#include<boost/circular_buffer.hpp>
namespace
spdlog
{
namespace
spdlog
{
namespace
sinks
{
namespace
sinks
{
template
<
typename
Mutex
>
template
<
typename
Mutex
>
SPDLOG_INLINE
ringbuffer_sink
<
Mutex
>::
ringbuffer_sink
(
size_t
buf_size
)
SPDLOG_INLINE
ringbuffer_sink
<
Mutex
>::
ringbuffer_sink
(
size_t
buf_size
)
{
{
buf
.
set_capacity
(
buf_size
);
buf
=
details
::
circular_q
<
std
::
string
>
(
buf_size
);
}
}
template
<
typename
Mutex
>
template
<
typename
Mutex
>
...
@@ -26,7 +24,7 @@ SPDLOG_INLINE void ringbuffer_sink<Mutex>::sink_it_(const details::log_msg &msg)
...
@@ -26,7 +24,7 @@ SPDLOG_INLINE void ringbuffer_sink<Mutex>::sink_it_(const details::log_msg &msg)
{
{
memory_buf_t
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
buf
.
push_
front
(
fmt
::
to_string
(
formatted
));
buf
.
push_
back
(
fmt
::
to_string
(
formatted
));
}
}
template
<
typename
Mutex
>
template
<
typename
Mutex
>
...
@@ -36,9 +34,9 @@ SPDLOG_INLINE std::vector<std::string> ringbuffer_sink<Mutex>::last(size_t lim)
...
@@ -36,9 +34,9 @@ SPDLOG_INLINE std::vector<std::string> ringbuffer_sink<Mutex>::last(size_t lim)
std
::
vector
<
std
::
string
>
ret
;
std
::
vector
<
std
::
string
>
ret
;
ret
.
reserve
(
lim
);
ret
.
reserve
(
lim
);
size_t
num
=
0
;
size_t
num
=
0
;
for
(
const
std
::
string
&
msg
:
buf
){
for
(
size_t
i
=
0
;
i
<
buf
.
size
();
i
++
){
num
++
;
num
++
;
ret
.
push_back
(
msg
);
ret
.
push_back
(
buf
.
at
(
i
)
);
if
(
lim
>
0
&&
num
==
lim
)
break
;
if
(
lim
>
0
&&
num
==
lim
)
break
;
}
}
return
ret
;
return
ret
;
...
...
include/spdlog/sinks/ringbuffer_sink.h
View file @
6f0cb636
...
@@ -6,13 +6,12 @@
...
@@ -6,13 +6,12 @@
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/sinks/base_sink.h"
#include "spdlog/sinks/base_sink.h"
#include "spdlog/details/synchronous_factory.h"
#include "spdlog/details/synchronous_factory.h"
#include "spdlog/details/circular_q.h"
#include <mutex>
#include <mutex>
#include <string>
#include <string>
#include <vector>
#include <vector>
#include<boost/circular_buffer.hpp>
namespace
spdlog
{
namespace
spdlog
{
namespace
sinks
{
namespace
sinks
{
/*
/*
...
@@ -30,7 +29,7 @@ protected:
...
@@ -30,7 +29,7 @@ protected:
void
flush_
()
override
{};
void
flush_
()
override
{};
private:
private:
boost
::
circular_buffer
<
std
::
string
>
buf
;
details
::
circular_q
<
std
::
string
>
buf
;
};
};
using
ringbuffer_sink_mt
=
ringbuffer_sink
<
std
::
mutex
>
;
using
ringbuffer_sink_mt
=
ringbuffer_sink
<
std
::
mutex
>
;
...
...
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