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
0ce670e4
Commit
0ce670e4
authored
Nov 25, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store level names as string_views
parent
2671b48a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
24 deletions
+23
-24
include/spdlog/common.h
include/spdlog/common.h
+13
-14
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+2
-2
tests/test_misc.cpp
tests/test_misc.cpp
+8
-8
No files found.
include/spdlog/common.h
View file @
0ce670e4
...
...
@@ -107,13 +107,13 @@ enum level_enum
"trace", "debug", "info", "warning", "error", "critical", "off" \
}
#endif
static
const
char
*
level_names
[]
SPDLOG_LEVEL_NAMES
;
static
string_view_t
level_string_views
[]
SPDLOG_LEVEL_NAMES
;
static
const
char
*
short_level_names
[]{
"T"
,
"D"
,
"I"
,
"W"
,
"E"
,
"C"
,
"O"
};
inline
const
char
*
to_c_str
(
spdlog
::
level
::
level_enum
l
)
SPDLOG_NOEXCEPT
inline
string_view_t
&
to_string_view
(
spdlog
::
level
::
level_enum
l
)
SPDLOG_NOEXCEPT
{
return
level_
name
s
[
l
];
return
level_
string_view
s
[
l
];
}
inline
const
char
*
to_short_c_str
(
spdlog
::
level
::
level_enum
l
)
SPDLOG_NOEXCEPT
...
...
@@ -123,17 +123,16 @@ inline const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
inline
spdlog
::
level
::
level_enum
from_str
(
const
std
::
string
&
name
)
SPDLOG_NOEXCEPT
{
static
std
::
unordered_map
<
std
::
string
,
level_enum
>
name_to_level
=
// map string->level
{{
level_names
[
0
],
level
::
trace
},
// trace
{
level_names
[
1
],
level
::
debug
},
// debug
{
level_names
[
2
],
level
::
info
},
// info
{
level_names
[
3
],
level
::
warn
},
// warn
{
level_names
[
4
],
level
::
err
},
// err
{
level_names
[
5
],
level
::
critical
},
// critical
{
level_names
[
6
],
level
::
off
}};
// off
auto
lvl_it
=
name_to_level
.
find
(
name
);
return
lvl_it
!=
name_to_level
.
end
()
?
lvl_it
->
second
:
level
::
off
;
int
level
=
0
;
for
(
const
auto
&
level_str
:
level_string_views
)
{
if
(
level_str
==
name
)
{
return
static_cast
<
level
::
level_enum
>
(
level
);
}
level
++
;
}
return
level
::
off
;
}
using
level_hasher
=
std
::
hash
<
int
>
;
...
...
include/spdlog/details/pattern_formatter.h
View file @
0ce670e4
...
...
@@ -159,7 +159,7 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
const
std
::
tm
&
,
fmt
::
memory_buffer
&
dest
)
override
{
string_view_t
level_name
{
level
::
to_c_str
(
msg
.
level
)}
;
string_view_t
&
level_name
=
level
::
to_string_view
(
msg
.
level
)
;
if
(
padinfo_
.
enabled
())
{
scoped_pad
p
(
level_name
,
padinfo_
,
dest
);
...
...
@@ -969,7 +969,7 @@ public:
// wrap the level name with color
msg
.
color_range_start
=
dest
.
size
();
// fmt_helper::append_string_view(level::to_c_str(msg.level), dest);
fmt_helper
::
append_string_view
(
level
::
to_
c_str
(
msg
.
level
),
dest
);
fmt_helper
::
append_string_view
(
level
::
to_
string_view
(
msg
.
level
),
dest
);
msg
.
color_range_end
=
dest
.
size
();
dest
.
push_back
(
']'
);
dest
.
push_back
(
' '
);
...
...
tests/test_misc.cpp
View file @
0ce670e4
...
...
@@ -43,15 +43,15 @@ TEST_CASE("log_levels", "[log_levels]")
REQUIRE
(
log_info
(
"Hello"
,
spdlog
::
level
::
trace
)
==
"Hello"
);
}
TEST_CASE
(
"
to_c_str"
,
"[convert_to_c_str]
"
)
TEST_CASE
(
"
level_to_string_view"
,
"[convert_to_string_view
"
)
{
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
trace
)
)
==
"trace"
);
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
debug
)
)
==
"debug"
);
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
info
)
)
==
"info"
);
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
warn
)
)
==
"warning"
);
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
err
)
)
==
"error"
);
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
critical
)
)
==
"critical"
);
REQUIRE
(
s
td
::
string
(
spdlog
::
level
::
to_c_str
(
spdlog
::
level
::
off
)
)
==
"off"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
trace
)
==
"trace"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
debug
)
==
"debug"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
info
)
==
"info"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
warn
)
==
"warning"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
err
)
==
"error"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
critical
)
==
"critical"
);
REQUIRE
(
s
pdlog
::
level
::
to_string_view
(
spdlog
::
level
::
off
)
==
"off"
);
}
TEST_CASE
(
"to_short_c_str"
,
"[convert_to_short_c_str]"
)
...
...
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