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
486dc510
Commit
486dc510
authored
Sep 03, 2021
by
Chris Love
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Winsock support
parent
4501f21a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
example/example.cpp
example/example.cpp
+11
-4
include/spdlog/details/udp_client-windows.h
include/spdlog/details/udp_client-windows.h
+5
-3
No files found.
example/example.cpp
View file @
486dc510
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
// spdlog usage example
// spdlog usage example
#include <cstdio>
#include <cstdio>
#include <chrono>
void
load_levels_example
();
void
load_levels_example
();
void
stdout_logger_example
();
void
stdout_logger_example
();
...
@@ -19,8 +20,8 @@ void multi_sink_example();
...
@@ -19,8 +20,8 @@ void multi_sink_example();
void
user_defined_example
();
void
user_defined_example
();
void
err_handler_example
();
void
err_handler_example
();
void
syslog_example
();
void
syslog_example
();
void
custom_flags_example
();
void
udp_example
();
void
udp_example
();
void
custom_flags_example
();
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
...
@@ -75,8 +76,8 @@ int main(int, char *[])
...
@@ -75,8 +76,8 @@ int main(int, char *[])
err_handler_example
();
err_handler_example
();
trace_example
();
trace_example
();
stopwatch_example
();
stopwatch_example
();
custom_flags_example
();
udp_example
();
udp_example
();
custom_flags_example
();
// Flush all *registered* loggers using a worker thread every 3 seconds.
// Flush all *registered* loggers using a worker thread every 3 seconds.
// note: registered loggers *must* be thread safe for this to work correctly!
// note: registered loggers *must* be thread safe for this to work correctly!
...
@@ -208,13 +209,19 @@ void stopwatch_example()
...
@@ -208,13 +209,19 @@ void stopwatch_example()
spdlog
::
info
(
"Stopwatch: {} seconds"
,
sw
);
spdlog
::
info
(
"Stopwatch: {} seconds"
,
sw
);
}
}
using
namespace
std
::
chrono_literals
;
void
udp_example
()
void
udp_example
()
{
{
spdlog
::
sinks
::
udp_sink_config
cfg
(
"127.0.0.1"
,
11091
);
spdlog
::
sinks
::
udp_sink_config
cfg
(
"127.0.0.1"
,
11091
);
auto
my_logger
=
spdlog
::
udp_logger_mt
(
"udplog"
,
cfg
);
auto
my_logger
=
spdlog
::
udp_logger_mt
(
"udplog"
,
cfg
);
my_logger
->
set_level
(
spdlog
::
level
::
debug
);
my_logger
->
set_level
(
spdlog
::
level
::
debug
);
my_logger
->
info
(
"hello world"
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
my_logger
->
info
(
"are you ok"
);
my_logger
->
info
(
"hello world {}"
,
i
);
#ifndef _WIN32
// sendto() on winsock will drop packets if sent too quickly
std
::
this_thread
::
sleep_for
(
40ms
);
#endif
}
}
}
// A logger with multiple sinks (stdout and file) - each with a different format and log level.
// A logger with multiple sinks (stdout and file) - each with a different format and log level.
...
...
include/spdlog/details/udp_client-windows.h
View file @
486dc510
...
@@ -79,9 +79,10 @@ public:
...
@@ -79,9 +79,10 @@ public:
close
();
close
();
}
}
addr_
.
sin_family
=
A
F_INET
;
addr_
.
sin_family
=
P
F_INET
;
addr_
.
sin_port
=
htons
(
port
);
addr_
.
sin_port
=
htons
(
port
);
InetPton
(
AF_INET
,
TEXT
(
host
.
c_str
()),
&
addr_
.
sin_addr
.
s_addr
);
addr_
.
sin_addr
.
s_addr
=
INADDR_ANY
;
InetPton
(
PF_INET
,
TEXT
(
host
.
c_str
()),
&
addr_
.
sin_addr
.
s_addr
);
socket_
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
socket_
=
socket
(
PF_INET
,
SOCK_DGRAM
,
0
);
if
(
socket_
==
INVALID_SOCKET
)
if
(
socket_
==
INVALID_SOCKET
)
...
@@ -113,7 +114,8 @@ public:
...
@@ -113,7 +114,8 @@ public:
void
send
(
const
char
*
data
,
size_t
n_bytes
)
void
send
(
const
char
*
data
,
size_t
n_bytes
)
{
{
if
((
sendto
(
socket_
,
data
,
static_cast
<
int
>
(
n_bytes
),
0
,
(
struct
sockaddr
*
)
&
addr_
,
sizeof
(
struct
sockaddr
)))
==
-
1
)
socklen_t
tolen
=
sizeof
(
struct
sockaddr
);
if
(
sendto
(
socket_
,
data
,
static_cast
<
int
>
(
n_bytes
),
0
,
(
struct
sockaddr
*
)
&
addr_
,
tolen
)
==
-
1
)
{
{
throw_spdlog_ex
(
"sendto(2) failed"
,
errno
);
throw_spdlog_ex
(
"sendto(2) failed"
,
errno
);
close
();
close
();
...
...
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