Skip to content

Commit c9e70e0

Browse files
committed
增强: 新增 msvc_sink(OutputDebugString(...)) v1.1.7
1 parent e34e928 commit c9e70e0

1 file changed

Lines changed: 59 additions & 5 deletions

File tree

include/tinylog.hpp

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
_____ _ _
33
|_ _(_)_ __ _ _| | ___ __ _
44
| | | | '_ \| | | | | / _ \ / _` | TinyLog for Modern C++
5-
| | | | | | | |_| | |__| (_) | (_| | version 1.1.6
5+
| | | | | | | |_| | |__| (_) | (_| | version 1.1.7
66
|_| |_|_| |_|\__, |_____\___/ \__, | https://github.com/yanminhui/tinylog
77
|___/ |___/
88
@@ -59,6 +59,9 @@ SOFTWARE.
5959
* // UTF-8 文件槽, 产生以 UTF-8 格式编码的日志文件,
6060
* // 其它行为与 [w]file_sink 一样.
6161
* //
62+
* // - [w]msvc_sink
63+
* // visual studio debug console output.
64+
* //
6265
* logger::add_sink<sink::wfile_sink<default_layout>>("d:\\default.log");
6366
*
6467
* // 过滤日志级别
@@ -102,10 +105,11 @@ SOFTWARE.
102105
* 2) 修正:wlout 拼写错误,layout using 错误. ----------- 2018/05/28 yanmh
103106
* 3) 修正:wcstombs 依赖全局 locale, std::cout 异常v1.1.1 2018/05/28 yanmh
104107
* 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
107110
* 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
109113
*/
110114

111115
#ifndef TINYTINYLOG_HPP
@@ -140,7 +144,7 @@ SOFTWARE.
140144
// 版本信息
141145
#define TINYLOG_VERSION_MAJOR 1
142146
#define TINYLOG_VERSION_MINOR 1
143-
#define TINYLOG_VERSION_PATCH 6
147+
#define TINYLOG_VERSION_PATCH 7
144148

145149
//--------------|
146150
// 用户可控制 |
@@ -1784,6 +1788,56 @@ class basic_u8_file_sink
17841788
using u8_file_sink = basic_u8_file_sink<char>;
17851789
using wu8_file_sink = basic_u8_file_sink<wchar_t>;
17861790

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+
17871841
} // namespace sink
17881842

17891843
//////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)