sim: add CXXRTL integration.
[lambdasoc.git] / lambdasoc / sim / include / util / log_fmt.h
1 #ifndef _FMT_LOG_H
2 #define _FMT_LOG_H
3 #include <cerrno>
4 #include <cstring>
5 #include <sstream>
6 #include <string>
7
8 static inline std::stringstream _fmt_msg(const std::string &msg, const std::string &file,
9 unsigned line) {
10 std::stringstream ss;
11 ss << msg << " (" << file << ":" << line << ")";
12 return ss;
13 }
14
15 static inline std::stringstream _fmt_errno(const std::string &msg, unsigned saved_errno,
16 const std::string &file, unsigned line) {
17 return _fmt_msg(msg + ": " + strerror(saved_errno), file, line);
18 }
19
20 #define fmt_msg(msg) _fmt_msg(msg, __FILE__, __LINE__).str()
21 #define fmt_errno(msg) _fmt_errno(msg, errno, __FILE__, __LINE__).str()
22
23 #endif // _FMT_LOG_H