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
48c8755d
Commit
48c8755d
authored
Mar 08, 2018
by
fegomes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include test to convert functions and change suggested by @gabime
parent
f9750ddd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
10 deletions
+57
-10
common.h
include/spdlog/common.h
+24
-10
test_misc.cpp
tests/test_misc.cpp
+33
-0
No files found.
include/spdlog/common.h
View file @
48c8755d
...
...
@@ -15,7 +15,8 @@
#include <memory>
#include <atomic>
#include <exception>
#include<functional>
#include <functional>
#include <unordered_map>
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
#include <codecvt>
...
...
@@ -89,6 +90,17 @@ enum level_enum
off
=
6
};
static
std
::
unordered_map
<
std
::
string
,
level_enum
>
name_to_level
=
{
{
"trace"
,
level
::
trace
},
{
"debug"
,
level
::
debug
},
{
"info"
,
level
::
info
},
{
"warning"
,
level
::
warn
},
{
"error"
,
level
::
err
},
{
"critical"
,
level
::
critical
},
{
"off"
,
level
::
off
}
};
#if !defined(SPDLOG_LEVEL_NAMES)
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" }
#endif
...
...
@@ -105,17 +117,19 @@ inline const char* to_short_str(spdlog::level::level_enum l)
{
return
short_level_names
[
l
];
}
inline
spdlog
::
level
::
level_enum
to_level_enum
(
const
char
*
name
)
inline
spdlog
::
level
::
level_enum
to_level_enum
(
const
std
::
string
&
name
)
{
for
(
size_t
level
=
0
;
level
<
size
(
level_names
);
level
++
)
{
if
(
!
strcmp
(
level_names
[
level
],
name
))
{
return
(
spdlog
::
level
::
level_enum
)
level
;
}
}
return
(
spdlog
::
level
::
level_enum
)
0
;
auto
ci
=
name_to_level
.
find
(
name
);
if
(
ci
!=
name_to_level
.
end
())
{
return
ci
->
second
;
}
else
{
return
level
::
off
;
}
}
using
level_hasher
=
std
::
hash
<
int
>
;
}
//level
...
...
tests/test_misc.cpp
View file @
48c8755d
...
...
@@ -42,6 +42,39 @@ TEST_CASE("log_levels", "[log_levels]")
REQUIRE
(
log_info
(
"Hello"
,
spdlog
::
level
::
trace
)
==
"Hello"
);
}
TEST_CASE
(
"to_str"
,
"[convert_to_str]"
)
{
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
trace
))
==
"trace"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
debug
))
==
"debug"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
info
))
==
"info"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
warn
))
==
"warning"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
err
))
==
"error"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
critical
))
==
"critical"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_str
(
spdlog
::
level
::
off
))
==
"off"
);
}
TEST_CASE
(
"to_short_str"
,
"[convert_to_short_str]"
)
{
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
trace
))
==
"T"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
debug
))
==
"D"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
info
))
==
"I"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
warn
))
==
"W"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
err
))
==
"E"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
critical
))
==
"C"
);
REQUIRE
(
std
::
string
(
spdlog
::
level
::
to_short_str
(
spdlog
::
level
::
off
))
==
"O"
);
}
TEST_CASE
(
"to_level_enum"
,
"[convert_to_level_enum]"
)
{
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"trace"
)
==
spdlog
::
level
::
trace
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"debug"
)
==
spdlog
::
level
::
debug
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"info"
)
==
spdlog
::
level
::
info
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"warning"
)
==
spdlog
::
level
::
warn
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"error"
)
==
spdlog
::
level
::
err
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"critical"
)
==
spdlog
::
level
::
critical
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"off"
)
==
spdlog
::
level
::
off
);
REQUIRE
(
spdlog
::
level
::
to_level_enum
(
"null"
)
==
spdlog
::
level
::
off
);
}
...
...
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