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
8b42b7d2
Commit
8b42b7d2
authored
Oct 02, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix support for wchar to utf8 under windows (fix issue #851 and #764)
parent
17702969
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
14 deletions
+31
-14
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+29
-7
include/spdlog/logger.h
include/spdlog/logger.h
+2
-7
No files found.
include/spdlog/details/logger_impl.h
View file @
8b42b7d2
...
...
@@ -175,6 +175,29 @@ inline void spdlog::logger::critical(const T &msg)
}
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
static_assert
(
_WIN32
,
"SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows"
);
inline
void
wbuf_to_utf8buf
(
const
fmt
::
wmemory_buffer
&
wbuf
,
fmt
::
memory_buffer
&
target
)
{
int
wbuf_size
=
static_cast
<
int
>
(
wbuf
.
size
());
if
(
wbuf_size
==
0
)
{
return
;
}
auto
result_size
=
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
wbuf
.
data
(),
wbuf_size
,
NULL
,
0
,
NULL
,
NULL
);
if
(
result_size
>
0
)
{
target
.
resize
(
result_size
);
::
WideCharToMultiByte
(
CP_UTF8
,
0
,
wbuf
.
data
(),
wbuf_size
,
&
target
.
data
()[
0
],
result_size
,
NULL
,
NULL
);
}
else
{
throw
spdlog
::
spdlog_ex
(
"Failed converting to utf8"
,
errno
);
}
}
template
<
typename
...
Args
>
inline
void
spdlog
::
logger
::
log
(
level
::
level_enum
lvl
,
const
wchar_t
*
fmt
,
const
Args
&
...
args
)
{
...
...
@@ -183,15 +206,14 @@ inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const
return
;
}
decltype
(
wstring_converter_
)
::
byte_string
utf8_string
;
try
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
wstring_converter_mutex_
);
utf8_string
=
wstring_converter_
.
to_bytes
(
fmt
);
}
log
(
lvl
,
utf8_string
.
c_str
(),
args
...);
// format to wmemory_buffer and convert to utf8
details
::
log_msg
log_msg
(
&
name_
,
lvl
);
fmt
::
wmemory_buffer
wbuf
;
fmt
::
format_to
(
wbuf
,
fmt
,
args
...);
wbuf_to_utf8buf
(
wbuf
,
log_msg
.
raw
);
sink_it_
(
log_msg
);
}
SPDLOG_CATCH_AND_HANDLE
}
...
...
include/spdlog/logger.h
View file @
8b42b7d2
...
...
@@ -25,6 +25,7 @@
#include <memory>
#include <string>
#include <vector>
#include <locale>
namespace
spdlog
{
...
...
@@ -146,8 +147,7 @@ protected:
// message/minute
void
default_err_handler_
(
const
std
::
string
&
msg
);
// increment the message count (only if
// defined(SPDLOG_ENABLE_MESSAGE_COUNTER))
// increment the message count (only if defined(SPDLOG_ENABLE_MESSAGE_COUNTER))
void
incr_msg_counter_
(
details
::
log_msg
&
msg
);
const
std
::
string
name_
;
...
...
@@ -157,11 +157,6 @@ protected:
log_err_handler
err_handler_
;
std
::
atomic
<
time_t
>
last_err_time_
;
std
::
atomic
<
size_t
>
msg_counter_
;
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
std
::
wstring_convert
<
std
::
codecvt_utf8
<
wchar_t
>>
wstring_converter_
;
std
::
mutex
wstring_converter_mutex_
;
#endif
};
}
// namespace spdlog
...
...
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