|
15 | 15 | #include <boost/log/sinks/text_ostream_backend.hpp> |
16 | 16 | #include <boost/log/sources/severity_channel_logger.hpp> |
17 | 17 | #include <boost/log/utility/manipulators/add_value.hpp> |
| 18 | +#include <boost/utility/string_view.hpp> |
18 | 19 |
|
19 | 20 | namespace viam { |
20 | 21 | namespace sdk { |
@@ -116,17 +117,26 @@ class Logger { |
116 | 117 | std::map<std::string, log_level> resource_levels_; |
117 | 118 | }; |
118 | 119 |
|
| 120 | +namespace log_detail { |
| 121 | + |
| 122 | +// Some of the filenames in the SDK are not unique, eg config/resource.hpp, resource/resource.hpp. |
| 123 | +// This function trims a full filename /path/to/some/file.xpp to some/file.xpp |
| 124 | +boost::string_view trim_filename(const char* file); |
| 125 | + |
| 126 | +} // namespace log_detail |
| 127 | + |
119 | 128 | BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_channel, "Channel", std::string); |
120 | 129 | BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_sev, "Severity", viam::sdk::log_level); |
121 | | -BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_file, "file", const char*); |
| 130 | +BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_file, "file", boost::string_view); |
122 | 131 | BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_line, "line", unsigned int); |
123 | 132 | BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_time, |
124 | 133 | "TimeStamp", |
125 | 134 | boost::log::attributes::local_clock::value_type); |
126 | 135 |
|
127 | | -#define VIAM_LOG_IMPL(lg, level) \ |
128 | | - BOOST_LOG_SEV((lg), ::viam::sdk::log_level::level) \ |
129 | | - << ::boost::log::add_value(::viam::sdk::attr_file_type{}, __FILE__) \ |
| 136 | +#define VIAM_LOG_IMPL(lg, level) \ |
| 137 | + BOOST_LOG_SEV((lg), ::viam::sdk::log_level::level) \ |
| 138 | + << ::boost::log::add_value(::viam::sdk::attr_file_type{}, \ |
| 139 | + ::viam::sdk::log_detail::trim_filename(__FILE__)) \ |
130 | 140 | << ::boost::log::add_value(::viam::sdk::attr_line_type{}, __LINE__) |
131 | 141 |
|
132 | 142 | /// @brief Log macro for general SDK logs. |
|
0 commit comments