|
2 | 2 | _____ _ _ |
3 | 3 | |_ _(_)_ __ _ _| | ___ __ _ |
4 | 4 | | | | | '_ \| | | | | / _ \ / _` | TinyLog for Modern C++ |
5 | | - | | | | | | | |_| | |__| (_) | (_| | version 1.1.6 |
| 5 | + | | | | | | | |_| | |__| (_) | (_| | version 1.1.7 |
6 | 6 | |_| |_|_| |_|\__, |_____\___/ \__, | https://github.com/yanminhui/tinylog |
7 | 7 | |___/ |___/ |
8 | 8 |
|
@@ -59,6 +59,9 @@ SOFTWARE. |
59 | 59 | * // UTF-8 文件槽, 产生以 UTF-8 格式编码的日志文件, |
60 | 60 | * // 其它行为与 [w]file_sink 一样. |
61 | 61 | * // |
| 62 | + * // - [w]msvc_sink |
| 63 | + * // visual studio debug console output. |
| 64 | + * // |
62 | 65 | * logger::add_sink<sink::wfile_sink<default_layout>>("d:\\default.log"); |
63 | 66 | * |
64 | 67 | * // 过滤日志级别 |
@@ -102,10 +105,11 @@ SOFTWARE. |
102 | 105 | * 2) 修正:wlout 拼写错误,layout using 错误. ----------- 2018/05/28 yanmh |
103 | 106 | * 3) 修正:wcstombs 依赖全局 locale, std::cout 异常v1.1.1 2018/05/28 yanmh |
104 | 107 | * 4) 优化:解耦终端颜色控制日志槽 v1.1.2 ---------------- 2018/06/01 yanmh |
105 | | - * 5) 优化:支持 wchar_t/char 混合输出 v1.1.3 ------------ 2018/06/02 yanmh |
106 | | - * 6) 优化: 模板参数可配互斥类型,支持槽过滤级别 v1.1.4 -- 2018/06/02 yanmh |
| 108 | + * 5) 增强:支持 wchar_t/char 混合输出 v1.1.3 ------------ 2018/06/02 yanmh |
| 109 | + * 6) 增强: 模板参数可配互斥类型,支持槽过滤级别 v1.1.4 -- 2018/06/02 yanmh |
107 | 110 | * 7) 优化: 日志时间精确到微秒 v1.1.5 -------------------- 2018/06/03 yanmh |
108 | | - * 8) 优化: 支持条件日志 l[w]printf_if/[w]lout_if v1.1.6 2018/06/03 yanmh |
| 111 | + * 8) 增强: 支持条件日志 l[w]printf_if/[w]lout_if v1.1.6 2018/06/03 yanmh |
| 112 | + * 9) 增强: 新增 msvc_sink(OutputDebugString(...)) v1.1.7 2018/06/03 yanmh |
109 | 113 | */ |
110 | 114 |
|
111 | 115 | #ifndef TINYTINYLOG_HPP |
@@ -140,7 +144,7 @@ SOFTWARE. |
140 | 144 | // 版本信息 |
141 | 145 | #define TINYLOG_VERSION_MAJOR 1 |
142 | 146 | #define TINYLOG_VERSION_MINOR 1 |
143 | | -#define TINYLOG_VERSION_PATCH 6 |
| 147 | +#define TINYLOG_VERSION_PATCH 7 |
144 | 148 |
|
145 | 149 | //--------------| |
146 | 150 | // 用户可控制 | |
@@ -1784,6 +1788,56 @@ class basic_u8_file_sink |
1784 | 1788 | using u8_file_sink = basic_u8_file_sink<char>; |
1785 | 1789 | using wu8_file_sink = basic_u8_file_sink<wchar_t>; |
1786 | 1790 |
|
| 1791 | +//----------------| |
| 1792 | +// MSVC Sink | |
| 1793 | +//----------------| |
| 1794 | + |
| 1795 | +#if defined(TINYLOG_WINDOWS_API) |
| 1796 | + |
| 1797 | +template <class charT, class layoutT = default_layout |
| 1798 | + , class mutexT = mutex_t |
| 1799 | + , class formatterT = formatter<layoutT>> |
| 1800 | +class basic_msvc_sink |
| 1801 | + : public basic_sink<charT, layoutT, mutexT, formatterT> |
| 1802 | +{ |
| 1803 | +public: |
| 1804 | + using base = basic_sink<charT, layoutT, mutexT, formatterT>; |
| 1805 | + using char_type = typename base::char_type; |
| 1806 | + using string_t = typename base::string_t; |
| 1807 | + |
| 1808 | +public: |
| 1809 | + bool is_open() const override final |
| 1810 | + { |
| 1811 | + return true; |
| 1812 | + } |
| 1813 | + |
| 1814 | +protected: |
| 1815 | + void writing(level /*lvl*/, string_t& msg) override final |
| 1816 | + { |
| 1817 | + writing_impl(msg); |
| 1818 | + } |
| 1819 | + |
| 1820 | +private: |
| 1821 | + template <class lineCharT, typename std::enable_if |
| 1822 | + <std::is_same<lineCharT, char>::value, int>::type = 0> |
| 1823 | + void writing_impl(std::basic_string<lineCharT> const& line) const |
| 1824 | + { |
| 1825 | + ::OutputDebugStringA(line.c_str()); |
| 1826 | + } |
| 1827 | + |
| 1828 | + template <class lineCharT, typename std::enable_if |
| 1829 | + <std::is_same<lineCharT, wchar_t>::value, int>::type = 0> |
| 1830 | + void writing_impl(std::basic_string<lineCharT> const& line) const |
| 1831 | + { |
| 1832 | + ::OutputDebugStringW(line.c_str()); |
| 1833 | + } |
| 1834 | +}; |
| 1835 | + |
| 1836 | +using msvc_sink = basic_msvc_sink<char>; |
| 1837 | +using wmsvc_sink= basic_msvc_sink<wchar_t>; |
| 1838 | + |
| 1839 | +#endif // TINYLOG_WINDOWS_API |
| 1840 | + |
1787 | 1841 | } // namespace sink |
1788 | 1842 |
|
1789 | 1843 | ////////////////////////////////////////////////////////////////////////////// |
|
0 commit comments