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
346b9ae5
Commit
346b9ae5
authored
Feb 10, 2020
by
v.reshetnikov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tcp_sink implementation for fluentbit
parent
12f36deb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
include/spdlog/tcp_sink.h
include/spdlog/tcp_sink.h
+47
-0
No files found.
include/spdlog/tcp_sink.h
0 → 100644
View file @
346b9ae5
#include <spdlog/spdlog.h>
#include <spdlog/sinks/base_sink.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
using
namespace
std
;
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
)
{
printf
(
"
\n
Socket creation error
\n
"
);
}
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
)
{
printf
(
"
\n
Invalid address/ Address not supported
\n
"
);
}
if
(
connect
(
sock
,
(
struct
sockaddr
*
)
&
serv_addr
,
sizeof
(
serv_addr
))
<
0
)
{
printf
(
"
\n
Connection Failed
\n
"
);
}
}
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
);
std
::
string
message
=
fmt
::
to_string
(
formatted
);
send
(
sock
,
message
.
c_str
()
,
message
.
size
()
,
0
);
}
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