MMKVLog.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Tencent is pleased to support the open source community by making
  3. * MMKV available.
  4. *
  5. * Copyright (C) 2018 THL A29 Limited, a Tencent company.
  6. * All rights reserved.
  7. *
  8. * Licensed under the BSD 3-Clause License (the "License"); you may not use
  9. * this file except in compliance with the License. You may obtain a copy of
  10. * the License at
  11. *
  12. * https://opensource.org/licenses/BSD-3-Clause
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. #ifndef MMKV_MMKVLOG_H
  21. #define MMKV_MMKVLOG_H
  22. #ifdef __cplusplus
  23. #include "MMKVPredef.h"
  24. #include <cerrno>
  25. #include <cstdint>
  26. #include <cstring>
  27. void _MMKVLogWithLevel(
  28. MMKV_NAMESPACE_PREFIX::MMKVLogLevel level, const char *filename, const char *func, int line, const char *format, ...);
  29. MMKV_NAMESPACE_BEGIN
  30. extern MMKVLogLevel g_currentLogLevel;
  31. extern mmkv::LogHandler g_logHandler;
  32. // enable logging
  33. #define ENABLE_MMKV_LOG
  34. #ifdef ENABLE_MMKV_LOG
  35. # ifdef __FILE_NAME__
  36. # define __MMKV_FILE_NAME__ __FILE_NAME__
  37. # else
  38. const char *_getFileName(const char *path);
  39. # define __MMKV_FILE_NAME__ MMKV_NAMESPACE_PREFIX::_getFileName(__FILE__)
  40. # endif
  41. # define MMKVError(format, ...) \
  42. _MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogError, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
  43. ##__VA_ARGS__)
  44. # define MMKVWarning(format, ...) \
  45. _MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogWarning, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
  46. ##__VA_ARGS__)
  47. # define MMKVInfo(format, ...) \
  48. _MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogInfo, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
  49. ##__VA_ARGS__)
  50. # ifdef MMKV_DEBUG
  51. # define MMKVDebug(format, ...) \
  52. _MMKVLogWithLevel(MMKV_NAMESPACE_PREFIX::MMKVLogDebug, __MMKV_FILE_NAME__, __func__, __LINE__, format, \
  53. ##__VA_ARGS__)
  54. # else
  55. # define MMKVDebug(format, ...) \
  56. {}
  57. # endif
  58. #else
  59. # define MMKVError(format, ...) \
  60. {}
  61. # define MMKVWarning(format, ...) \
  62. {}
  63. # define MMKVInfo(format, ...) \
  64. {}
  65. # define MMKVDebug(format, ...) \
  66. {}
  67. #endif
  68. MMKV_NAMESPACE_END
  69. #endif
  70. #endif //MMKV_MMKVLOG_H