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
05cac05c
Commit
05cac05c
authored
Jul 14, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang_format
parent
724713ac
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
165 additions
and
169 deletions
+165
-169
include/spdlog/sinks/wincolor_sink-inl.h
include/spdlog/sinks/wincolor_sink-inl.h
+161
-164
include/spdlog/sinks/wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+4
-5
No files found.
include/spdlog/sinks/wincolor_sink-inl.h
View file @
05cac05c
...
@@ -11,14 +11,14 @@
...
@@ -11,14 +11,14 @@
#include "spdlog/details/pattern_formatter.h"
#include "spdlog/details/pattern_formatter.h"
namespace
spdlog
{
namespace
spdlog
{
namespace
sinks
{
namespace
sinks
{
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
wincolor_sink
(
HANDLE
out_handle
,
color_mode
mode
)
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
wincolor_sink
(
HANDLE
out_handle
,
color_mode
mode
)
:
out_handle_
(
out_handle
)
:
out_handle_
(
out_handle
)
,
mutex_
(
ConsoleMutex
::
mutex
())
,
mutex_
(
ConsoleMutex
::
mutex
())
,
formatter_
(
details
::
make_unique
<
spdlog
::
pattern_formatter
>
())
,
formatter_
(
details
::
make_unique
<
spdlog
::
pattern_formatter
>
())
{
{
// check if out_handle is points to the actual console.
// check if out_handle is points to the actual console.
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
// ::GetConsoleMode() should return 0 if it is redirected or not valid console handle.
DWORD
console_mode
;
DWORD
console_mode
;
...
@@ -31,25 +31,25 @@ namespace spdlog {
...
@@ -31,25 +31,25 @@ namespace spdlog {
colors_
[
level
::
err
]
=
RED
|
BOLD
;
// red bold
colors_
[
level
::
err
]
=
RED
|
BOLD
;
// red bold
colors_
[
level
::
critical
]
=
BACKGROUND_RED
|
WHITE
|
BOLD
;
// white bold on red background
colors_
[
level
::
critical
]
=
BACKGROUND_RED
|
WHITE
|
BOLD
;
// white bold on red background
colors_
[
level
::
off
]
=
0
;
colors_
[
level
::
off
]
=
0
;
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::~
wincolor_sink
()
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::~
wincolor_sink
()
{
{
this
->
flush
();
this
->
flush
();
}
}
// change the color for the given level
// change the color for the given level
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_color
(
level
::
level_enum
level
,
WORD
color
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_color
(
level
::
level_enum
level
,
WORD
color
)
{
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
colors_
[
level
]
=
color
;
colors_
[
level
]
=
color
;
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
log
(
const
details
::
log_msg
&
msg
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
log
(
const
details
::
log_msg
&
msg
)
{
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fmt
::
memory_buffer
formatted
;
fmt
::
memory_buffer
formatted
;
formatter_
->
format
(
msg
,
formatted
);
formatter_
->
format
(
msg
,
formatted
);
...
@@ -76,32 +76,31 @@ namespace spdlog {
...
@@ -76,32 +76,31 @@ namespace spdlog {
{
{
print_range_
(
formatted
,
0
,
formatted
.
size
());
print_range_
(
formatted
,
0
,
formatted
.
size
());
}
}
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
flush
()
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
flush
()
{
{
// windows console always flushed?
// windows console always flushed?
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_pattern
(
const
std
::
string
&
pattern
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_pattern
(
const
std
::
string
&
pattern
)
{
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
formatter_
=
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
));
formatter_
=
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
));
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
{
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
formatter_
=
std
::
move
(
sink_formatter
);
formatter_
=
std
::
move
(
sink_formatter
);
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_color_mode
(
color_mode
mode
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_color_mode
(
color_mode
mode
)
{
{
switch
(
mode
)
switch
(
mode
)
{
{
case
color_mode
:
:
always
:
case
color_mode
:
:
always
:
...
@@ -114,14 +113,13 @@ namespace spdlog {
...
@@ -114,14 +113,13 @@ namespace spdlog {
default:
default:
should_do_colors_
=
true
;
should_do_colors_
=
true
;
}
}
}
}
// set color and return the orig console attributes (for resetting later)
// set color and return the orig console attributes (for resetting later)
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
WORD
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_console_attribs
(
WORD
attribs
)
WORD
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_console_attribs
(
WORD
attribs
)
{
{
in_console_
in_console_
CONSOLE_SCREEN_BUFFER_INFO
orig_buffer_info
;
CONSOLE_SCREEN_BUFFER_INFO
orig_buffer_info
;
::
GetConsoleScreenBufferInfo
(
out_handle_
,
&
orig_buffer_info
);
::
GetConsoleScreenBufferInfo
(
out_handle_
,
&
orig_buffer_info
);
WORD
back_color
=
orig_buffer_info
.
wAttributes
;
WORD
back_color
=
orig_buffer_info
.
wAttributes
;
// retrieve the current background color
// retrieve the current background color
...
@@ -129,20 +127,19 @@ namespace spdlog {
...
@@ -129,20 +127,19 @@ namespace spdlog {
// keep the background color unchanged
// keep the background color unchanged
::
SetConsoleTextAttribute
(
out_handle_
,
attribs
|
back_color
);
::
SetConsoleTextAttribute
(
out_handle_
,
attribs
|
back_color
);
return
orig_buffer_info
.
wAttributes
;
// return orig attribs
return
orig_buffer_info
.
wAttributes
;
// return orig attribs
}
}
// print a range of formatted message to console
// print a range of formatted message to console
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
)
{
{
auto
size
=
static_cast
<
DWORD
>
(
end
-
start
);
auto
size
=
static_cast
<
DWORD
>
(
end
-
start
);
::
WriteConsoleA
(
out_handle_
,
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
::
WriteConsoleA
(
out_handle_
,
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
}
}
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
write_to_file_
(
const
fmt
::
memory_buffer
&
formatted
)
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
write_to_file_
(
const
fmt
::
memory_buffer
&
formatted
)
{
{
auto
size
=
static_cast
<
DWORD
>
(
formatted
.
size
());
auto
size
=
static_cast
<
DWORD
>
(
formatted
.
size
());
if
(
size
==
0
)
if
(
size
==
0
)
{
{
...
@@ -160,19 +157,19 @@ namespace spdlog {
...
@@ -160,19 +157,19 @@ namespace spdlog {
}
}
total_written
+=
bytes_written
;
total_written
+=
bytes_written
;
}
while
(
total_written
<
size
);
}
while
(
total_written
<
size
);
}
}
// wincolor_stdout_sink
// wincolor_stdout_sink
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
wincolor_stdout_sink
<
ConsoleMutex
>::
wincolor_stdout_sink
(
color_mode
mode
)
SPDLOG_INLINE
wincolor_stdout_sink
<
ConsoleMutex
>::
wincolor_stdout_sink
(
color_mode
mode
)
:
wincolor_sink
<
ConsoleMutex
>
(
::
GetStdHandle
(
STD_OUTPUT_HANDLE
),
mode
)
:
wincolor_sink
<
ConsoleMutex
>
(
::
GetStdHandle
(
STD_OUTPUT_HANDLE
),
mode
)
{}
{}
// wincolor_stderr_sink
// wincolor_stderr_sink
template
<
typename
ConsoleMutex
>
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
wincolor_stderr_sink
<
ConsoleMutex
>::
wincolor_stderr_sink
(
color_mode
mode
)
SPDLOG_INLINE
wincolor_stderr_sink
<
ConsoleMutex
>::
wincolor_stderr_sink
(
color_mode
mode
)
:
wincolor_sink
<
ConsoleMutex
>
(
::
GetStdHandle
(
STD_ERROR_HANDLE
),
mode
)
:
wincolor_sink
<
ConsoleMutex
>
(
::
GetStdHandle
(
STD_ERROR_HANDLE
),
mode
)
{}
{}
}
// namespace sinks
}
// namespace sinks
}
// namespace spdlog
}
// namespace spdlog
\ No newline at end of file
include/spdlog/sinks/wincolor_sink.h
View file @
05cac05c
...
@@ -59,9 +59,8 @@ protected:
...
@@ -59,9 +59,8 @@ protected:
// print a range of formatted message to console
// print a range of formatted message to console
void
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
);
void
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
);
//
in case we are redirected to file (not in console mode)
//
in case we are redirected to file (not in console mode)
void
write_to_file_
(
const
fmt
::
memory_buffer
&
formatted
);
void
write_to_file_
(
const
fmt
::
memory_buffer
&
formatted
);
};
};
template
<
typename
ConsoleMutex
>
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