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
f5492aed
Commit
f5492aed
authored
Aug 28, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unified usage of fmt::memory_buffer across the codebase
parent
c2efd6ee
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
77 additions
and
80 deletions
+77
-80
common-inl.h
include/spdlog/common-inl.h
+1
-1
common.h
include/spdlog/common.h
+2
-0
file_helper-inl.h
include/spdlog/details/file_helper-inl.h
+1
-1
file_helper.h
include/spdlog/details/file_helper.h
+1
-1
fmt_helper.h
include/spdlog/details/fmt_helper.h
+14
-22
log_msg_buffer.h
include/spdlog/details/log_msg_buffer.h
+1
-1
os-inl.h
include/spdlog/details/os-inl.h
+2
-2
os.h
include/spdlog/details/os.h
+1
-1
pattern_formatter-inl.h
include/spdlog/details/pattern_formatter-inl.h
+0
-0
pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+2
-2
formatter.h
include/spdlog/formatter.h
+1
-1
logger.h
include/spdlog/logger.h
+3
-3
android_sink.h
include/spdlog/sinks/android_sink.h
+1
-1
ansicolor_sink-inl.h
include/spdlog/sinks/ansicolor_sink-inl.h
+2
-2
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+1
-1
basic_file_sink-inl.h
include/spdlog/sinks/basic_file_sink-inl.h
+1
-1
daily_file_sink.h
include/spdlog/sinks/daily_file_sink.h
+2
-2
dup_filter_sink.h
include/spdlog/sinks/dup_filter_sink.h
+1
-1
msvc_sink.h
include/spdlog/sinks/msvc_sink.h
+1
-1
ostream_sink.h
include/spdlog/sinks/ostream_sink.h
+1
-1
rotating_file_sink-inl.h
include/spdlog/sinks/rotating_file_sink-inl.h
+2
-2
stdout_sinks-inl.h
include/spdlog/sinks/stdout_sinks-inl.h
+1
-1
syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+1
-1
wincolor_sink-inl.h
include/spdlog/sinks/wincolor_sink-inl.h
+3
-3
wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+2
-2
test_file_helper.cpp
tests/test_file_helper.cpp
+1
-1
test_fmt_helper.cpp
tests/test_fmt_helper.cpp
+6
-4
test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+21
-20
test_sink.h
tests/test_sink.h
+1
-1
No files found.
include/spdlog/common-inl.h
View file @
f5492aed
...
...
@@ -44,7 +44,7 @@ SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
SPDLOG_INLINE
spdlog_ex
::
spdlog_ex
(
const
std
::
string
&
msg
,
int
last_errno
)
{
fmt
::
memory_buffer
outbuf
;
memory_buf_t
outbuf
;
fmt
::
format_system_error
(
outbuf
,
last_errno
,
msg
);
msg_
=
fmt
::
to_string
(
outbuf
);
}
...
...
include/spdlog/common.h
View file @
f5492aed
...
...
@@ -105,6 +105,8 @@ using basic_string_view_t = fmt::basic_string_view<T>;
using
string_view_t
=
basic_string_view_t
<
char
>
;
using
memory_buf_t
=
fmt
::
basic_memory_buffer
<
char
,
250
>
;
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
#ifndef _WIN32
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
...
...
include/spdlog/details/file_helper-inl.h
View file @
f5492aed
...
...
@@ -66,7 +66,7 @@ SPDLOG_INLINE void file_helper::close()
}
}
SPDLOG_INLINE
void
file_helper
::
write
(
const
fmt
::
memory_buffer
&
buf
)
SPDLOG_INLINE
void
file_helper
::
write
(
const
memory_buf_t
&
buf
)
{
size_t
msg_size
=
buf
.
size
();
auto
data
=
buf
.
data
();
...
...
include/spdlog/details/file_helper.h
View file @
f5492aed
...
...
@@ -26,7 +26,7 @@ public:
void
reopen
(
bool
truncate
);
void
flush
();
void
close
();
void
write
(
const
fmt
::
memory_buffer
&
buf
);
void
write
(
const
memory_buf_t
&
buf
);
size_t
size
()
const
;
const
filename_t
&
filename
()
const
;
static
bool
file_exists
(
const
filename_t
&
fname
);
...
...
include/spdlog/details/fmt_helper.h
View file @
f5492aed
...
...
@@ -12,21 +12,14 @@ namespace spdlog {
namespace
details
{
namespace
fmt_helper
{
template
<
size_t
Buffer_Size
>
inline
spdlog
::
string_view_t
to_string_view
(
const
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
buf
)
SPDLOG_NOEXCEPT
inline
spdlog
::
string_view_t
to_string_view
(
const
memory_buf_t
&
buf
)
SPDLOG_NOEXCEPT
{
return
spdlog
::
string_view_t
(
buf
.
data
(),
buf
.
size
());
}
template
<
size_t
Buffer_Size1
,
size_t
Buffer_Size2
>
inline
void
append_buf
(
const
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size1
>
&
buf
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size2
>
&
dest
)
{
auto
*
buf_ptr
=
buf
.
data
();
dest
.
append
(
buf_ptr
,
buf_ptr
+
buf
.
size
());
}
template
<
size_t
Buffer_Size
>
inline
void
append_string_view
(
spdlog
::
string_view_t
view
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
append_string_view
(
spdlog
::
string_view_t
view
,
memory_buf_t
&
dest
)
{
auto
*
buf_ptr
=
view
.
data
();
if
(
buf_ptr
!=
nullptr
)
...
...
@@ -35,8 +28,8 @@ inline void append_string_view(spdlog::string_view_t view, fmt::basic_memory_buf
}
}
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
append_int
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
>
inline
void
append_int
(
T
n
,
memory_buf_t
&
dest
)
{
fmt
::
format_int
i
(
n
);
dest
.
append
(
i
.
data
(),
i
.
data
()
+
i
.
size
());
...
...
@@ -49,8 +42,7 @@ inline unsigned count_digits(T n)
return
static_cast
<
unsigned
>
(
fmt
::
internal
::
count_digits
(
static_cast
<
count_type
>
(
n
)));
}
template
<
size_t
Buffer_Size
>
inline
void
pad2
(
int
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
inline
void
pad2
(
int
n
,
memory_buf_t
&
dest
)
{
if
(
n
>
99
)
{
...
...
@@ -72,8 +64,8 @@ inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
}
}
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad_uint
(
T
n
,
unsigned
int
width
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
>
inline
void
pad_uint
(
T
n
,
unsigned
int
width
,
memory_buf_t
&
dest
)
{
static_assert
(
std
::
is_unsigned
<
T
>::
value
,
"pad_uint must get unsigned T"
);
auto
digits
=
count_digits
(
n
);
...
...
@@ -85,20 +77,20 @@ inline void pad_uint(T n, unsigned int width, fmt::basic_memory_buffer<char, Buf
append_int
(
n
,
dest
);
}
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad3
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
>
inline
void
pad3
(
T
n
,
memory_buf_t
&
dest
)
{
pad_uint
(
n
,
3
,
dest
);
}
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad6
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
>
inline
void
pad6
(
T
n
,
memory_buf_t
&
dest
)
{
pad_uint
(
n
,
6
,
dest
);
}
template
<
typename
T
,
size_t
Buffer_Size
>
inline
void
pad9
(
T
n
,
fmt
::
basic_memory_buffer
<
char
,
Buffer_Size
>
&
dest
)
template
<
typename
T
>
inline
void
pad9
(
T
n
,
memory_buf_t
&
dest
)
{
pad_uint
(
n
,
9
,
dest
);
}
...
...
include/spdlog/details/log_msg_buffer.h
View file @
f5492aed
...
...
@@ -14,7 +14,7 @@ namespace details {
class
log_msg_buffer
:
public
log_msg
{
fmt
::
basic_memory_buffer
<
char
,
250
>
buffer
;
memory_buf_t
buffer
;
void
update_string_views
()
{
logger_name
=
string_view_t
{
buffer
.
data
(),
logger_name
.
size
()};
...
...
include/spdlog/details/os-inl.h
View file @
f5492aed
...
...
@@ -350,7 +350,7 @@ SPDLOG_INLINE void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
SPDLOG_INLINE
std
::
string
filename_to_str
(
const
filename_t
&
filename
)
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
wstr_to_utf8buf
(
filename
,
buf
);
return
fmt
::
to_string
(
buf
);
}
...
...
@@ -406,7 +406,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
}
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
SPDLOG_INLINE
void
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
wstr
,
fmt
::
memory_buffer
&
target
)
SPDLOG_INLINE
void
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
wstr
,
memory_buf_t
&
target
)
{
if
(
wstr
.
size
()
>
static_cast
<
size_t
>
(
std
::
numeric_limits
<
int
>::
max
()))
{
...
...
include/spdlog/details/os.h
View file @
f5492aed
...
...
@@ -81,7 +81,7 @@ bool is_color_terminal() SPDLOG_NOEXCEPT;
bool
in_terminal
(
FILE
*
file
)
SPDLOG_NOEXCEPT
;
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
void
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
wstr
,
fmt
::
memory_buffer
&
target
);
void
wstr_to_utf8buf
(
basic_string_view_t
<
wchar_t
>
wstr
,
memory_buf_t
&
target
);
#endif
}
// namespace os
...
...
include/spdlog/details/pattern_formatter-inl.h
View file @
f5492aed
This diff is collapsed.
Click to expand it.
include/spdlog/details/pattern_formatter.h
View file @
f5492aed
...
...
@@ -50,7 +50,7 @@ public:
{}
flag_formatter
()
=
default
;
virtual
~
flag_formatter
()
=
default
;
virtual
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
=
0
;
virtual
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
,
memory_buf_t
&
dest
)
=
0
;
protected
:
padding_info
padinfo_
;
...
...
@@ -71,7 +71,7 @@ public:
pattern_formatter
&
operator
=
(
const
pattern_formatter
&
other
)
=
delete
;
std
::
unique_ptr
<
formatter
>
clone
()
const
override
;
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
override
;
void
format
(
const
details
::
log_msg
&
msg
,
memory_buf_t
&
dest
)
override
;
private
:
std
::
string
pattern_
;
...
...
include/spdlog/formatter.h
View file @
f5492aed
...
...
@@ -12,7 +12,7 @@ class formatter
{
public
:
virtual
~
formatter
()
=
default
;
virtual
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
=
0
;
virtual
void
format
(
const
details
::
log_msg
&
msg
,
memory_buf_t
&
dest
)
=
0
;
virtual
std
::
unique_ptr
<
formatter
>
clone
()
const
=
0
;
};
}
// namespace spdlog
include/spdlog/logger.h
View file @
f5492aed
...
...
@@ -87,7 +87,7 @@ public:
}
SPDLOG_TRY
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
fmt
::
format_to
(
buf
,
fmt
,
args
...);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
if
(
level_enabled
)
...
...
@@ -243,7 +243,7 @@ public:
fmt
::
wmemory_buffer
wbuf
;
fmt
::
format_to
(
wbuf
,
fmt
,
args
...);
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
details
::
os
::
wstr_to_utf8buf
(
wstring_view_t
(
wbuf
.
data
(),
wbuf
.
size
()),
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
...
...
@@ -312,7 +312,7 @@ public:
try
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
details
::
os
::
wstr_to_utf8buf
(
msg
,
buf
);
details
::
log_msg
log_msg
(
loc
,
name_
,
lvl
,
string_view_t
(
buf
.
data
(),
buf
.
size
()));
...
...
include/spdlog/sinks/android_sink.h
View file @
f5492aed
...
...
@@ -40,7 +40,7 @@ protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
const
android_LogPriority
priority
=
convert_to_android_
(
msg
.
level
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
if
(
use_raw_msg_
)
{
details
::
fmt_helper
::
append_string_view
(
msg
.
payload
,
formatted
);
...
...
include/spdlog/sinks/ansicolor_sink-inl.h
View file @
f5492aed
...
...
@@ -44,7 +44,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg
// If color is not supported in the terminal, log as is instead.
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter_
->
format
(
msg
,
formatted
);
if
(
should_do_colors_
&&
msg
.
color_range_end
>
msg
.
color_range_start
)
{
...
...
@@ -115,7 +115,7 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
ansicolor_sink
<
ConsoleMutex
>::
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
)
SPDLOG_INLINE
void
ansicolor_sink
<
ConsoleMutex
>::
print_range_
(
const
memory_buf_t
&
formatted
,
size_t
start
,
size_t
end
)
{
fwrite
(
formatted
.
data
()
+
start
,
sizeof
(
char
),
end
-
start
,
target_file_
);
}
...
...
include/spdlog/sinks/ansicolor_sink.h
View file @
f5492aed
...
...
@@ -82,7 +82,7 @@ private:
std
::
unique_ptr
<
spdlog
::
formatter
>
formatter_
;
std
::
unordered_map
<
level
::
level_enum
,
string_view_t
,
level
::
level_hasher
>
colors_
;
void
print_ccode_
(
const
string_view_t
&
color_code
);
void
print_range_
(
const
fmt
::
memory_buffer
&
formatted
,
size_t
start
,
size_t
end
);
void
print_range_
(
const
memory_buf_t
&
formatted
,
size_t
start
,
size_t
end
);
};
template
<
typename
ConsoleMutex
>
...
...
include/spdlog/sinks/basic_file_sink-inl.h
View file @
f5492aed
...
...
@@ -28,7 +28,7 @@ SPDLOG_INLINE const filename_t &basic_file_sink<Mutex>::filename() const
template
<
typename
Mutex
>
SPDLOG_INLINE
void
basic_file_sink
<
Mutex
>::
sink_it_
(
const
details
::
log_msg
&
msg
)
{
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
file_helper_
.
write
(
formatted
);
}
...
...
include/spdlog/sinks/daily_file_sink.h
View file @
f5492aed
...
...
@@ -30,7 +30,7 @@ struct daily_filename_calculator
{
filename_t
basename
,
ext
;
std
::
tie
(
basename
,
ext
)
=
details
::
file_helper
::
split_by_extension
(
filename
);
std
::
conditional
<
std
::
is_same
<
filename_t
::
value_type
,
char
>::
value
,
fmt
::
memory_buffer
,
fmt
::
wmemory_buffer
>::
type
w
;
std
::
conditional
<
std
::
is_same
<
filename_t
::
value_type
,
char
>::
value
,
memory_buf_t
,
fmt
::
wmemory_buffer
>::
type
w
;
fmt
::
format_to
(
w
,
SPDLOG_FILENAME_T
(
"{}_{:04d}-{:02d}-{:02d}{}"
),
basename
,
now_tm
.
tm_year
+
1900
,
now_tm
.
tm_mon
+
1
,
now_tm
.
tm_mday
,
ext
);
return
fmt
::
to_string
(
w
);
...
...
@@ -78,7 +78,7 @@ protected:
file_helper_
.
open
(
FileNameCalc
::
calc_filename
(
base_filename_
,
now_tm
(
time
)),
truncate_
);
rotation_tp_
=
next_rotation_tp_
();
}
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
file_helper_
.
write
(
formatted
);
}
...
...
include/spdlog/sinks/dup_filter_sink.h
View file @
f5492aed
...
...
@@ -66,7 +66,7 @@ protected:
// log the "skipped.." message
if
(
skip_counter_
>
0
)
{
fmt
::
basic_memory_buffer
<
char
,
64
>
buf
;
memory_buf_t
buf
;
fmt
::
format_to
(
buf
,
"Skipped {} duplicate messages.."
,
skip_counter_
);
details
::
log_msg
skipped_msg
{
msg
.
logger_name
,
msg
.
level
,
string_view_t
{
buf
.
data
(),
buf
.
size
()}};
dist_sink
<
Mutex
>::
sink_it_
(
skipped_msg
);
...
...
include/spdlog/sinks/msvc_sink.h
View file @
f5492aed
...
...
@@ -28,7 +28,7 @@ protected:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
OutputDebugStringA
(
fmt
::
to_string
(
formatted
).
c_str
());
}
...
...
include/spdlog/sinks/ostream_sink.h
View file @
f5492aed
...
...
@@ -25,7 +25,7 @@ public:
protected
:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
ostream_
.
write
(
formatted
.
data
(),
static_cast
<
std
::
streamsize
>
(
formatted
.
size
()));
if
(
force_flush_
)
...
...
include/spdlog/sinks/rotating_file_sink-inl.h
View file @
f5492aed
...
...
@@ -43,7 +43,7 @@ SPDLOG_INLINE rotating_file_sink<Mutex>::rotating_file_sink(
template
<
typename
Mutex
>
SPDLOG_INLINE
filename_t
rotating_file_sink
<
Mutex
>::
calc_filename
(
const
filename_t
&
filename
,
std
::
size_t
index
)
{
typename
std
::
conditional
<
std
::
is_same
<
filename_t
::
value_type
,
char
>::
value
,
fmt
::
memory_buffer
,
fmt
::
wmemory_buffer
>::
type
w
;
typename
std
::
conditional
<
std
::
is_same
<
filename_t
::
value_type
,
char
>::
value
,
memory_buf_t
,
fmt
::
wmemory_buffer
>::
type
w
;
if
(
index
!=
0u
)
{
filename_t
basename
,
ext
;
...
...
@@ -66,7 +66,7 @@ SPDLOG_INLINE const filename_t &rotating_file_sink<Mutex>::filename() const
template
<
typename
Mutex
>
SPDLOG_INLINE
void
rotating_file_sink
<
Mutex
>::
sink_it_
(
const
details
::
log_msg
&
msg
)
{
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
current_size_
+=
formatted
.
size
();
if
(
current_size_
>
max_size_
)
...
...
include/spdlog/sinks/stdout_sinks-inl.h
View file @
f5492aed
...
...
@@ -26,7 +26,7 @@ template<typename ConsoleMutex>
SPDLOG_INLINE
void
stdout_sink_base
<
ConsoleMutex
>::
log
(
const
details
::
log_msg
&
msg
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter_
->
format
(
msg
,
formatted
);
fwrite
(
formatted
.
data
(),
sizeof
(
char
),
formatted
.
size
(),
file_
);
fflush
(
file_
);
// flush every line to terminal
...
...
include/spdlog/sinks/syslog_sink.h
View file @
f5492aed
...
...
@@ -50,7 +50,7 @@ protected:
if
(
enable_formatting_
)
{
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
payload
=
string_view_t
(
formatted
.
data
(),
formatted
.
size
());
}
...
...
include/spdlog/sinks/wincolor_sink-inl.h
View file @
f5492aed
...
...
@@ -52,7 +52,7 @@ template<typename ConsoleMutex>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
log
(
const
details
::
log_msg
&
msg
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter_
->
format
(
msg
,
formatted
);
if
(
!
in_console_
)
{
...
...
@@ -131,14 +131,14 @@ WORD SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(WORD attri
// print a range of formatted message to console
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
memory_buf_t
&
formatted
,
size_t
start
,
size_t
end
)
{
auto
size
=
static_cast
<
DWORD
>
(
end
-
start
);
::
WriteConsoleA
(
out_handle_
,
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
}
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
memory_buf_t
&
formatted
)
{
auto
size
=
static_cast
<
DWORD
>
(
formatted
.
size
());
if
(
size
==
0
)
...
...
include/spdlog/sinks/wincolor_sink.h
View file @
f5492aed
...
...
@@ -58,10 +58,10 @@ protected:
WORD
set_foreground_color_
(
WORD
attribs
);
// 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
memory_buf_t
&
formatted
,
size_t
start
,
size_t
end
);
// 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
memory_buf_t
&
formatted
);
};
template
<
typename
ConsoleMutex
>
...
...
tests/test_file_helper.cpp
View file @
f5492aed
...
...
@@ -10,7 +10,7 @@ static const std::string target_filename = "logs/file_helper_test.txt";
static
void
write_with_helper
(
file_helper
&
helper
,
size_t
howmany
)
{
fmt
::
memory_buffer
formatted
;
spdlog
::
memory_buf_t
formatted
;
fmt
::
format_to
(
formatted
,
"{}"
,
std
::
string
(
howmany
,
'1'
));
helper
.
write
(
formatted
);
helper
.
flush
();
...
...
tests/test_fmt_helper.cpp
View file @
f5492aed
...
...
@@ -2,30 +2,32 @@
#include "includes.h"
#include "spdlog/details/fmt_helper.h"
using
spdlog
::
memory_buf_t
;
void
test_pad2
(
int
n
,
const
char
*
expected
)
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
spdlog
::
details
::
fmt_helper
::
pad2
(
n
,
buf
);
REQUIRE
(
fmt
::
to_string
(
buf
)
==
expected
);
}
void
test_pad3
(
uint32_t
n
,
const
char
*
expected
)
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
spdlog
::
details
::
fmt_helper
::
pad3
(
n
,
buf
);
REQUIRE
(
fmt
::
to_string
(
buf
)
==
expected
);
}
void
test_pad6
(
std
::
size_t
n
,
const
char
*
expected
)
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
spdlog
::
details
::
fmt_helper
::
pad6
(
n
,
buf
);
REQUIRE
(
fmt
::
to_string
(
buf
)
==
expected
);
}
void
test_pad9
(
std
::
size_t
n
,
const
char
*
expected
)
{
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
spdlog
::
details
::
fmt_helper
::
pad9
(
n
,
buf
);
REQUIRE
(
fmt
::
to_string
(
buf
)
==
expected
);
}
...
...
tests/test_pattern_formatter.cpp
View file @
f5492aed
#include "includes.h"
using
spdlog
::
memory_buf_t
;
// log to str and return it
template
<
typename
...
Args
>
static
std
::
string
log_to_str
(
const
std
::
string
&
msg
,
const
Args
&
...
args
)
{
std
::
ostringstream
oss
;
...
...
@@ -61,9 +62,9 @@ TEST_CASE("color range test1", "[pattern_formatter]")
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%^%v%$"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
fmt
::
memory_buffer
buf
;
memory_buf_t
buf
;
fmt
::
format_to
(
buf
,
"Hello"
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
spdlog
::
string_view_t
(
buf
.
data
(),
buf
.
size
()));
formatter
->
format
(
msg
,
formatted
);
...
...
@@ -77,7 +78,7 @@ TEST_CASE("color range test2", "[pattern_formatter]")
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%^%$"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
""
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter
->
format
(
msg
,
formatted
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
0
);
...
...
@@ -89,7 +90,7 @@ TEST_CASE("color range test3", "[pattern_formatter]")
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%^***%$"
);
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"ignored"
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter
->
format
(
msg
,
formatted
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
3
);
...
...
@@ -101,7 +102,7 @@ TEST_CASE("color range test4", "[pattern_formatter]")
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"ignored"
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter
->
format
(
msg
,
formatted
);
REQUIRE
(
msg
.
color_range_start
==
2
);
REQUIRE
(
msg
.
color_range_end
==
5
);
...
...
@@ -113,7 +114,7 @@ TEST_CASE("color range test5", "[pattern_formatter]")
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"**%^"
);
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"ignored"
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter
->
format
(
msg
,
formatted
);
REQUIRE
(
msg
.
color_range_start
==
2
);
REQUIRE
(
msg
.
color_range_end
==
0
);
...
...
@@ -124,7 +125,7 @@ TEST_CASE("color range test6", "[pattern_formatter]")
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"**%$"
);
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"ignored"
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
formatter
->
format
(
msg
,
formatted
);
REQUIRE
(
msg
.
color_range_start
==
0
);
REQUIRE
(
msg
.
color_range_end
==
2
);
...
...
@@ -198,8 +199,8 @@ TEST_CASE("clone-default-formatter", "[pattern_formatter]")
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"some message"
);
fmt
::
memory_buffer
formatted_1
;
fmt
::
memory_buffer
formatted_2
;
memory_buf_t
formatted_1
;
memory_buf_t
formatted_2
;
formatter_1
->
format
(
msg
,
formatted_1
);
formatter_2
->
format
(
msg
,
formatted_2
);
...
...
@@ -213,8 +214,8 @@ TEST_CASE("clone-default-formatter2", "[pattern_formatter]")
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"some message"
);
fmt
::
memory_buffer
formatted_1
;
fmt
::
memory_buffer
formatted_2
;
memory_buf_t
formatted_1
;
memory_buf_t
formatted_2
;
formatter_1
->
format
(
msg
,
formatted_1
);
formatter_2
->
format
(
msg
,
formatted_2
);
...
...
@@ -228,8 +229,8 @@ TEST_CASE("clone-formatter", "[pattern_formatter]")
std
::
string
logger_name
=
"test"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"some message"
);
fmt
::
memory_buffer
formatted_1
;
fmt
::
memory_buffer
formatted_2
;
memory_buf_t
formatted_1
;
memory_buf_t
formatted_2
;
formatter_1
->
format
(
msg
,
formatted_1
);
formatter_2
->
format
(
msg
,
formatted_2
);
REQUIRE
(
fmt
::
to_string
(
formatted_1
)
==
fmt
::
to_string
(
formatted_2
));
...
...
@@ -243,8 +244,8 @@ TEST_CASE("clone-formatter-2", "[pattern_formatter]")
std
::
string
logger_name
=
"test2"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"some message"
);
fmt
::
memory_buffer
formatted_1
;
fmt
::
memory_buffer
formatted_2
;
memory_buf_t
formatted_1
;
memory_buf_t
formatted_2
;
formatter_1
->
format
(
msg
,
formatted_1
);
formatter_2
->
format
(
msg
,
formatted_2
);
REQUIRE
(
fmt
::
to_string
(
formatted_1
)
==
fmt
::
to_string
(
formatted_2
));
...
...
@@ -263,7 +264,7 @@ static const char *test_path = "/a/b//myfile.cpp";
TEST_CASE
(
"short filename formatter-1"
,
"[pattern_formatter]"
)
{
spdlog
::
pattern_formatter
formatter
(
"%s"
,
spdlog
::
pattern_time_type
::
local
,
""
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
std
::
string
logger_name
=
"logger-name"
;
spdlog
::
source_loc
source_loc
{
test_path
,
123
,
"some_func()"
};
spdlog
::
details
::
log_msg
msg
(
source_loc
,
"logger-name"
,
spdlog
::
level
::
info
,
"Hello"
);
...
...
@@ -274,7 +275,7 @@ TEST_CASE("short filename formatter-1", "[pattern_formatter]")
TEST_CASE
(
"short filename formatter-2"
,
"[pattern_formatter]"
)
{
spdlog
::
pattern_formatter
formatter
(
"%s:%#"
,
spdlog
::
pattern_time_type
::
local
,
""
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
std
::
string
logger_name
=
"logger-name"
;
spdlog
::
source_loc
source_loc
{
"myfile.cpp"
,
123
,
"some_func()"
};
spdlog
::
details
::
log_msg
msg
(
source_loc
,
"logger-name"
,
spdlog
::
level
::
info
,
"Hello"
);
...
...
@@ -285,7 +286,7 @@ TEST_CASE("short filename formatter-2", "[pattern_formatter]")
TEST_CASE
(
"short filename formatter-3"
,
"[pattern_formatter]"
)
{
spdlog
::
pattern_formatter
formatter
(
"%s %v"
,
spdlog
::
pattern_time_type
::
local
,
""
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
std
::
string
logger_name
=
"logger-name"
;
spdlog
::
source_loc
source_loc
{
""
,
123
,
"some_func()"
};
spdlog
::
details
::
log_msg
msg
(
source_loc
,
"logger-name"
,
spdlog
::
level
::
info
,
"Hello"
);
...
...
@@ -296,7 +297,7 @@ TEST_CASE("short filename formatter-3", "[pattern_formatter]")
TEST_CASE
(
"full filename formatter"
,
"[pattern_formatter]"
)
{
spdlog
::
pattern_formatter
formatter
(
"%g"
,
spdlog
::
pattern_time_type
::
local
,
""
);
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
std
::
string
logger_name
=
"logger-name"
;
spdlog
::
source_loc
source_loc
{
test_path
,
123
,
"some_func()"
};
spdlog
::
details
::
log_msg
msg
(
source_loc
,
"logger-name"
,
spdlog
::
level
::
info
,
"Hello"
);
...
...
tests/test_sink.h
View file @
f5492aed
...
...
@@ -49,7 +49,7 @@ public:
protected
:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
fmt
::
memory_buffer
formatted
;
memory_buf_t
formatted
;
base_sink
<
Mutex
>::
formatter_
->
format
(
msg
,
formatted
);
// save the line without the eol
auto
eol_len
=
strlen
(
details
::
os
::
default_eol
);
...
...
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