File tree Expand file tree Collapse file tree 3 files changed +22
-8
lines changed Expand file tree Collapse file tree 3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 22
22
23
23
# include < network/logging/logging.hpp>
24
24
# ifndef NETWORK_MESSAGE
25
- # define NETWORK_MESSAGE (msg ) network::logging::log_record() << " [network " << __FILE__ << ' : ' << __LINE__ << " ]: " << msg;
25
+ # define NETWORK_MESSAGE (msg ) network::logging::log_record( __FILE__, __LINE__ ) << msg;
26
26
# endif
27
27
28
28
#else
Original file line number Diff line number Diff line change @@ -31,10 +31,20 @@ class log_record
31
31
public:
32
32
log_record (){} // = default;
33
33
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, unsigned long line )
45
+ : m_filename( filename )
46
+ , m_line( line )
36
47
{
37
- write ( message );
38
48
}
39
49
40
50
~log_record ()
@@ -49,15 +59,18 @@ class log_record
49
59
return *this ;
50
60
}
51
61
52
- std::string full_message () const { return m_text_stream.str (); }
62
+ std::string message () const { return m_text_stream.str (); }
63
+ const std::string& filename () const { return m_filename; }
64
+ unsigned long line () const { return m_line; }
53
65
54
66
private:
55
67
// disable copy
56
68
log_record ( const log_record& ); // = delete;
57
69
log_record& operator =( const log_record& ); // = delete;
58
70
59
71
std::ostringstream m_text_stream; // stream in which we build the message
60
-
72
+ std::string m_filename; // = "unknown";
73
+ unsigned long m_line; // = 0;
61
74
};
62
75
63
76
template < typename TypeOfSomething >
Original file line number Diff line number Diff line change @@ -18,8 +18,9 @@ namespace handler
18
18
namespace
19
19
{
20
20
void std_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;
23
24
}
24
25
}
25
26
You can’t perform that action at this time.
0 commit comments