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
3b0e7b4d
Unverified
Commit
3b0e7b4d
authored
May 10, 2019
by
Gabi Melman
Committed by
GitHub
May 10, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1075 from psalz/add-force-color-output-option
Add option to force color output without TTY
parents
36693514
5e856c6b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
13 deletions
+55
-13
common.h
include/spdlog/common.h
+10
-0
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+18
-2
stdout_color_sinks.h
include/spdlog/sinks/stdout_color_sinks.h
+8
-8
wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+19
-3
No files found.
include/spdlog/common.h
View file @
3b0e7b4d
...
@@ -159,6 +159,16 @@ inline spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCE
...
@@ -159,6 +159,16 @@ inline spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCE
using
level_hasher
=
std
::
hash
<
int
>
;
using
level_hasher
=
std
::
hash
<
int
>
;
}
// namespace level
}
// namespace level
//
// Color mode used by sinks with color support.
//
enum
class
color_mode
{
always
,
automatic
,
never
};
//
//
// Pattern time - specific time getting to use for pattern_formatter.
// Pattern time - specific time getting to use for pattern_formatter.
// local time by default
// local time by default
...
...
include/spdlog/sinks/ansicolor_sink.h
View file @
3b0e7b4d
...
@@ -33,12 +33,12 @@ class ansicolor_sink final : public sink
...
@@ -33,12 +33,12 @@ class ansicolor_sink final : public sink
{
{
public
:
public
:
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
ansicolor_sink
()
ansicolor_sink
(
color_mode
mode
=
color_mode
::
automatic
)
:
target_file_
(
TargetStream
::
stream
())
:
target_file_
(
TargetStream
::
stream
())
,
mutex_
(
ConsoleMutex
::
mutex
())
,
mutex_
(
ConsoleMutex
::
mutex
())
{
{
s
hould_do_colors_
=
details
::
os
::
in_terminal
(
target_file_
)
&&
details
::
os
::
is_color_terminal
(
);
s
et_color_mode
(
mode
);
colors_
[
level
::
trace
]
=
white
;
colors_
[
level
::
trace
]
=
white
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
green
;
colors_
[
level
::
info
]
=
green
;
...
@@ -138,6 +138,22 @@ public:
...
@@ -138,6 +138,22 @@ public:
return
should_do_colors_
;
return
should_do_colors_
;
}
}
void
set_color_mode
(
color_mode
mode
)
{
switch
(
mode
)
{
case
color_mode
:
:
always
:
should_do_colors_
=
true
;
return
;
case
color_mode
:
:
automatic
:
should_do_colors_
=
details
::
os
::
in_terminal
(
target_file_
)
&&
details
::
os
::
is_color_terminal
();
return
;
case
color_mode
:
:
never
:
should_do_colors_
=
false
;
return
;
}
}
private
:
private
:
void
print_ccode_
(
const
std
::
string
&
color_code
)
void
print_ccode_
(
const
std
::
string
&
color_code
)
{
{
...
...
include/spdlog/sinks/stdout_color_sinks.h
View file @
3b0e7b4d
...
@@ -31,26 +31,26 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
...
@@ -31,26 +31,26 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
}
// namespace sinks
}
// namespace sinks
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
)
{
{
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_mt
>
(
logger_name
);
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_mt
>
(
logger_name
,
mode
);
}
}
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
)
{
{
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_st
>
(
logger_name
);
return
Factory
::
template
create
<
sinks
::
stdout_color_sink_st
>
(
logger_name
,
mode
);
}
}
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
)
{
{
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_mt
>
(
logger_name
);
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_mt
>
(
logger_name
,
mode
);
}
}
template
<
typename
Factory
=
default_factory
>
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
)
{
{
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_st
>
(
logger_name
);
return
Factory
::
template
create
<
sinks
::
stderr_color_sink_st
>
(
logger_name
,
mode
);
}
}
}
// namespace spdlog
}
// namespace spdlog
include/spdlog/sinks/wincolor_sink.h
View file @
3b0e7b4d
...
@@ -37,10 +37,11 @@ public:
...
@@ -37,10 +37,11 @@ public:
const
WORD
WHITE
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
WHITE
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
wincolor_sink
()
wincolor_sink
(
color_mode
mode
=
color_mode
::
automatic
)
:
out_handle_
(
OutHandle
::
handle
())
:
out_handle_
(
OutHandle
::
handle
())
,
mutex_
(
ConsoleMutex
::
mutex
())
,
mutex_
(
ConsoleMutex
::
mutex
())
{
{
set_color_mode
(
mode
);
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
debug
]
=
CYAN
;
colors_
[
level
::
debug
]
=
CYAN
;
colors_
[
level
::
info
]
=
GREEN
;
colors_
[
level
::
info
]
=
GREEN
;
...
@@ -70,7 +71,7 @@ public:
...
@@ -70,7 +71,7 @@ public:
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
);
if
(
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
);
...
@@ -83,7 +84,7 @@ public:
...
@@ -83,7 +84,7 @@ public:
// after color range
// after color range
print_range_
(
formatted
,
msg
.
color_range_end
,
formatted
.
size
());
print_range_
(
formatted
,
msg
.
color_range_end
,
formatted
.
size
());
}
}
else
// print without colors if color range is invalid
else
// print without colors if color range is invalid
(or color is disabled)
{
{
print_range_
(
formatted
,
0
,
formatted
.
size
());
print_range_
(
formatted
,
0
,
formatted
.
size
());
}
}
...
@@ -106,6 +107,20 @@ public:
...
@@ -106,6 +107,20 @@ public:
formatter_
=
std
::
move
(
sink_formatter
);
formatter_
=
std
::
move
(
sink_formatter
);
}
}
void
set_color_mode
(
color_mode
mode
)
{
switch
(
mode
)
{
case
color_mode
:
:
always
:
case
color_mode
:
:
automatic
:
should_do_colors_
=
true
;
return
;
case
color_mode
:
:
never
:
should_do_colors_
=
false
;
return
;
}
}
private
:
private
:
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
// set color and return the orig console attributes (for resetting later)
// set color and return the orig console attributes (for resetting later)
...
@@ -130,6 +145,7 @@ private:
...
@@ -130,6 +145,7 @@ private:
HANDLE
out_handle_
;
HANDLE
out_handle_
;
mutex_t
&
mutex_
;
mutex_t
&
mutex_
;
bool
should_do_colors_
;
std
::
unordered_map
<
level
::
level_enum
,
WORD
,
level
::
level_hasher
>
colors_
;
std
::
unordered_map
<
level
::
level_enum
,
WORD
,
level
::
level_hasher
>
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