Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbec19e1

Browse files
committed
Run clang-format on logging/
1 parent321041f commitbec19e1

File tree

4 files changed

+97
-112
lines changed

4 files changed

+97
-112
lines changed

‎logging/src/logging.cpp‎

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,40 @@
1111
#include<memory>
1212
#include<network/logging/logging.hpp>
1313

14-
namespacenetwork {namespacelogging {
14+
namespacenetwork {
15+
namespacelogging {
1516

16-
constchar* log_record::UNKNOWN_FILE_NAME ="unknown";
17+
constchar* log_record::UNKNOWN_FILE_NAME ="unknown";
1718

18-
19-
namespacehandler
20-
{
21-
namespace
22-
{
23-
voidstd_log_handler(const log_record& log )
24-
{
25-
std::cerr <<"[network" << log.filename() <<":" << log.line() <<"]"
26-
<< log.message() << std::endl;
27-
}
28-
}
29-
30-
log_record_handlerget_std_log_handler() {return &std_log_handler; }
31-
log_record_handlerget_default_log_handler() {return &std_log_handler; }
19+
namespacehandler {
20+
namespace {
21+
voidstd_log_handler(const log_record& log) {
22+
std::cerr <<"[network" << log.filename() <<":" << log.line() <<"]"
23+
<< log.message() << std::endl;
24+
}
3225
}
3326

27+
log_record_handlerget_std_log_handler() {return &std_log_handler; }
28+
log_record_handlerget_default_log_handler() {return &std_log_handler; }
29+
}
3430

35-
namespace
36-
{
37-
// the log handler have to manage itself the thread safety on call
38-
staticauto current_log_record_handler = std::make_shared<log_record_handler>(&handler::std_log_handler);
31+
namespace{
32+
// the log handler have to manage itself the thread safety on call
33+
staticauto current_log_record_handler = std::make_shared<log_record_handler>(
34+
&handler::std_log_handler);
3935

4036
}
4137

42-
43-
voidset_log_record_handler( log_record_handler handler )
44-
{
45-
current_log_record_handler = std::make_shared<log_record_handler>( handler );
38+
voidset_log_record_handler(log_record_handler handler) {
39+
current_log_record_handler = std::make_shared<log_record_handler>(handler);
4640
}
4741

48-
voidlog(const log_record& log )
49-
{
42+
voidlog(const log_record& log) {
5043
auto log_handler = current_log_record_handler;
51-
if( log_handler )
52-
{
53-
(*log_handler)( log );
44+
if (log_handler) {
45+
(*log_handler)(log);
5446
}
5547
}
5648

57-
58-
}}
49+
}
50+
}

‎logging/src/network/logging/logging.hpp‎

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,69 @@
99
#include<sstream>
1010
#include<functional>
1111

12-
namespacenetwork {namespacelogging {
12+
namespacenetwork {
13+
namespacelogging {
1314

1415
classlog_record;
1516

1617
//using log_record_handler = std::function< void (const std::string&) >; // use this when VS can compile it...
17-
typedef std::function<void(const log_record&)> log_record_handler;
18+
typedef std::function<void(const log_record&)> log_record_handler;
1819

19-
voidset_log_record_handler(log_record_handler handler);
20-
voidlog(const log_record& message);
20+
voidset_log_record_handler(log_record_handler handler);
21+
voidlog(const log_record& message);
2122

22-
namespacehandler
23-
{
24-
log_record_handlerget_std_log_handler();
25-
log_record_handlerget_default_log_handler();
23+
namespacehandler {
24+
log_record_handlerget_std_log_handler();
25+
log_record_handlerget_default_log_handler();
2626
}
2727

2828
/** Helper to build a log record as a stream.*/
29-
classlog_record
30-
{
31-
public:
32-
log_record()
33-
: m_filename( UNKNOWN_FILE_NAME )
34-
, m_line(0)
35-
{}// = default;
29+
classlog_record {
30+
public:
31+
log_record() : m_filename(UNKNOWN_FILE_NAME), m_line(0) {}// = default;
3632

3733
staticconstchar* UNKNOWN_FILE_NAME;
3834

3935
// Implicit construction from anything serializable to text.
40-
template<typename TypeOfSomething >
41-
log_record( TypeOfSomething&& message )
42-
: m_filename( UNKNOWN_FILE_NAME )
43-
, m_line(0)
44-
{
45-
write( std::forward<TypeOfSomething>(message) );
36+
template<typename TypeOfSomething>
37+
log_record(TypeOfSomething && message)
38+
: m_filename(UNKNOWN_FILE_NAME),
39+
m_line(0) {
40+
write(std::forward<TypeOfSomething>(message));
4641
}
4742

4843
// Construction with recording context informations.
49-
log_record( std::string filename,unsignedlong line )
50-
: m_filename( filename )
51-
, m_line( line )
52-
{
53-
}
54-
55-
template<typename TypeOfSomething >
56-
log_record&write( TypeOfSomething&& something )
57-
{
44+
log_record(std::string filename,unsignedlong line)
45+
: m_filename(filename),
46+
m_line(line) {}
47+
48+
template<typename TypeOfSomething>
49+
log_record&write(TypeOfSomething && something) {
5850
m_text_stream << std::forward<TypeOfSomething>(something);
5951
return *this;
6052
}
61-
62-
template<typename TypeOfSomething >
63-
inline log_record&operator<<( TypeOfSomething&& something )
64-
{
65-
returnwrite( std::forward<TypeOfSomething>(something) );
53+
54+
template<typename TypeOfSomething>
55+
inline log_record&operator<<(TypeOfSomething && something) {
56+
returnwrite(std::forward<TypeOfSomething>(something));
6657
}
6758

6859
std::stringmessage()const {return m_text_stream.str(); }
6960
const std::string&filename()const {return m_filename; }
7061
unsignedlongline()const {return m_line; }
7162

72-
private:
63+
private:
7364

7465
// disable copy
75-
log_record(const log_record& );// = delete;
76-
log_record&operator=(const log_record& );// = delete;
66+
log_record(const log_record&);// = delete;
67+
log_record&operator=(const log_record&);// = delete;
7768

78-
std::ostringstream m_text_stream;// stream in which we build the message
79-
std::string m_filename;// = UNKNOWN_FILE_NAME;
80-
unsignedlong m_line;// = 0;
69+
std::ostringstream m_text_stream;// stream in which we build the message
70+
std::string m_filename;// = UNKNOWN_FILE_NAME;
71+
unsignedlong m_line;// = 0;
8172
};
8273

83-
}}
84-
74+
}
75+
}
8576

8677
#endif/* end of include guard: NETWORK_LOGGING_HPP_20121112*/

‎logging/test/logging_custom_handler.cpp‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@
1313
usingnamespacenetwork::logging;
1414

1515
TEST(logging_custom_handler, custom_log_handler_output) {
16-
16+
1717
std::stringstream log_output;
18-
auto custom_log_handler = [&](const log_record& log )
19-
{
18+
auto custom_log_handler = [&](const log_record & log) {
2019
log_output <<"[CPPNETLIB]<" << log.filename() <<":" << log.line() <<">"
2120
<< log.message();
22-
};
21+
}
22+
;
2323

2424
constauto line_num =42;
2525
constauto file_name ="somewhere.cpp";
26-
constauto message ="At line" +std::to_string(line_num) +" we check the code.";
26+
constauto message ="At line" +std::to_string(line_num) +
27+
" we check the code.";
2728

28-
set_log_record_handler( custom_log_handler );
29-
log(log_record( file_name, line_num ) <<"At line" << line_num <<" we check the code." );
29+
set_log_record_handler(custom_log_handler);
30+
log(log_record(file_name, line_num) <<"At line" << line_num
31+
<<" we check the code.");
3032

3133
constauto result_output = log_output.str();
3234

33-
ASSERT_TRUE(!result_output.empty());
34-
ASSERT_TRUE(result_output =="[CPPNETLIB]<somewhere.cpp:42>" + message);
35+
ASSERT_TRUE(!result_output.empty());
36+
ASSERT_TRUE(result_output =="[CPPNETLIB]<somewhere.cpp:42>" + message);
3537
}

‎logging/test/logging_log_record.cpp‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,62 +15,62 @@ using namespace network::logging;
1515

1616
TEST(logging_log_record, default_constructor) {
1717
log_record record;
18-
ASSERT_TRUE(record.message() =="");
19-
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
20-
ASSERT_TRUE(record.line() ==0);
18+
ASSERT_TRUE(record.message() =="");
19+
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
20+
ASSERT_TRUE(record.line() ==0);
2121
}
2222

2323
TEST(logging_log_record, cstring_constructor) {
2424
constauto message ="This is a test.";
25-
log_recordrecord(message);
26-
ASSERT_TRUE(record.message() == message);
27-
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
28-
ASSERT_TRUE(record.line() ==0);
25+
log_recordrecord(message);
26+
ASSERT_TRUE(record.message() == message);
27+
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
28+
ASSERT_TRUE(record.line() ==0);
2929
}
3030

3131
TEST(logging_log_record, string_constructor) {
3232
const std::stringmessage("This is a test.");
33-
log_recordrecord(message);
34-
ASSERT_TRUE(record.message() == message);
35-
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
36-
ASSERT_TRUE(record.line() ==0);
33+
log_recordrecord(message);
34+
ASSERT_TRUE(record.message() == message);
35+
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
36+
ASSERT_TRUE(record.line() ==0);
3737
}
3838

3939
TEST(logging_log_record, int_constructor) {
4040
constauto num =42;
41-
log_recordrecord(num);
42-
ASSERT_TRUE(record.message() ==std::to_string(num ));
43-
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
44-
ASSERT_TRUE(record.line() ==0);
41+
log_recordrecord(num);
42+
ASSERT_TRUE(record.message() ==std::to_string(num));
43+
ASSERT_TRUE(record.filename() == log_record::UNKNOWN_FILE_NAME);
44+
ASSERT_TRUE(record.line() ==0);
4545
}
4646

4747
TEST(logging_log_record, info_constructor) {
4848
constauto line_num =42;
4949
constauto file_name ="somewhere.cpp";
50-
log_recordrecord(file_name, line_num);
51-
ASSERT_TRUE(record.message() =="");
52-
ASSERT_TRUE(record.filename() == file_name);
53-
ASSERT_TRUE(record.line() == line_num);
50+
log_recordrecord(file_name, line_num);
51+
ASSERT_TRUE(record.message() =="");
52+
ASSERT_TRUE(record.filename() == file_name);
53+
ASSERT_TRUE(record.line() == line_num);
5454
}
5555

5656
TEST(logging_log_record, text_stream) {
5757
constauto line_num =42;
5858
constauto file_name ="somewhere.cpp";
59-
constauto message ="At line" +std::to_string(line_num) +" we check the code.";
60-
log_recordrecord( file_name, line_num );
59+
constauto message ="At line" +std::to_string(line_num) +
60+
" we check the code.";
61+
log_recordrecord(file_name, line_num);
6162

6263
record <<"At line" << line_num <<" we check the code.";
6364

64-
ASSERT_TRUE(record.message() == message);
65-
ASSERT_TRUE(record.filename() == file_name);
66-
ASSERT_TRUE(record.line() == line_num);
65+
ASSERT_TRUE(record.message() == message);
66+
ASSERT_TRUE(record.filename() == file_name);
67+
ASSERT_TRUE(record.line() == line_num);
6768
}
6869

69-
TEST(logging_log_record, raw_log) {
70-
log("This is a raw log." );
71-
}
70+
TEST(logging_log_record, raw_log) {log("This is a raw log."); }
7271

7372
TEST(logging_log_record, macro_log) {
74-
NETWORK_MESSAGE("This is a log through the macro." );
75-
NETWORK_MESSAGE("This is a log through the macro, with a stream! Num=" <<42 <<" - OK!" );
73+
NETWORK_MESSAGE("This is a log through the macro.");
74+
NETWORK_MESSAGE("This is a log through the macro, with a stream! Num="
75+
<<42 <<" - OK!");
7676
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp