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
7a3a560c
Commit
7a3a560c
authored
May 24, 2019
by
gabime
Browse files
Options
Browse Files
Download
Plain Diff
Merge v1.x
parents
2963da13
74dbf4cf
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
34 deletions
+80
-34
common.h
include/spdlog/common.h
+10
-0
ansicolor_sink-inl.h
include/spdlog/sinks/ansicolor_sink-inl.h
+19
-2
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+3
-3
stdout_color_sinks-inl.h
include/spdlog/sinks/stdout_color_sinks-inl.h
+9
-8
stdout_color_sinks.h
include/spdlog/sinks/stdout_color_sinks.h
+5
-6
wincolor_sink-inl.h
include/spdlog/sinks/wincolor_sink-inl.h
+21
-3
wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+4
-3
spdlog.cpp
src/spdlog.cpp
+9
-9
No files found.
include/spdlog/common.h
View file @
7a3a560c
...
...
@@ -156,6 +156,16 @@ spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT;
using
level_hasher
=
std
::
hash
<
int
>
;
}
// 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.
// local time by default
...
...
include/spdlog/sinks/ansicolor_sink-inl.h
View file @
7a3a560c
...
...
@@ -10,12 +10,12 @@
#include "spdlog/details/os.h"
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
SPDLOG_INLINE
spdlog
::
sinks
::
ansicolor_sink
<
TargetStream
,
ConsoleMutex
>::
ansicolor_sink
()
SPDLOG_INLINE
spdlog
::
sinks
::
ansicolor_sink
<
TargetStream
,
ConsoleMutex
>::
ansicolor_sink
(
color_mode
mode
)
:
target_file_
(
TargetStream
::
stream
())
,
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
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
green
;
...
...
@@ -88,6 +88,23 @@ SPDLOG_INLINE bool spdlog::sinks::ansicolor_sink<TargetStream, ConsoleMutex>::sh
return
should_do_colors_
;
}
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
SPDLOG_INLINE
void
spdlog
::
sinks
::
ansicolor_sink
<
TargetStream
,
ConsoleMutex
>::
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
;
}
}
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
SPDLOG_INLINE
void
spdlog
::
sinks
::
ansicolor_sink
<
TargetStream
,
ConsoleMutex
>::
print_ccode_
(
const
std
::
string
&
color_code
)
{
...
...
include/spdlog/sinks/ansicolor_sink.h
View file @
7a3a560c
...
...
@@ -29,7 +29,7 @@ class ansicolor_sink final : public sink
{
public
:
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
ansicolor_sink
();
ansicolor_sink
(
color_mode
mode
=
color_mode
::
automatic
);
~
ansicolor_sink
()
override
=
default
;
ansicolor_sink
(
const
ansicolor_sink
&
other
)
=
delete
;
...
...
@@ -40,6 +40,7 @@ public:
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"
;
...
...
@@ -91,4 +92,4 @@ using ansicolor_stderr_sink_st = ansicolor_sink<details::console_stderr, details
#ifdef SPDLOG_HEADER_ONLY
#include "ansicolor_sink-inl.h"
#endif
\ No newline at end of file
#endif
include/spdlog/sinks/stdout_color_sinks-inl.h
View file @
7a3a560c
...
...
@@ -13,26 +13,26 @@
namespace
spdlog
{
template
<
typename
Factory
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
,
color_mode
mode
)
{
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
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
,
color_mode
mode
)
{
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
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
,
color_mode
mode
)
{
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
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
,
color_mode
mode
)
{
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
\ No newline at end of file
include/spdlog/sinks/stdout_color_sinks.h
View file @
7a3a560c
...
...
@@ -29,19 +29,19 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
}
// namespace sinks
template
<
typename
Factory
=
default_factory
>
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
);
template
<
typename
Factory
=
default_factory
>
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
);
template
<
typename
Factory
=
default_factory
>
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
);
template
<
typename
Factory
=
default_factory
>
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
);
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
,
color_mode
mode
=
color_mode
::
automatic
);
}
// namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "stdout_color_sinks-inl.h"
#endif
\ No newline at end of file
#endif
include/spdlog/sinks/wincolor_sink-inl.h
View file @
7a3a560c
...
...
@@ -13,10 +13,11 @@ namespace spdlog {
namespace
sinks
{
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
SPDLOG_INLINE
wincolor_sink
<
TargetStream
,
ConsoleMutex
>::
wincolor_sink
()
SPDLOG_INLINE
wincolor_sink
<
TargetStream
,
ConsoleMutex
>::
wincolor_sink
(
color_mode
mode
)
:
out_handle_
(
TargetStream
::
handle
())
,
mutex_
(
ConsoleMutex
::
mutex
())
{
set_color_mode
(
mode
);
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
debug
]
=
CYAN
;
colors_
[
level
::
info
]
=
GREEN
;
...
...
@@ -46,7 +47,7 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::log(const details:
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fmt
::
memory_buffer
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
print_range_
(
formatted
,
0
,
msg
.
color_range_start
);
...
...
@@ -59,7 +60,7 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::log(const details:
// after color range
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
());
}
...
...
@@ -85,6 +86,23 @@ void SPDLOG_INLINE wincolor_sink<TargetStream, ConsoleMutex>::set_formatter(std:
formatter_
=
std
::
move
(
sink_formatter
);
}
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
void
SPDLOG_INLINE
wincolor_sink
<
TargetStream
,
ConsoleMutex
>::
set_color_mode
(
color_mode
mode
)
{
switch
(
mode
)
{
case
color_mode
:
:
always
:
case
color_mode
:
:
automatic
:
should_do_colors_
=
true
;
break
;
case
color_mode
:
:
never
:
should_do_colors_
=
false
;
break
;
default
:
should_do_colors_
=
true
;
}
}
// set color and return the orig console attributes (for resetting later)
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
WORD
SPDLOG_INLINE
wincolor_sink
<
TargetStream
,
ConsoleMutex
>::
set_console_attribs
(
WORD
attribs
)
...
...
include/spdlog/sinks/wincolor_sink.h
View file @
7a3a560c
...
...
@@ -35,7 +35,7 @@ public:
const
WORD
WHITE
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
wincolor_sink
();
wincolor_sink
(
color_mode
mode
=
color_mode
::
automatic
);
~
wincolor_sink
()
override
;
wincolor_sink
(
const
wincolor_sink
&
other
)
=
delete
;
...
...
@@ -47,11 +47,13 @@ public:
void
flush
()
final
override
;
void
set_pattern
(
const
std
::
string
&
pattern
)
override
final
;
void
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
override
final
;
void
set_color_mode
(
color_mode
mode
);
private
:
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
HANDLE
out_handle_
;
mutex_t
&
mutex_
;
bool
should_do_colors_
;
std
::
unordered_map
<
level
::
level_enum
,
WORD
,
level
::
level_hasher
>
colors_
;
// set color and return the orig console attributes (for resetting later)
...
...
@@ -71,4 +73,4 @@ using wincolor_stderr_sink_st = wincolor_sink<details::console_stderr, details::
#ifdef SPDLOG_HEADER_ONLY
#include "wincolor_sink-inl.h"
#endif
\ No newline at end of file
#endif
src/spdlog.cpp
View file @
7a3a560c
...
...
@@ -58,15 +58,15 @@ template class spdlog::sinks::ansicolor_sink<spdlog::details::console_stderr, sp
#endif
#include "spdlog/sinks/stdout_color_sinks-inl.h"
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_st
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_st
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_st
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_st
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
// Slightly modified version of fmt lib's format.cc source file.
// Copyright (c) 2012 - 2016, Victor Zverovich
...
...
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