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
b09b07ab
Commit
b09b07ab
authored
Sep 18, 2015
by
Gabi Melman
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #133 from daersc/master
Add distributional sink
parents
f35520bf
2175b008
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
include/spdlog/sinks/dist_sink.h
include/spdlog/sinks/dist_sink.h
+92
-0
No files found.
include/spdlog/sinks/dist_sink.h
0 → 100644
View file @
b09b07ab
/*************************************************************************/
/* spdlog - an extremely fast and easy to use c++11 logging library. */
/* Copyright (c) 2015 David Schury. */
/* Copyright (c) 2014 Gabi Melman. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#pragma once
#include <algorithm>
#include <memory>
#include <mutex>
#include <list>
#include "../details/log_msg.h"
#include "../details/null_mutex.h"
#include "./base_sink.h"
#include "./sink.h"
namespace
spdlog
{
namespace
sinks
{
template
<
class
Mutex
>
class
dist_sink
:
public
base_sink
<
Mutex
>
{
public:
explicit
dist_sink
()
:
_sinks
()
{}
dist_sink
(
const
dist_sink
&
)
=
delete
;
dist_sink
&
operator
=
(
const
dist_sink
&
)
=
delete
;
virtual
~
dist_sink
()
=
default
;
protected:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
for
(
auto
iter
=
_sinks
.
begin
();
iter
!=
_sinks
.
end
();
iter
++
)
(
*
iter
)
->
log
(
msg
);
}
std
::
vector
<
std
::
shared_ptr
<
sink
>>
_sinks
;
public:
void
flush
()
override
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
_mutex
);
for
(
auto
iter
=
_sinks
.
begin
();
iter
!=
_sinks
.
end
();
iter
++
)
(
*
iter
)
->
flush
();
}
void
add_sink
(
std
::
shared_ptr
<
sink
>
sink
)
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
_mutex
);
if
(
sink
&&
_sinks
.
end
()
==
std
::
find
(
_sinks
.
begin
(),
_sinks
.
end
(),
sink
))
{
_sinks
.
push_back
(
sink
);
}
}
void
remove_sink
(
std
::
shared_ptr
<
sink
>
sink
)
{
std
::
lock_guard
<
Mutex
>
lock
(
base_sink
<
Mutex
>::
_mutex
);
auto
pos
=
std
::
find
(
_sinks
.
begin
(),
_sinks
.
end
(),
sink
);
if
(
pos
!=
_sinks
.
end
())
{
_sinks
.
erase
(
pos
);
}
}
};
typedef
dist_sink
<
std
::
mutex
>
dist_sink_mt
;
typedef
dist_sink
<
details
::
null_mutex
>
dist_sink_st
;
}
}
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