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
fc594b55
Unverified
Commit
fc594b55
authored
Jan 06, 2021
by
Charles Milette
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent win_eventlog_sink from silently discarding errors when wide support is enabled
parent
f39ccccc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
23 deletions
+11
-23
include/spdlog/common.h
include/spdlog/common.h
+1
-0
include/spdlog/details/os-inl.h
include/spdlog/details/os-inl.h
+3
-3
include/spdlog/details/os.h
include/spdlog/details/os.h
+1
-1
include/spdlog/sinks/win_eventlog_sink.h
include/spdlog/sinks/win_eventlog_sink.h
+6
-19
No files found.
include/spdlog/common.h
View file @
fc594b55
...
...
@@ -103,6 +103,7 @@ using err_handler = std::function<void(const std::string &err_msg)>;
using
string_view_t
=
fmt
::
basic_string_view
<
char
>
;
using
wstring_view_t
=
fmt
::
basic_string_view
<
wchar_t
>
;
using
memory_buf_t
=
fmt
::
basic_memory_buffer
<
char
,
250
>
;
using
wmemory_buf_t
=
fmt
::
basic_memory_buffer
<
wchar_t
,
250
>
;
using
filename_memory_buf_t
=
fmt
::
basic_memory_buffer
<
filename_t
::
value_type
,
250
>
;
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
...
...
include/spdlog/details/os-inl.h
View file @
fc594b55
...
...
@@ -469,7 +469,7 @@ SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target)
throw_spdlog_ex
(
fmt
::
format
(
"WideCharToMultiByte failed. Last error: {}"
,
::
GetLastError
()));
}
SPDLOG_INLINE
void
utf8_to_wstrbuf
(
string_view_t
str
,
memory_buf_t
&
target
)
SPDLOG_INLINE
void
utf8_to_wstrbuf
(
string_view_t
str
,
w
memory_buf_t
&
target
)
{
if
(
str
.
size
()
>
static_cast
<
size_t
>
((
std
::
numeric_limits
<
int
>::
max
)()))
{
...
...
@@ -484,7 +484,7 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, memory_buf_t &target)
}
int
result_size
=
static_cast
<
int
>
(
target
.
capacity
());
if
(
(
str_size
+
1
)
*
2
<
result_size
)
if
(
str_size
+
1
>
result_size
)
{
result_size
=
::
MultiByteToWideChar
(
CP_UTF8
,
MB_ERR_INVALID_CHARS
,
str
.
data
(),
str_size
,
NULL
,
0
);
}
...
...
@@ -492,7 +492,7 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, memory_buf_t &target)
if
(
result_size
>
0
)
{
target
.
resize
(
result_size
);
result_size
=
::
MultiByteToWideChar
(
CP_UTF8
,
MB_ERR_INVALID_CHARS
,
str
.
data
(),
str_size
,
(
LPWSTR
)
target
.
data
(),
result_size
);
result_size
=
::
MultiByteToWideChar
(
CP_UTF8
,
MB_ERR_INVALID_CHARS
,
str
.
data
(),
str_size
,
target
.
data
(),
result_size
);
if
(
result_size
>
0
)
{
...
...
include/spdlog/details/os.h
View file @
fc594b55
...
...
@@ -91,7 +91,7 @@ SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
SPDLOG_API
void
wstr_to_utf8buf
(
wstring_view_t
wstr
,
memory_buf_t
&
target
);
SPDLOG_API
void
utf8_to_wstrbuf
(
string_view_t
str
,
memory_buf_t
&
target
);
SPDLOG_API
void
utf8_to_wstrbuf
(
string_view_t
str
,
w
memory_buf_t
&
target
);
#endif
// Return directory name from given path or empty string
...
...
include/spdlog/sinks/win_eventlog_sink.h
View file @
fc594b55
...
...
@@ -224,35 +224,22 @@ protected:
formatted
.
push_back
(
'\0'
);
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
try
{
memory_buf_t
buf
;
details
::
os
::
utf8_to_wstrbuf
(
string_view_t
(
formatted
.
data
(),
formatted
.
size
()),
buf
);
wmemory_buf_t
buf
;
details
::
os
::
utf8_to_wstrbuf
(
string_view_t
(
formatted
.
data
(),
formatted
.
size
()),
buf
);
LPCWSTR
lp_wstr
=
reinterpret_cast
<
LPCWSTR
>
(
buf
.
data
()
);
succeeded
=
::
ReportEventW
(
event_log_handle
(),
eventlog
::
get_event_type
(
msg
),
eventlog
::
get_event_category
(
msg
),
event_id_
,
LPCWSTR
lp_wstr
=
buf
.
data
(
);
succeeded
=
::
ReportEventW
(
event_log_handle
(),
eventlog
::
get_event_type
(
msg
),
eventlog
::
get_event_category
(
msg
),
event_id_
,
current_user_sid_
.
as_sid
(),
1
,
0
,
&
lp_wstr
,
nullptr
);
if
(
!
succeeded
)
{
SPDLOG_THROW
(
win32_error
(
"ReportEvent"
));
}
}
catch
(...)
{
// WCHAR string conversion can fail and if it does, we shouldn't call to report event function.
}
#else
LPCSTR
lp_str
=
reinterpret_cast
<
LPCSTR
>
(
formatted
.
data
());
LPCSTR
lp_str
=
formatted
.
data
();
succeeded
=
::
ReportEventA
(
event_log_handle
(),
eventlog
::
get_event_type
(
msg
),
eventlog
::
get_event_category
(
msg
),
event_id_
,
current_user_sid_
.
as_sid
(),
1
,
0
,
&
lp_str
,
nullptr
);
#endif
if
(
!
succeeded
)
{
SPDLOG_THROW
(
win32_error
(
"ReportEvent"
));
}
#endif
}
void
flush_
()
override
{}
...
...
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