日志相关

/* 日志接口 */
#define os_err(fmt, ...)    __os_log(OS_LOG_ERR, __FILE__, __LINE__, fmt, __VA_ARGS__)
#define os_err(fmt, ...)    __os_log(OS_LOG_ERR, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
#define os_err(fmt, args...)    __os_log(OS_LOG_ERR, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
void __os_log(int level, const char *file, int line, char *fmt, ...);


#define LOGINS()    CLogInfo(__FILE__, __LINE__)
class CLogInfo
{
public:
    CLogInfo(const char *file, int line) :__file(file), __line(line) {};

    void operator ()(const char *format, ...) {
        char buf[1024];
        va_list args;
        int len = os_snprintf(buf, sizeof(buf), "%s:[%d]===", __file, __line);;

        va_start(args, format);
        os_vsnprintf(buf + len, sizeof(buf) - len, format, args);
        va_end(args);

        puts(buf);
    };
private:
    const char *__file;
    int __line;
};

/* QT */
#if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) || defined(Q_CC_DIAB)
#  define Q_FUNC_INFO __PRETTY_FUNCTION__
#elif defined(_MSC_VER)
    /* MSVC 2002 doesn't have __FUNCSIG__ nor can it handle QT_STRINGIFY. */
#  if _MSC_VER <= 1300
#      define Q_FUNC_INFO __FILE__ "(line number unavailable)"
#  else
#      define Q_FUNC_INFO __FUNCSIG__
#  endif
#else
#   if defined(Q_OS_SOLARIS) || defined(Q_CC_XLC) || defined(Q_OS_SYMBIAN)
#      define Q_FUNC_INFO __FILE__ "(line number unavailable)"
#   else
        /* These two macros makes it possible to turn the builtin line expander into a
         * string literal. */
#       define QT_STRINGIFY2(x) #x
#       define QT_STRINGIFY(x) QT_STRINGIFY2(x)
#       define Q_FUNC_INFO __FILE__ ":" QT_STRINGIFY(__LINE__)
#   endif
    /* The MIPSpro and RVCT compilers postpones macro expansion,
       and therefore macros must be in scope when being used. */
#   if !defined(Q_CC_MIPS) && !defined(Q_CC_RVCT) && !defined(Q_CC_NOKIAX86)
#       undef QT_STRINGIFY2
#       undef QT_STRINGIFY
#   endif
#endif

你可能感兴趣的:(日志)