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

Commit98a3100

Browse files
committed
Improved log record.
- log record informations are now separated- the log handler decide how to format the log record- log record accepts more than compatible-to-string types onconstruction,anything string-streamable will work (need additional tests though)
1 parentf6e6ee6 commit98a3100

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

‎include/network/detail/debug.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include<network/logging/logging.hpp>
2424
#ifndef NETWORK_MESSAGE
25-
#defineNETWORK_MESSAGE(msg) network::logging::log_record() <<"[network" <<__FILE__ <<':' <<__LINE__<<"]:" << msg;
25+
#defineNETWORK_MESSAGE(msg) network::logging::log_record(__FILE__,__LINE__) << msg;
2626
#endif
2727

2828
#else

‎include/network/logging/logging.hpp‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,20 @@ class log_record
3131
public:
3232
log_record(){}// = default;
3333

34-
// Implicit construction from string
35-
log_record(const std::string& message )
34+
// Implicit construction from anything serializable to text.
35+
template<typename TypeOfSomething >
36+
log_record( TypeOfSomething&& message )
37+
: m_filename("unknown" )
38+
, m_line(0)
39+
{
40+
write( std::forward<TypeOfSomething>(message) );
41+
}
42+
43+
// Construction with recording context informations.
44+
log_record( std::string filename,unsignedlong line )
45+
: m_filename( filename )
46+
, m_line( line )
3647
{
37-
write( message );
3848
}
3949

4050
~log_record()
@@ -49,15 +59,18 @@ class log_record
4959
return *this;
5060
}
5161

52-
std::stringfull_message()const {return m_text_stream.str(); }
62+
std::stringmessage()const {return m_text_stream.str(); }
63+
const std::string&filename()const {return m_filename; }
64+
unsignedlongline()const {return m_line; }
5365

5466
private:
5567
// disable copy
5668
log_record(const log_record& );// = delete;
5769
log_record&operator=(const log_record& );// = delete;
5870

5971
std::ostringstream m_text_stream;// stream in which we build the message
60-
72+
std::string m_filename;// = "unknown";
73+
unsignedlong m_line;// = 0;
6174
};
6275

6376
template<typename TypeOfSomething >

‎libs/network/src/logging/logging.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ namespace handler
1818
namespace
1919
{
2020
voidstd_log_handler(const log_record& log )
21-
{
22-
std::cerr << log.full_message() << std::endl;
21+
{
22+
std::cerr <<"[network" << log.filename() <<":" << log.line() <<"]"
23+
<< log.message() << std::endl;
2324
}
2425
}
2526

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp