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
9c90fe82
Commit
9c90fe82
authored
Jul 20, 2021
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed wchar support
parent
b85a666f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
53 deletions
+52
-53
include/spdlog/logger.h
include/spdlog/logger.h
+52
-53
No files found.
include/spdlog/logger.h
View file @
9c90fe82
...
...
@@ -19,6 +19,9 @@
#include <spdlog/details/backtracer.h>
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
# ifndef _WIN32
# error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
# endif
# include <spdlog/details/os.h>
#endif
...
...
@@ -139,56 +142,6 @@ public:
log
(
loc
,
lvl
,
"{}"
,
msg
);
}
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
# ifndef _WIN32
# error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
# else
template
<
typename
...
Args
>
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
wstring_view_t
fmt
,
Args
&&
...
args
)
{
bool
log_enabled
=
should_log
(
lvl
);
bool
traceback_enabled
=
tracer_
.
enabled
();
if
(
!
log_enabled
&&
!
traceback_enabled
)
{
return
;
}
SPDLOG_TRY
{
// format to wmemory_buffer and convert to utf8
fmt
::
wmemory_buffer
wbuf
;
fmt
::
format_to
(
std
::
back_inserter
(
wbuf
),
fmt
,
std
::
forward
<
Args
>
(
args
)...);
memory_buf_t
buf
;
details
::
os
::
wstr_to_utf8buf
(
wstring_view_t
(
wbuf
.
data
(),
wbuf
.
size
()),
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
log_it_
(
log_msg
,
log_enabled
,
traceback_enabled
);
}
SPDLOG_LOGGER_CATCH
()
}
// T can be statically converted to wstring_view
template
<
class
T
,
typename
std
::
enable_if
<
is_convertible_to_wstring_view
<
const
T
&
>
::
value
,
int
>::
type
=
0
>
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
T
&
msg
)
{
bool
log_enabled
=
should_log
(
lvl
);
bool
traceback_enabled
=
tracer_
.
enabled
();
if
(
!
log_enabled
&&
!
traceback_enabled
)
{
return
;
}
SPDLOG_TRY
{
memory_buf_t
buf
;
details
::
os
::
wstr_to_utf8buf
(
msg
,
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
log_it_
(
log_msg
,
log_enabled
,
traceback_enabled
);
}
SPDLOG_LOGGER_CATCH
()
}
# endif // _WIN32
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
template
<
typename
FormatString
,
typename
...
Args
>
void
trace
(
const
FormatString
&
fmt
,
Args
&&
...
args
)
{
...
...
@@ -316,7 +269,9 @@ protected:
details
::
backtracer
tracer_
;
// common implementation for after templated public api has been resolved
template
<
typename
FormatString
,
typename
...
Args
>
template
<
typename
FormatString
,
typename
...
Args
,
typename
Char
=
fmt
::
char_t
<
FormatString
>,
typename
std
::
enable_if
<!
std
::
is_same
<
Char
,
wchar_t
>::
value
,
Char
>::
type
*
=
nullptr
>
void
log_
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
FormatString
&
fmt
,
Args
&&
...
args
)
{
bool
log_enabled
=
should_log
(
lvl
);
...
...
@@ -328,14 +283,58 @@ protected:
SPDLOG_TRY
{
memory_buf_t
buf
;
// little bit faster than fmt::format_to(std::back_inserter(buf), fmt, std::forward<Args>(args)...);
fmt
::
detail
::
vformat_to
(
buf
,
fmt
::
string_view
(
fmt
),
fmt
::
make_format_args
(
args
...),
{});
fmt
::
detail
::
vformat_to
(
buf
,
fmt
::
to_string_view
(
fmt
),
fmt
::
make_format_args
(
args
...));
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
log_it_
(
log_msg
,
log_enabled
,
traceback_enabled
);
}
SPDLOG_LOGGER_CATCH
()
}
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template
<
typename
...
Args
>
void
log_
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
wstring_view_t
&
fmt
,
Args
&&
...
args
)
{
bool
log_enabled
=
should_log
(
lvl
);
bool
traceback_enabled
=
tracer_
.
enabled
();
if
(
!
log_enabled
&&
!
traceback_enabled
)
{
return
;
}
SPDLOG_TRY
{
// format to wmemory_buffer and convert to utf8
fmt
::
wmemory_buffer
wbuf
;
fmt
::
format_to
(
std
::
back_inserter
(
wbuf
),
fmt
,
std
::
forward
<
Args
>
(
args
)...);
memory_buf_t
buf
;
details
::
os
::
wstr_to_utf8buf
(
wstring_view_t
(
wbuf
.
data
(),
wbuf
.
size
()),
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
log_it_
(
log_msg
,
log_enabled
,
traceback_enabled
);
}
SPDLOG_LOGGER_CATCH
()
}
// T can be statically converted to wstring_view, and no formatting needed.
template
<
class
T
,
typename
std
::
enable_if
<
std
::
is_convertible
<
const
T
&
,
spdlog
::
wstring_view_t
>
::
value
,
int
>::
type
=
0
>
void
log_
(
source_loc
loc
,
level
::
level_enum
lvl
,
const
T
&
msg
)
{
bool
log_enabled
=
should_log
(
lvl
);
bool
traceback_enabled
=
tracer_
.
enabled
();
if
(
!
log_enabled
&&
!
traceback_enabled
)
{
return
;
}
SPDLOG_TRY
{
memory_buf_t
buf
;
details
::
os
::
wstr_to_utf8buf
(
msg
,
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
log_it_
(
log_msg
,
log_enabled
,
traceback_enabled
);
}
SPDLOG_LOGGER_CATCH
()
}
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
// log the given message (if the given log level is high enough),
// and save backtrace (if backtrace is enabled).
void
log_it_
(
const
details
::
log_msg
&
log_msg
,
bool
log_enabled
,
bool
traceback_enabled
);
...
...
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