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
91046e6c
Commit
91046e6c
authored
Feb 13, 2021
by
Gabi Melman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify wincolor sink color mode management
parent
17e1ba8a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
16 deletions
+18
-16
include/spdlog/sinks/wincolor_sink-inl.h
include/spdlog/sinks/wincolor_sink-inl.h
+17
-14
include/spdlog/sinks/wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+1
-2
No files found.
include/spdlog/sinks/wincolor_sink-inl.h
View file @
91046e6c
...
@@ -22,12 +22,7 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color
...
@@ -22,12 +22,7 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color
,
formatter_
(
details
::
make_unique
<
spdlog
::
pattern_formatter
>
())
,
formatter_
(
details
::
make_unique
<
spdlog
::
pattern_formatter
>
())
{
{
// check if out_handle is points to the actual console.
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
DWORD
console_mode
;
in_console_
=
::
GetConsoleMode
(
static_cast
<
HANDLE
>
(
out_handle_
),
&
console_mode
)
!=
0
;
set_color_mode_impl
(
mode
);
set_color_mode_impl
(
mode
);
// set level colors
// set level colors
colors_
[
level
::
trace
]
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
// white
colors_
[
level
::
trace
]
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
// white
colors_
[
level
::
debug
]
=
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
// cyan
colors_
[
level
::
debug
]
=
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
// cyan
...
@@ -66,16 +61,10 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
...
@@ -66,16 +61,10 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
msg
.
color_range_end
=
0
;
msg
.
color_range_end
=
0
;
memory_buf_t
formatted
;
memory_buf_t
formatted
;
formatter_
->
format
(
msg
,
formatted
);
formatter_
->
format
(
msg
,
formatted
);
if
(
!
in_console_
)
{
write_to_file_
(
formatted
);
return
;
}
if
(
should_do_colors_
&&
msg
.
color_range_end
>
msg
.
color_range_start
)
if
(
should_do_colors_
&&
msg
.
color_range_end
>
msg
.
color_range_start
)
{
{
// before color range
// before color range
print_range_
(
formatted
,
0
,
msg
.
color_range_start
);
print_range_
(
formatted
,
0
,
msg
.
color_range_start
);
// in color range
// in color range
auto
orig_attribs
=
static_cast
<
WORD
>
(
set_foreground_color_
(
colors_
[
msg
.
level
]));
auto
orig_attribs
=
static_cast
<
WORD
>
(
set_foreground_color_
(
colors_
[
msg
.
level
]));
print_range_
(
formatted
,
msg
.
color_range_start
,
msg
.
color_range_end
);
print_range_
(
formatted
,
msg
.
color_range_start
,
msg
.
color_range_end
);
...
@@ -85,7 +74,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
...
@@ -85,7 +74,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
}
}
else
// print without colors if color range is invalid (or color is disabled)
else
// print without colors if color range is invalid (or color is disabled)
{
{
print_range_
(
formatted
,
0
,
formatted
.
size
()
);
write_to_file_
(
formatted
);
}
}
}
}
...
@@ -119,7 +108,21 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
...
@@ -119,7 +108,21 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_color_mode_impl
(
color_mode
mode
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_color_mode_impl
(
color_mode
mode
)
{
{
should_do_colors_
=
mode
!=
color_mode
::
never
;
switch
(
mode
)
{
case
color_mode
:
:
always
:
should_do_colors_
=
true
;
break
;
case
color_mode
:
:
never
:
should_do_colors_
=
false
;
break
;
default:
// should do colors only if out_handle_ points to actual console.
DWORD
console_mode
;
bool
in_console
=
::
GetConsoleMode
(
static_cast
<
HANDLE
>
(
out_handle_
),
&
console_mode
)
!=
0
;
should_do_colors_
=
in_console
;
break
;
}
}
}
// set foreground color and return the orig console attributes (for resetting later)
// set foreground color and return the orig console attributes (for resetting later)
...
...
include/spdlog/sinks/wincolor_sink.h
View file @
91046e6c
...
@@ -42,7 +42,6 @@ protected:
...
@@ -42,7 +42,6 @@ protected:
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
void
*
out_handle_
;
void
*
out_handle_
;
mutex_t
&
mutex_
;
mutex_t
&
mutex_
;
bool
in_console_
;
bool
should_do_colors_
;
bool
should_do_colors_
;
std
::
unique_ptr
<
spdlog
::
formatter
>
formatter_
;
std
::
unique_ptr
<
spdlog
::
formatter
>
formatter_
;
std
::
array
<
std
::
uint16_t
,
level
::
n_levels
>
colors_
;
std
::
array
<
std
::
uint16_t
,
level
::
n_levels
>
colors_
;
...
...
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