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
81444265
Commit
81444265
authored
Apr 19, 2020
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang-format
parent
5716ab70
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
102 deletions
+111
-102
include/spdlog/details/log_msg-inl.h
include/spdlog/details/log_msg-inl.h
+2
-2
include/spdlog/pattern_formatter-inl.h
include/spdlog/pattern_formatter-inl.h
+5
-4
src/fmt.cpp
src/fmt.cpp
+86
-79
tests/test_time_point.cpp
tests/test_time_point.cpp
+18
-17
No files found.
include/spdlog/details/log_msg-inl.h
View file @
81444265
...
...
@@ -12,8 +12,8 @@
namespace
spdlog
{
namespace
details
{
SPDLOG_INLINE
log_msg
::
log_msg
(
spdlog
::
l
og_clock
::
time_point
log_time
,
spdlog
::
source_loc
loc
,
string_view_t
a_logger_name
,
spdlog
::
l
evel
::
level_enum
lvl
,
spdlog
::
string_view_t
msg
)
SPDLOG_INLINE
log_msg
::
log_msg
(
spdlog
::
log_clock
::
time_point
log_time
,
spdlog
::
source_loc
loc
,
string_view_t
a_logger_name
,
spdlog
::
level
::
level_enum
lvl
,
spdlog
::
string_view_t
msg
)
:
logger_name
(
a_logger_name
)
,
level
(
lvl
)
,
time
(
log_time
)
...
...
include/spdlog/pattern_formatter-inl.h
View file @
81444265
...
...
@@ -95,7 +95,10 @@ struct null_scoped_padder
null_scoped_padder
(
size_t
/*wrapped_size*/
,
const
padding_info
&
/*padinfo*/
,
memory_buf_t
&
/*dest*/
)
{}
template
<
typename
T
>
static
unsigned
int
count_digits
(
T
/* number */
)
{
return
0
;}
static
unsigned
int
count_digits
(
T
/* number */
)
{
return
0
;
}
};
template
<
typename
ScopedPadder
>
...
...
@@ -653,7 +656,6 @@ public:
}
};
// Current pid
template
<
typename
ScopedPadder
>
class
pid_formatter
final
:
public
flag_formatter
...
...
@@ -766,7 +768,7 @@ public:
}
size_t
text_size
;
if
(
padinfo_
.
enabled
())
if
(
padinfo_
.
enabled
())
{
// calc text size for padding based on "filename:line"
text_size
=
std
::
char_traits
<
char
>::
length
(
msg
.
source
.
filename
)
+
ScopedPadder
::
count_digits
(
msg
.
source
.
line
)
+
1
;
...
...
@@ -900,7 +902,6 @@ private:
log_clock
::
time_point
last_message_time_
;
};
// Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
class
full_formatter
final
:
public
flag_formatter
...
...
src/fmt.cpp
View file @
81444265
...
...
@@ -2,7 +2,6 @@
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
#ifndef SPDLOG_COMPILED_LIB
#error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif
...
...
@@ -10,53 +9,63 @@
#if !defined(SPDLOG_FMT_EXTERNAL)
#include <spdlog/fmt/bundled/format-inl.h>
FMT_BEGIN_NAMESPACE
namespace
internal
{
template
<
typename
T
>
int
format_float
(
char
*
buf
,
std
::
size_t
size
,
const
char
*
format
,
int
precision
,
T
value
)
{
template
<
typename
T
>
int
format_float
(
char
*
buf
,
std
::
size_t
size
,
const
char
*
format
,
int
precision
,
T
value
)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if
(
precision
>
100000
)
throw
std
::
runtime_error
(
"fuzz mode - avoid large allocation inside snprintf"
);
throw
std
::
runtime_error
(
"fuzz mode - avoid large allocation inside snprintf"
);
#endif
// Suppress the warning about nonliteral format string.
int
(
*
snprintf_ptr
)(
char
*
,
size_t
,
const
char
*
,
...)
=
FMT_SNPRINTF
;
return
precision
<
0
?
snprintf_ptr
(
buf
,
size
,
format
,
value
)
:
snprintf_ptr
(
buf
,
size
,
format
,
precision
,
value
);
int
(
*
snprintf_ptr
)(
char
*
,
size_t
,
const
char
*
,
...)
=
FMT_SNPRINTF
;
return
precision
<
0
?
snprintf_ptr
(
buf
,
size
,
format
,
value
)
:
snprintf_ptr
(
buf
,
size
,
format
,
precision
,
value
);
}
struct
sprintf_specs
{
struct
sprintf_specs
{
int
precision
;
char
type
;
bool
alt
:
1
;
template
<
typename
Char
>
template
<
typename
Char
>
constexpr
sprintf_specs
(
basic_format_specs
<
Char
>
specs
)
:
precision
(
specs
.
precision
),
type
(
specs
.
type
),
alt
(
specs
.
alt
)
{}
constexpr
bool
has_precision
()
const
{
return
precision
>=
0
;
}
:
precision
(
specs
.
precision
)
,
type
(
specs
.
type
)
,
alt
(
specs
.
alt
)
{}
constexpr
bool
has_precision
()
const
{
return
precision
>=
0
;
}
};
// This is deprecated and is kept only to preserve ABI compatibility.
template
<
typename
Double
>
char
*
sprintf_format
(
Double
value
,
internal
::
buffer
<
char
>&
buf
,
sprintf_specs
specs
)
{
template
<
typename
Double
>
char
*
sprintf_format
(
Double
value
,
internal
::
buffer
<
char
>
&
buf
,
sprintf_specs
specs
)
{
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
FMT_ASSERT
(
buf
.
capacity
()
!=
0
,
"empty buffer"
);
// Build format string.
enum
{
max_format_size
=
10
};
// longest format: %#-*.*Lg
enum
{
max_format_size
=
10
};
// longest format: %#-*.*Lg
char
format
[
max_format_size
];
char
*
format_ptr
=
format
;
char
*
format_ptr
=
format
;
*
format_ptr
++
=
'%'
;
if
(
specs
.
alt
||
!
specs
.
type
)
*
format_ptr
++
=
'#'
;
if
(
specs
.
precision
>=
0
)
{
if
(
specs
.
alt
||
!
specs
.
type
)
*
format_ptr
++
=
'#'
;
if
(
specs
.
precision
>=
0
)
{
*
format_ptr
++
=
'.'
;
*
format_ptr
++
=
'*'
;
}
if
(
std
::
is_same
<
Double
,
long
double
>::
value
)
*
format_ptr
++
=
'L'
;
if
(
std
::
is_same
<
Double
,
long
double
>::
value
)
*
format_ptr
++
=
'L'
;
char
type
=
specs
.
type
;
...
...
@@ -65,51 +74,66 @@ char* sprintf_format(Double value, internal::buffer<char>& buf,
else
if
(
type
==
0
||
type
==
'n'
)
type
=
'g'
;
#if FMT_MSC_VER
if
(
type
==
'F'
)
{
// MSVC's printf doesn't support 'F'.
type
=
'f'
;
}
if
(
type
==
'F'
)
{
// MSVC's printf doesn't support 'F'.
type
=
'f'
;
}
#endif
*
format_ptr
++
=
type
;
*
format_ptr
=
'\0'
;
// Format using snprintf.
char
*
start
=
nullptr
;
char
*
decimal_point_pos
=
nullptr
;
for
(;;)
{
char
*
start
=
nullptr
;
char
*
decimal_point_pos
=
nullptr
;
for
(;;)
{
std
::
size_t
buffer_size
=
buf
.
capacity
();
start
=
&
buf
[
0
];
int
result
=
format_float
(
start
,
buffer_size
,
format
,
specs
.
precision
,
value
);
if
(
result
>=
0
)
{
int
result
=
format_float
(
start
,
buffer_size
,
format
,
specs
.
precision
,
value
);
if
(
result
>=
0
)
{
unsigned
n
=
internal
::
to_unsigned
(
result
);
if
(
n
<
buf
.
capacity
())
{
if
(
n
<
buf
.
capacity
())
{
// Find the decimal point.
auto
p
=
buf
.
data
(),
end
=
p
+
n
;
if
(
*
p
==
'+'
||
*
p
==
'-'
)
++
p
;
if
(
specs
.
type
!=
'a'
&&
specs
.
type
!=
'A'
)
{
while
(
p
<
end
&&
*
p
>=
'0'
&&
*
p
<=
'9'
)
++
p
;
if
(
p
<
end
&&
*
p
!=
'e'
&&
*
p
!=
'E'
)
{
if
(
*
p
==
'+'
||
*
p
==
'-'
)
++
p
;
if
(
specs
.
type
!=
'a'
&&
specs
.
type
!=
'A'
)
{
while
(
p
<
end
&&
*
p
>=
'0'
&&
*
p
<=
'9'
)
++
p
;
if
(
p
<
end
&&
*
p
!=
'e'
&&
*
p
!=
'E'
)
{
decimal_point_pos
=
p
;
if
(
!
specs
.
type
)
{
if
(
!
specs
.
type
)
{
// Keep only one trailing zero after the decimal point.
++
p
;
if
(
*
p
==
'0'
)
++
p
;
while
(
p
!=
end
&&
*
p
>=
'1'
&&
*
p
<=
'9'
)
++
p
;
char
*
where
=
p
;
while
(
p
!=
end
&&
*
p
==
'0'
)
++
p
;
if
(
p
==
end
||
*
p
<
'0'
||
*
p
>
'9'
)
{
if
(
p
!=
end
)
std
::
memmove
(
where
,
p
,
to_unsigned
(
end
-
p
));
if
(
*
p
==
'0'
)
++
p
;
while
(
p
!=
end
&&
*
p
>=
'1'
&&
*
p
<=
'9'
)
++
p
;
char
*
where
=
p
;
while
(
p
!=
end
&&
*
p
==
'0'
)
++
p
;
if
(
p
==
end
||
*
p
<
'0'
||
*
p
>
'9'
)
{
if
(
p
!=
end
)
std
::
memmove
(
where
,
p
,
to_unsigned
(
end
-
p
));
n
-=
static_cast
<
unsigned
>
(
p
-
where
);
}
}
}
}
buf
.
resize
(
n
);
break
;
// The buffer is large enough - continue with formatting.
break
;
// The buffer is large enough - continue with formatting.
}
buf
.
reserve
(
n
+
1
);
}
else
{
}
else
{
// If result is negative we ask to increase the capacity by at least 1,
// but as std::vector, the buffer grows exponentially.
buf
.
reserve
(
buf
.
capacity
()
+
1
);
...
...
@@ -117,23 +141,18 @@ char* sprintf_format(Double value, internal::buffer<char>& buf,
}
return
decimal_point_pos
;
}
}
// namespace internal
}
// namespace internal
template
FMT_API
char
*
internal
::
sprintf_format
(
double
,
internal
::
buffer
<
char
>
&
,
sprintf_specs
);
template
FMT_API
char
*
internal
::
sprintf_format
(
long
double
,
internal
::
buffer
<
char
>
&
,
sprintf_specs
);
template
FMT_API
char
*
internal
::
sprintf_format
(
double
,
internal
::
buffer
<
char
>
&
,
sprintf_specs
);
template
FMT_API
char
*
internal
::
sprintf_format
(
long
double
,
internal
::
buffer
<
char
>
&
,
sprintf_specs
);
template
struct
FMT_INSTANTIATION_DEF_API
internal
::
basic_data
<
void
>;
// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
int
(
*
instantiate_format_float
)(
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>&
)
=
internal
::
format_float
;
int
(
*
instantiate_format_float
)(
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
)
=
internal
::
format_float
;
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
template
FMT_API
internal
::
locale_ref
::
locale_ref
(
const
std
::
locale
&
loc
);
template
FMT_API
internal
::
locale_ref
::
locale_ref
(
const
std
::
locale
&
loc
);
template
FMT_API
std
::
locale
internal
::
locale_ref
::
get
<
std
::
locale
>()
const
;
#endif
...
...
@@ -143,28 +162,18 @@ template FMT_API std::string internal::grouping_impl<char>(locale_ref);
template
FMT_API
char
internal
::
thousands_sep_impl
(
locale_ref
);
template
FMT_API
char
internal
::
decimal_point_impl
(
locale_ref
);
template
FMT_API
void
internal
::
buffer
<
char
>
::
append
(
const
char
*
,
const
char
*
);
template
FMT_API
void
internal
::
buffer
<
char
>
::
append
(
const
char
*
,
const
char
*
);
template
FMT_API
void
internal
::
arg_map
<
format_context
>
::
init
(
const
basic_format_args
<
format_context
>
&
args
);
template
FMT_API
void
internal
::
arg_map
<
format_context
>
::
init
(
const
basic_format_args
<
format_context
>
&
args
);
template
FMT_API
std
::
string
internal
::
vformat
<
char
>(
string_view
,
basic_format_args
<
format_context
>);
template
FMT_API
std
::
string
internal
::
vformat
<
char
>(
string_view
,
basic_format_args
<
format_context
>);
template
FMT_API
format_context
::
iterator
internal
::
vformat_to
(
internal
::
buffer
<
char
>
&
,
string_view
,
basic_format_args
<
format_context
>);
template
FMT_API
format_context
::
iterator
internal
::
vformat_to
(
internal
::
buffer
<
char
>
&
,
string_view
,
basic_format_args
<
format_context
>);
template
FMT_API
int
internal
::
snprintf_float
(
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
snprintf_float
(
long
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
format_float
(
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
format_float
(
long
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
snprintf_float
(
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
snprintf_float
(
long
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
format_float
(
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
template
FMT_API
int
internal
::
format_float
(
long
double
,
int
,
internal
::
float_specs
,
internal
::
buffer
<
char
>
&
);
// Explicit instantiations for wchar_t.
...
...
@@ -172,11 +181,9 @@ template FMT_API std::string internal::grouping_impl<wchar_t>(locale_ref);
template
FMT_API
wchar_t
internal
::
thousands_sep_impl
(
locale_ref
);
template
FMT_API
wchar_t
internal
::
decimal_point_impl
(
locale_ref
);
template
FMT_API
void
internal
::
buffer
<
wchar_t
>
::
append
(
const
wchar_t
*
,
const
wchar_t
*
);
template
FMT_API
void
internal
::
buffer
<
wchar_t
>
::
append
(
const
wchar_t
*
,
const
wchar_t
*
);
template
FMT_API
std
::
wstring
internal
::
vformat
<
wchar_t
>(
wstring_view
,
basic_format_args
<
wformat_context
>);
template
FMT_API
std
::
wstring
internal
::
vformat
<
wchar_t
>(
wstring_view
,
basic_format_args
<
wformat_context
>);
FMT_END_NAMESPACE
#endif // !SPDLOG_FMT_EXTERNAL
\ No newline at end of file
tests/test_time_point.cpp
View file @
81444265
...
...
@@ -4,28 +4,29 @@
TEST_CASE
(
"time_point1"
,
"[time_point log_msg]"
)
{
std
::
shared_ptr
<
spdlog
::
sinks
::
test_sink_st
>
test_sink
(
new
spdlog
::
sinks
::
test_sink_st
);
spdlog
::
logger
logger
(
"test-time_point"
,
test_sink
);
std
::
shared_ptr
<
spdlog
::
sinks
::
test_sink_st
>
test_sink
(
new
spdlog
::
sinks
::
test_sink_st
);
spdlog
::
logger
logger
(
"test-time_point"
,
test_sink
);
spdlog
::
source_loc
source
{};
std
::
chrono
::
system_clock
::
time_point
tp
{
std
::
chrono
::
system_clock
::
now
()};
spdlog
::
source_loc
source
{};
std
::
chrono
::
system_clock
::
time_point
tp
{
std
::
chrono
::
system_clock
::
now
()};
test_sink
->
set_pattern
(
"%T.%F"
);
// interested in the time_point
// all the following should have the same time
test_sink
->
set_delay
(
std
::
chrono
::
milliseconds
(
10
));
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
spdlog
::
details
::
log_msg
msg
{
tp
,
source
,
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
// all the following should have the same time
test_sink
->
set_delay
(
std
::
chrono
::
milliseconds
(
10
));
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
spdlog
::
details
::
log_msg
msg
{
tp
,
source
,
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
test_sink
->
log
(
msg
);
}
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
source
,
spdlog
::
level
::
info
,
"formatted message"
);
// last line has different time_point
}
// now the real test... that the times are the same.
std
::
vector
<
std
::
string
>
lines
=
test_sink
->
lines
();
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
source
,
spdlog
::
level
::
info
,
"formatted message"
);
// last line has different time_point
// now the real test... that the times are the same.
std
::
vector
<
std
::
string
>
lines
=
test_sink
->
lines
();
REQUIRE
(
lines
[
0
]
==
lines
[
1
]);
REQUIRE
(
lines
[
2
]
==
lines
[
3
]);
REQUIRE
(
lines
[
4
]
==
lines
[
5
]);
...
...
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