LightLog.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef LIGHTLOG_H
  2. #define LIGHTLOG_H
  3. #include <QDebug>
  4. #include <QDateTime>
  5. // #define LOG_DEBUG(msg) do{ QString file = __FILE__; qDebug("[%s] [ %s:%d ] %s", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str() , file.right(file.count() - file.lastIndexOf('/') -1).toStdString().c_str() , __LINE__ , msg); }while(0)
  6. // #define LOG_INFO(msg) do{ QString file = __FILE__; qInfo("[%s] [ %s:%d ] %s", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str() , file.right(file.count() - file.lastIndexOf('/') -1).toStdString().c_str() , __LINE__ , msg); }while(0)
  7. // #define LOG_WARN(msg) do{ QString file = __FILE__; qWarning("[%s] [ %s:%d ] %s", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str() , file.right(file.count() - file.lastIndexOf('/') -1).toStdString().c_str() , __LINE__ , msg); }while(0)
  8. // #define LOG_DEBUG(_log_msg) do{ QString _log_file = __FILE__; QString _log_str = '[' + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + ']' + '[' + _log_file.right(file.count() - _log_file.lastIndexOf('/') -1) + ':' + QString::number(__LINE__) + "] " + _log_msg; qDebug() << _log_str; }while(0)
  9. // #define LOG_INFO(_log_msg) do{ QString _log_file = __FILE__; QString _log_str = '[' + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + ']' + '[' + _log_file.right(file.count() - _log_file.lastIndexOf('/') -1) + ':' + QString::number(__LINE__) + "] " + _log_msg; qInfo() << _log_str; }while(0)
  10. // #define LOG_WARN(_log_msg) do{ QString _log_file = __FILE__; QString _log_str = '[' + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + ']' + '[' + _log_file.right(file.count() - _log_file.lastIndexOf('/') -1) + ':' + QString::number(__LINE__) + "] " + _log_msg; qWarning() << _log_str; }while(0)
  11. /********** LOG_DEBUG **********/
  12. #define QLOG_DEBUG(_log_msg) \
  13. do { \
  14. QString _log_file = __FILE__; \
  15. QString _log_str = '[' + \
  16. QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") \
  17. + ']' + '[' + \
  18. _log_file.right(_log_file.count() - _log_file.lastIndexOf('/') -1) \
  19. + ':' + \
  20. QString::number(__LINE__) + "] " + _log_msg; \
  21. qDebug() << _log_str; \
  22. } while(0)
  23. /********** LOG_INFO **********/
  24. #define QLOG_INFO(_log_msg) \
  25. do { \
  26. QString _log_file = __FILE__; \
  27. QString _log_str = \
  28. '[' + \
  29. QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + \
  30. ']' + '[' + \
  31. _log_file.right(_log_file.count() - _log_file.lastIndexOf('/') - 1) \
  32. + ':' + \
  33. QString::number(__LINE__) + "] " + _log_msg; \
  34. qInfo() << _log_str; \
  35. } while (0)
  36. /********** LOG_WARN **********/
  37. #define QLOG_WARN(_log_msg) \
  38. do { \
  39. QString _log_file = __FILE__; \
  40. QString _log_str = \
  41. '[' + \
  42. QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") + \
  43. ']' + '[' + \
  44. _log_file.right(_log_file.count() - _log_file.lastIndexOf('/') - 1) \
  45. + ':' + \
  46. QString::number(__LINE__) + "] " + _log_msg; \
  47. qWarning() << _log_str; \
  48. } while (0)
  49. // void hello()
  50. // {
  51. // QString file = __FILE__;
  52. // file.lastIndexOf('/');
  53. // file.right(file.count() - file.lastIndexOf('/')).toStdString().c_str();
  54. // QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
  55. // qInfo("[%s] [ %s:%d ] %s", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toStdString().c_str() , file.right(file.count() - file.lastIndexOf('/') -1).toStdString().c_str() , __LINE__ , "hello");
  56. // }
  57. #endif /* LIGHTLOG_H */