File indexing completed on 2024-05-19 16:50:19
0001 /***************************************************************************** 0002 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #ifndef _QTC_UTILS_LOG_H_ 0023 #define _QTC_UTILS_LOG_H_ 0024 0025 #include "utils.h" 0026 #include <stdarg.h> 0027 0028 namespace QtCurve { 0029 0030 void backtrace(); 0031 enum class LogLevel { 0032 Debug, 0033 Info, 0034 Warn, 0035 Error, 0036 Force 0037 }; 0038 0039 namespace Log { 0040 0041 LogLevel level(); 0042 0043 __attribute__((format(printf, 5, 0))) 0044 void logv(LogLevel level, const char *fname, int line, 0045 const char *func, const char *fmt, va_list ap); 0046 0047 __attribute__((format(printf, 5, 6))) 0048 void log(LogLevel level, const char *fname, int line, const char *func, 0049 const char *fmt, ...); 0050 0051 static inline bool 0052 checkLevel(LogLevel _level) 0053 { 0054 return qtcUnlikely(_level <= LogLevel::Force && _level >= level()); 0055 } 0056 0057 } 0058 } 0059 0060 #define qtcLog(__level, fmt, args...) \ 0061 do { \ 0062 using namespace QtCurve; \ 0063 LogLevel level = (__level); \ 0064 if (!Log::checkLevel(level)) { \ 0065 break; \ 0066 } \ 0067 Log::log(level, __FILE__, __LINE__, __FUNCTION__, fmt, ##args); \ 0068 } while (0) 0069 0070 #define qtcDebug(fmt, args...) qtcLog(LogLevel::Debug, fmt, ##args) 0071 #define qtcInfo(fmt, args...) qtcLog(LogLevel::Info, fmt, ##args) 0072 #define qtcWarn(fmt, args...) qtcLog(LogLevel::Warn, fmt, ##args) 0073 #define qtcError(fmt, args...) qtcLog(LogLevel::Error, fmt, ##args) 0074 #define qtcForceLog(fmt, args...) qtcLog(LogLevel::Force, fmt, ##args) 0075 0076 #endif