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
808bc1f4
Commit
808bc1f4
authored
Sep 24, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang format
parent
41d879e2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
22 deletions
+23
-22
bench.cpp
bench/bench.cpp
+2
-3
example.cpp
example/example.cpp
+1
-2
bin_to_hex.h
include/spdlog/fmt/bin_to_hex.h
+17
-12
test_misc.cpp
tests/test_misc.cpp
+3
-5
No files found.
bench/bench.cpp
View file @
808bc1f4
...
@@ -54,7 +54,6 @@ int main(int argc, char *argv[])
...
@@ -54,7 +54,6 @@ int main(int argc, char *argv[])
cout
<<
"******************************************************************"
cout
<<
"******************************************************************"
"*************
\n
"
;
"*************
\n
"
;
bench
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_st"
));
bench
(
howmany
,
spdlog
::
create
<
null_sink_st
>
(
"null_st"
));
return
0
;
return
0
;
...
@@ -65,8 +64,8 @@ int main(int argc, char *argv[])
...
@@ -65,8 +64,8 @@ int main(int argc, char *argv[])
auto
basic_st
=
spdlog
::
basic_logger_st
(
"basic_st"
,
"logs/basic_st.log"
,
true
);
auto
basic_st
=
spdlog
::
basic_logger_st
(
"basic_st"
,
"logs/basic_st.log"
,
true
);
bench
(
howmany
,
basic_st
);
bench
(
howmany
,
basic_st
);
//auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files);
//
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files);
//bench(howmany, rotating_st);
//
bench(howmany, rotating_st);
auto
daily_st
=
spdlog
::
daily_logger_st
(
"daily_st"
,
"logs/daily_st.log"
);
auto
daily_st
=
spdlog
::
daily_logger_st
(
"daily_st"
,
"logs/daily_st.log"
);
bench
(
howmany
,
daily_st
);
bench
(
howmany
,
daily_st
);
...
...
example/example.cpp
View file @
808bc1f4
...
@@ -169,12 +169,11 @@ void binary_example()
...
@@ -169,12 +169,11 @@ void binary_example()
auto
console
=
spdlog
::
get
(
"console"
);
auto
console
=
spdlog
::
get
(
"console"
);
std
::
array
<
char
,
80
>
buf
;
std
::
array
<
char
,
80
>
buf
;
console
->
info
(
"Binary example: {}"
,
spdlog
::
to_hex
(
buf
));
console
->
info
(
"Binary example: {}"
,
spdlog
::
to_hex
(
buf
));
console
->
info
(
"Another binary example:{:n}"
,
spdlog
::
to_hex
(
std
::
begin
(
buf
),
std
::
begin
(
buf
)
+
10
));
console
->
info
(
"Another binary example:{:n}"
,
spdlog
::
to_hex
(
std
::
begin
(
buf
),
std
::
begin
(
buf
)
+
10
));
// more examples:
// more examples:
// logger->info("uppercase: {:X}", spdlog::to_hex(buf));
// logger->info("uppercase: {:X}", spdlog::to_hex(buf));
// logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf));
// logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf));
// logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf));
// logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf));
}
}
// create logger with 2 targets with different log levels and formats
// create logger with 2 targets with different log levels and formats
...
...
include/spdlog/fmt/bin_to_hex.h
View file @
808bc1f4
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
// char buf[128];
// char buf[128];
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf)));
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf)));
namespace
spdlog
{
namespace
spdlog
{
namespace
details
{
namespace
details
{
...
@@ -30,20 +29,27 @@ class bytes_range
...
@@ -30,20 +29,27 @@ class bytes_range
{
{
public
:
public
:
bytes_range
(
It
range_begin
,
It
range_end
)
bytes_range
(
It
range_begin
,
It
range_end
)
:
begin_
(
range_begin
),
end_
(
range_end
)
:
begin_
(
range_begin
)
{}
,
end_
(
range_end
)
{
}
It
begin
()
const
{
return
begin_
;}
It
begin
()
const
It
end
()
const
{
return
end_
;}
{
return
begin_
;
}
It
end
()
const
{
return
end_
;
}
private
:
private
:
It
begin_
,
end_
;
It
begin_
,
end_
;
};
};
}
// namespace details
}
// namespace details
// create a bytes_range that wraps the given container
// create a bytes_range that wraps the given container
template
<
typename
Container
>
template
<
typename
Container
>
inline
details
::
bytes_range
<
typename
Container
::
const_iterator
>
to_hex
(
const
Container
&
container
)
inline
details
::
bytes_range
<
typename
Container
::
const_iterator
>
to_hex
(
const
Container
&
container
)
{
{
static_assert
(
sizeof
(
typename
Container
::
value_type
)
==
1
,
"sizeof(Container::value_type) != 1"
);
static_assert
(
sizeof
(
typename
Container
::
value_type
)
==
1
,
"sizeof(Container::value_type) != 1"
);
...
@@ -58,7 +64,6 @@ inline details::bytes_range<It> to_hex(const It range_begin, const It range_end)
...
@@ -58,7 +64,6 @@ inline details::bytes_range<It> to_hex(const It range_begin, const It range_end)
return
details
::
bytes_range
<
It
>
(
range_begin
,
range_end
);
return
details
::
bytes_range
<
It
>
(
range_begin
,
range_end
);
}
}
}
// namespace spdlog
}
// namespace spdlog
namespace
fmt
{
namespace
fmt
{
...
@@ -114,7 +119,7 @@ struct formatter<spdlog::details::bytes_range<T>>
...
@@ -114,7 +119,7 @@ struct formatter<spdlog::details::bytes_range<T>>
std
::
size_t
column
=
line_size
;
std
::
size_t
column
=
line_size
;
auto
inserter
=
ctx
.
begin
();
auto
inserter
=
ctx
.
begin
();
for
(
auto
&
item
:
the_range
)
for
(
auto
&
item
:
the_range
)
{
{
auto
ch
=
static_cast
<
unsigned
char
>
(
item
);
auto
ch
=
static_cast
<
unsigned
char
>
(
item
);
pos
++
;
pos
++
;
...
@@ -126,7 +131,7 @@ struct formatter<spdlog::details::bytes_range<T>>
...
@@ -126,7 +131,7 @@ struct formatter<spdlog::details::bytes_range<T>>
// put first byte without delimiter in front of it
// put first byte without delimiter in front of it
*
inserter
++
=
hex_chars
[(
ch
>>
4
)
&
0x0f
];
*
inserter
++
=
hex_chars
[(
ch
>>
4
)
&
0x0f
];
*
inserter
++
=
hex_chars
[
ch
&
0x0f
];
*
inserter
++
=
hex_chars
[
ch
&
0x0f
];
column
+=
2
;
column
+=
2
;
continue
;
continue
;
}
}
...
@@ -138,7 +143,7 @@ struct formatter<spdlog::details::bytes_range<T>>
...
@@ -138,7 +143,7 @@ struct formatter<spdlog::details::bytes_range<T>>
*
inserter
++
=
hex_chars
[(
ch
>>
4
)
&
0x0f
];
*
inserter
++
=
hex_chars
[(
ch
>>
4
)
&
0x0f
];
*
inserter
++
=
hex_chars
[
ch
&
0x0f
];
*
inserter
++
=
hex_chars
[
ch
&
0x0f
];
column
+=
2
;
column
+=
2
;
}
}
return
inserter
;
return
inserter
;
}
}
...
@@ -155,7 +160,7 @@ struct formatter<spdlog::details::bytes_range<T>>
...
@@ -155,7 +160,7 @@ struct formatter<spdlog::details::bytes_range<T>>
if
(
put_positions
)
if
(
put_positions
)
{
{
fmt
::
format_to
(
inserter
,
"{:<04X}: "
,
pos
-
1
);
fmt
::
format_to
(
inserter
,
"{:<04X}: "
,
pos
-
1
);
return
7
;
return
7
;
}
}
else
else
...
...
tests/test_misc.cpp
View file @
808bc1f4
...
@@ -135,8 +135,6 @@ TEST_CASE("clone async", "[clone]")
...
@@ -135,8 +135,6 @@ TEST_CASE("clone async", "[clone]")
spdlog
::
drop_all
();
spdlog
::
drop_all
();
}
}
#include "spdlog/fmt/bin_to_hex.h"
#include "spdlog/fmt/bin_to_hex.h"
TEST_CASE
(
"to_hex"
,
"[to_hex]"
)
TEST_CASE
(
"to_hex"
,
"[to_hex]"
)
...
@@ -145,7 +143,7 @@ TEST_CASE("to_hex", "[to_hex]")
...
@@ -145,7 +143,7 @@ TEST_CASE("to_hex", "[to_hex]")
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
std
::
vector
<
unsigned
char
>
v
{
9
,
0xa
,
0xb
,
0xc
,
0xff
,
0xff
};
std
::
vector
<
unsigned
char
>
v
{
9
,
0xa
,
0xb
,
0xc
,
0xff
,
0xff
};
oss_logger
.
info
(
"{}"
,
spdlog
::
to_hex
(
v
));
oss_logger
.
info
(
"{}"
,
spdlog
::
to_hex
(
v
));
auto
output
=
oss
.
str
();
auto
output
=
oss
.
str
();
...
@@ -158,7 +156,7 @@ TEST_CASE("to_hex_upper", "[to_hex]")
...
@@ -158,7 +156,7 @@ TEST_CASE("to_hex_upper", "[to_hex]")
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
std
::
vector
<
unsigned
char
>
v
{
9
,
0xa
,
0xb
,
0xc
,
0xff
,
0xff
};
std
::
vector
<
unsigned
char
>
v
{
9
,
0xa
,
0xb
,
0xc
,
0xff
,
0xff
};
oss_logger
.
info
(
"{:X}"
,
spdlog
::
to_hex
(
v
));
oss_logger
.
info
(
"{:X}"
,
spdlog
::
to_hex
(
v
));
auto
output
=
oss
.
str
();
auto
output
=
oss
.
str
();
...
@@ -171,7 +169,7 @@ TEST_CASE("to_hex_no_delimiter", "[to_hex]")
...
@@ -171,7 +169,7 @@ TEST_CASE("to_hex_no_delimiter", "[to_hex]")
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
std
::
vector
<
unsigned
char
>
v
{
9
,
0xa
,
0xb
,
0xc
,
0xff
,
0xff
};
std
::
vector
<
unsigned
char
>
v
{
9
,
0xa
,
0xb
,
0xc
,
0xff
,
0xff
};
oss_logger
.
info
(
"{:sX}"
,
spdlog
::
to_hex
(
v
));
oss_logger
.
info
(
"{:sX}"
,
spdlog
::
to_hex
(
v
));
auto
output
=
oss
.
str
();
auto
output
=
oss
.
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