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
48d4ed9b
Commit
48d4ed9b
authored
Sep 27, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1675
parent
3bed7835
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
include/spdlog/sinks/stdout_sinks-inl.h
include/spdlog/sinks/stdout_sinks-inl.h
+27
-3
include/spdlog/sinks/stdout_sinks.h
include/spdlog/sinks/stdout_sinks.h
+4
-0
No files found.
include/spdlog/sinks/stdout_sinks-inl.h
View file @
48d4ed9b
...
...
@@ -11,6 +11,15 @@
#include <spdlog/pattern_formatter.h>
#include <memory>
#ifdef _WIN32
// under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675)
// so instead we use ::FileWrite
#include <spdlog/details/windows_include.h>
#include <fileapi.h> // WriteFile (..)
#include <io.h> // _get_osfhandle(..)
#include <stdio.h> // _fileno(..)
#endif // WIN32
namespace
spdlog
{
namespace
sinks
{
...
...
@@ -20,7 +29,16 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
:
mutex_
(
ConsoleMutex
::
mutex
())
,
file_
(
file
)
,
formatter_
(
details
::
make_unique
<
spdlog
::
pattern_formatter
>
())
{}
{
#ifdef _WIN32
// get windows handle from the FILE* object
handle_
=
(
HANDLE
)
::
_get_osfhandle
(
::
_fileno
(
file_
));
if
(
handle_
==
INVALID_HANDLE_VALUE
)
{
throw_spdlog_ex
(
"spdlog::stdout_sink_base: _get_osfhandle() failed"
,
errno
);
}
#endif // WIN32
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
stdout_sink_base
<
ConsoleMutex
>::
log
(
const
details
::
log_msg
&
msg
)
...
...
@@ -28,8 +46,14 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
memory_buf_t
formatted
;
formatter_
->
format
(
msg
,
formatted
);
fwrite
(
formatted
.
data
(),
sizeof
(
char
),
formatted
.
size
(),
file_
);
fflush
(
file_
);
// flush every line to terminal
#ifdef _WIN32
auto
size
=
static_cast
<
DWORD
>
(
formatted
.
size
());
DWORD
bytes_written
=
0
;
::
WriteFile
(
handle_
,
formatted
.
data
(),
size
,
&
bytes_written
,
nullptr
);
#else
::
fwrite
(
formatted
.
data
(),
sizeof
(
char
),
formatted
.
size
(),
file_
);
::
fflush
(
file_
);
// flush every line to terminal
#endif // WIN32
}
template
<
typename
ConsoleMutex
>
...
...
include/spdlog/sinks/stdout_sinks.h
View file @
48d4ed9b
...
...
@@ -7,6 +7,7 @@
#include <spdlog/details/synchronous_factory.h>
#include <spdlog/sinks/sink.h>
#include <cstdio>
#include <spdlog/details/windows_include.h>
namespace
spdlog
{
...
...
@@ -36,6 +37,9 @@ protected:
mutex_t
&
mutex_
;
FILE
*
file_
;
std
::
unique_ptr
<
spdlog
::
formatter
>
formatter_
;
#ifdef _WIN32
HANDLE
handle_
;
#endif // WIN32
};
template
<
typename
ConsoleMutex
>
...
...
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