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
38584a1f
Unverified
Commit
38584a1f
authored
Feb 10, 2020
by
Gabi Melman
Committed by
GitHub
Feb 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1426 from Proheeler/v1.x
tcp_sink implementation for fluentbit
parents
12f36deb
d96d8c49
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
include/spdlog/tcp_sink.h
include/spdlog/tcp_sink.h
+51
-0
No files found.
include/spdlog/tcp_sink.h
0 → 100644
View file @
38584a1f
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include <spdlog/spdlog.h>
#include <spdlog/sinks/base_sink.h>
#include <spdlog/common-inl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
template
<
typename
Mutex
>
class
tcp_sink
:
public
spdlog
::
sinks
::
base_sink
<
Mutex
>
{
public:
tcp_sink
(
std
::
string
address
,
int
port
)
{
if
((
sock_
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
<
0
)
{
SPDLOG_THROW
(
spdlog
::
spdlog_ex
(
"Socket creation error"
,
errno
));
}
serv_addr_
.
sin_family
=
AF_INET
;
serv_addr_
.
sin_port
=
htons
(
port
);
if
(
inet_pton
(
AF_INET
,
address
.
c_str
(),
&
serv_addr_
.
sin_addr
)
<=
0
)
{
SPDLOG_THROW
(
spdlog
::
spdlog_ex
(
"Invalid address/ Address not supported"
,
errno
));
}
if
(
connect
(
sock_
,
(
struct
sockaddr
*
)
&
serv_addr_
,
sizeof
(
serv_addr_
))
<
0
)
{
SPDLOG_THROW
(
spdlog
::
spdlog_ex
(
"Connection Failed"
,
errno
));
}
}
protected:
void
sink_it_
(
const
spdlog
::
details
::
log_msg
&
msg
)
override
{
spdlog
::
memory_buf_t
formatted
;
spdlog
::
sinks
::
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
int
res
=
send
(
sock_
,
formatted
.
data
()
,
formatted
.
size
()
,
0
);
if
(
res
<
0
)
SPDLOG_THROW
(
spdlog
::
spdlog_ex
(
"Message Send Failed"
,
errno
));
}
void
flush_
()
override
{
}
private:
int
sock_
;
struct
sockaddr_in
serv_addr_
;
};
using
tcp_sink_mt
=
tcp_sink
<
std
::
mutex
>
;
using
tcp_sink_st
=
tcp_sink
<
spdlog
::
details
::
null_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