YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Debug.h
浏览该文件的文档.
1 /*
2  © 2012-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YCL_INC_Debug_h_
29 #define YCL_INC_Debug_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YCLib_YCommon
33 #include <libdefect/string.h> // for std::string;
34 #if YF_Multithread == 1
35 # include <mutex>
36 #endif
37 
65 #ifndef NDEBUG
66 # ifndef YCL_Use_TraceSrc
67 # define YCL_Use_TraceSrc 1
68 # endif
69 #endif
70 
71 
72 namespace platform
73 {
74 
84 YF_API void
85 YDebugSetStatus(bool = true);
86 
91 YF_API bool
93 
99 YF_API void
100 YDebugBegin();
101 
106 YF_API void
107 YDebug();
112 YF_API void
113 YDebug(const char*);
114 
119 #if defined _WIN32 && !defined __USE_MINGW_ANSI_STDIO
120 YB_ATTR(format (ms_printf, 1, 2))
121 #else
122 YB_ATTR(format (printf, 1, 2))
123 #endif
124 YF_API int
125 yprintf(const char*, ...);
127 
128 
135 {
136 public:
138  using Filter = std::function<bool(Level, Logger&)>;
139  using Sender = std::function<void(Level, Logger&, const char*)>;
140 
142 
143 private:
145  Filter filter{DefaultFilter};
147  Sender sender{FetchDefaultSender()};
148 #if YF_Multithread == 1
149  std::recursive_mutex record_mtx;
150 #endif
151 
152 public:
153  DefGetter(const ynothrow, Sender, Sender, sender)
154 
155 
159  void
160  SetFilter(Filter);
165  void
166  SetWriter(Sender);
167 
169  static bool
170  DefaultFilter(Level, Logger&) ynothrow;
171 
173  static void
174  DefaultSendLog(Level, Logger&, const char*) ynothrowv;
175 
181  void
183  DoLog(Level, const char*);
184  PDefH(void, DoLog, Level lv, const std::string& str)
185  ImplRet(DoLog(lv, str.c_str()))
187 
192  void
193  DoLogException(Level level, const std::exception&) ynothrow;
194 
196  static Sender
197  FetchDefaultSender(const std::string& = "YFramework");
198 
199  template<typename _fCaller, typename... _tParams>
200  void
201  Log(Level level, _fCaller&& f, _tParams&&... args)
202  {
203  if(filter(level, *this))
204  try
205  {
206  DoLog(level, yforward(f)(yforward(args)...));
207  }
208  catch(std::exception& e)
209  {
210  DoLogException(level, e);
211  throw;
212  }
213  }
214 };
215 
216 
221 YF_API Logger&
223 
224 
230 YF_API YB_ATTR(format (printf, 3, 4)) std::string
231 LogWithSource(const char*, int, const char*, ...);
232 
233 
240 #define YCL_Log(_lv, ...) platform::FetchCommonLogger().Log(_lv, __VA_ARGS__)
241 
242 
248 #if YCL_Use_TraceSrc
249 # define YCL_Trace(_lv, ...) \
250  YCL_Log(_lv, [&]{ \
251  return platform::LogWithSource(__FILE__, __LINE__, __VA_ARGS__); \
252  })
253 #else
254 # define YCL_Trace(_lv, ...) \
255  YCL_Log(_lv, [&]{return ystdex::sfmt(__VA_ARGS__);})
256 #endif
257 
258 
266 #if YB_Use_YTrace
267 # define YTraceDe(_lv, ...) YCL_Trace(_lv, __VA_ARGS__)
268 #else
269 # define YTraceDe(...)
270 #endif
271 
272 } // namespace platform;
273 
274 namespace platform_ex
275 {
276 
277 #if YCL_Android
278 
285 YF_API void
286 LogAssert(bool, const char*, const char*, int, const char*);
287 
288 # ifdef YAssert
289 # undef YAssert
290 # define YAssert(_expr, _msg) \
292  platform_ex::LogAssert(_expr, #_expr, __FILE__, __LINE__, _msg)
293 # endif
294 
295 
307 YF_API int
308 MapAndroidLogLevel(platform::Descriptions::RecordLevel);
309 
310 
316 class YF_API AndroidLogSender
317 {
318 public:
319  using Logger = platform::Logger;
320  using Level = Logger::Level;
321 
322 private:
323  std::string tag;
324 
325 public:
326  AndroidLogSender(const std::string&);
327  DefDeCopyCtor(AndroidLogSender)
328  DefDeMoveCtor(AndroidLogSender)
329  ~AndroidLogSender();
330 
332  void
333  operator()(Level, Logger&, const char*) const;
334 
335  DefGetter(const ynothrow, const std::string&, Tag, tag)
336 };
337 #endif
338 
339 } // namespace platform_ex;
340 
341 #endif
342 
#define ynothrowv
YSLib 无异常抛出保证验证:有条件地使用无异常抛出规范。
Definition: ydef.h:494
yconstfn const string _tParams && args
Definition: Loader.h:111
YF_API void YDebugBegin()
调试模式:显示控制台。
Definition: Debug.cpp:75
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:136
#define YF_API
Definition: Platform.h:64
std::function< bool(Level, Logger &)> Filter
Definition: Debug.h:138
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
yconstfn Integer &Trait::AMask Trait::XYZBitsN yconstfn DefGetter(const ynothrow, typename Trait::BType, B, Integer &Trait::XMask) yconstfn DefGetter(const ynothrow
标准库实现 修正。
YF_API void YDebugSetStatus(bool=true)
调试模式:设置状态。
Definition: Debug.cpp:63
std::size_t size ynothrow
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:141
std::string LogWithSource(const char *file, int line, const char *fmt,...)
Definition: Debug.cpp:225
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
日志记录器。
Definition: Debug.h:134
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
YF_API Logger & FetchCommonLogger()
取公共日志记录器。
Definition: Debug.cpp:212
yconstexpr const KeyInput KeyIndex ynothrow ImplRet(char()) namespace KeyCodes
本机按键编码。
Definition: Keys.h:191
RecordLevel
记录等级。
Definition: ycommon.h:69
_tWidget _fCallable && f
Definition: ywgtevt.h:597
YF_API bool YDebugGetStatus()
调试模式:取得状态。
Definition: Debug.cpp:69
union YB_ATTR(packed) YB_ATTR(aligned(yalignof(typename XYZATrait< _vB
BGRA 四元组。
YF_API int yprintf(const char *,...)
调试模式 printf :显示控制台格式化输出 ,按键继续。
Definition: Debug.cpp:102
YF_API void YDebug()
调试模式:按键继续。
Definition: Debug.cpp:82
PDefH(bool, ufexists, const _tString &str) ynothrow ImplRet(ufexists(str.c_str())) YF_API char16_t *u16getcwd_n(char16_t *buf
判断指定字符串为文件名的文件是否存在。
std::function< void(Level, Logger &, const char *)> Sender
Definition: Debug.h:139