Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
f0fcc73f
Commit
f0fcc73f
authored
Jun 18, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor improvments to ansicolor sink
parent
a340b381
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
36 deletions
+44
-36
ansicolor_sink-inl.h
include/spdlog/sinks/ansicolor_sink-inl.h
+6
-6
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+38
-30
No files found.
include/spdlog/sinks/ansicolor_sink-inl.h
View file @
f0fcc73f
...
...
@@ -22,14 +22,14 @@ SPDLOG_INLINE ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, co
colors_
[
level
::
trace
]
=
white
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
green
;
colors_
[
level
::
warn
]
=
yellow
+
bold
;
colors_
[
level
::
err
]
=
red
+
bold
;
colors_
[
level
::
critical
]
=
bold
+
on_red
;
colors_
[
level
::
warn
]
=
yellow
_
bold
;
colors_
[
level
::
err
]
=
red
_
bold
;
colors_
[
level
::
critical
]
=
bold
_
on_red
;
colors_
[
level
::
off
]
=
reset
;
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
ansicolor_sink
<
ConsoleMutex
>::
set_color
(
level
::
level_enum
color_level
,
const
std
::
string
&
color
)
SPDLOG_INLINE
void
ansicolor_sink
<
ConsoleMutex
>::
set_color
(
level
::
level_enum
color_level
,
string_view_t
color
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
colors_
[
color_level
]
=
color
;
...
...
@@ -107,9 +107,9 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
ansicolor_sink
<
ConsoleMutex
>::
print_ccode_
(
const
st
d
::
string
&
color_code
)
SPDLOG_INLINE
void
ansicolor_sink
<
ConsoleMutex
>::
print_ccode_
(
const
st
ring_view_t
&
color_code
)
{
fwrite
(
color_code
.
data
(),
sizeof
(
char
),
color_code
.
size
(),
target_file_
);
fwrite
(
color_code
.
data
(),
sizeof
(
string_view_t
::
char_type
),
color_code
.
size
(),
target_file_
);
}
template
<
typename
ConsoleMutex
>
...
...
include/spdlog/sinks/ansicolor_sink.h
View file @
f0fcc73f
...
...
@@ -20,6 +20,7 @@ namespace sinks {
* of the message.
* If no color terminal detected, omit the escape codes.
*/
template
<
typename
ConsoleMutex
>
class
ansicolor_sink
:
public
sink
{
...
...
@@ -30,50 +31,57 @@ public:
ansicolor_sink
(
const
ansicolor_sink
&
other
)
=
delete
;
ansicolor_sink
&
operator
=
(
const
ansicolor_sink
&
other
)
=
delete
;
void
set_color
(
level
::
level_enum
color_level
,
const
std
::
string
&
color
);
void
set_color
(
level
::
level_enum
color_level
,
string_view_t
color
);
void
set_color_mode
(
color_mode
mode
);
bool
should_color
();
void
log
(
const
details
::
log_msg
&
msg
)
override
;
void
flush
()
override
;
void
set_pattern
(
const
std
::
string
&
pattern
)
final
;
void
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
override
;
bool
should_color
();
void
set_color_mode
(
color_mode
mode
);
/// Formatting codes
const
std
::
string
reset
=
"
\033
[m"
;
const
std
::
string
bold
=
"
\033
[1m"
;
const
std
::
string
dark
=
"
\033
[2m"
;
const
std
::
string
underline
=
"
\033
[4m"
;
const
std
::
string
blink
=
"
\033
[5m"
;
const
std
::
string
reverse
=
"
\033
[7m"
;
const
std
::
string
concealed
=
"
\033
[8m"
;
const
std
::
string
clear_line
=
"
\033
[K"
;
// Formatting codes
const
string_view_t
reset
=
"
\033
[m"
;
const
string_view_t
bold
=
"
\033
[1m"
;
const
string_view_t
dark
=
"
\033
[2m"
;
const
string_view_t
underline
=
"
\033
[4m"
;
const
string_view_t
blink
=
"
\033
[5m"
;
const
string_view_t
reverse
=
"
\033
[7m"
;
const
string_view_t
concealed
=
"
\033
[8m"
;
const
string_view_t
clear_line
=
"
\033
[K"
;
// Foreground colors
const
st
d
::
string
black
=
"
\033
[30m"
;
const
st
d
::
string
red
=
"
\033
[31m"
;
const
st
d
::
string
green
=
"
\033
[32m"
;
const
st
d
::
string
yellow
=
"
\033
[33m"
;
const
st
d
::
string
blue
=
"
\033
[34m"
;
const
st
d
::
string
magenta
=
"
\033
[35m"
;
const
st
d
::
string
cyan
=
"
\033
[36m"
;
const
st
d
::
string
white
=
"
\033
[37m"
;
const
st
ring_view_t
black
=
"
\033
[30m"
;
const
st
ring_view_t
red
=
"
\033
[31m"
;
const
st
ring_view_t
green
=
"
\033
[32m"
;
const
st
ring_view_t
yellow
=
"
\033
[33m"
;
const
st
ring_view_t
blue
=
"
\033
[34m"
;
const
st
ring_view_t
magenta
=
"
\033
[35m"
;
const
st
ring_view_t
cyan
=
"
\033
[36m"
;
const
st
ring_view_t
white
=
"
\033
[37m"
;
/// Background colors
const
std
::
string
on_black
=
"
\033
[40m"
;
const
std
::
string
on_red
=
"
\033
[41m"
;
const
std
::
string
on_green
=
"
\033
[42m"
;
const
std
::
string
on_yellow
=
"
\033
[43m"
;
const
std
::
string
on_blue
=
"
\033
[44m"
;
const
std
::
string
on_magenta
=
"
\033
[45m"
;
const
std
::
string
on_cyan
=
"
\033
[46m"
;
const
std
::
string
on_white
=
"
\033
[47m"
;
const
string_view_t
on_black
=
"
\033
[40m"
;
const
string_view_t
on_red
=
"
\033
[41m"
;
const
string_view_t
on_green
=
"
\033
[42m"
;
const
string_view_t
on_yellow
=
"
\033
[43m"
;
const
string_view_t
on_blue
=
"
\033
[44m"
;
const
string_view_t
on_magenta
=
"
\033
[45m"
;
const
string_view_t
on_cyan
=
"
\033
[46m"
;
const
string_view_t
on_white
=
"
\033
[47m"
;
/// Bold colors
const
string_view_t
yellow_bold
=
"
\033
[33m
\033
[1m"
;
const
string_view_t
red_bold
=
"
\033
[31m
\033
[1m"
;
const
string_view_t
bold_on_red
=
"
\033
[1m
\033
[31m"
;
private
:
FILE
*
target_file_
;
mutex_t
&
mutex_
;
bool
should_do_colors_
;
std
::
unordered_map
<
level
::
level_enum
,
st
d
::
string
,
level
::
level_hasher
>
colors_
;
void
print_ccode_
(
const
st
d
::
string
&
color_code
);
std
::
unordered_map
<
level
::
level_enum
,
st
ring_view_t
,
level
::
level_hasher
>
colors_
;
void
print_ccode_
(
const
st
ring_view_t
&
color_code
);
void
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
);
};
...
...
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