da_log.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DA_LOG_H_
  17. #define DA_LOG_H_
  18. #include <errno.h>
  19. #include <fcntl.h>
  20. #include <libgen.h>
  21. #include <stdarg.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <sys/stat.h>
  25. #include <sys/syscall.h>
  26. #include <sys/types.h>
  27. #include <time.h>
  28. #include <unistd.h>
  29. #include "da_util.h"
  30. extern int __log_level__;
  31. extern int __business_id__;
  32. #define log_bare(lvl, fmt, args...) _write_log_(lvl, NULL, NULL, 0, fmt, ##args)
  33. #define log_generic(lvl, fmt, args...) \
  34. _write_log_(lvl, __FILE__, __FUNCTION__, __LINE__, fmt, ##args)
  35. #define log_emerg(fmt, args...) log_generic(0, fmt, ##args)
  36. #define log_alert(fmt, args...) log_generic(1, fmt, ##args)
  37. #define log_crit(fmt, args...) log_generic(2, fmt, ##args)
  38. #define log_error(fmt, args...) log_generic(3, fmt, ##args)
  39. #define log_warning(fmt, args...) \
  40. do { \
  41. if (__log_level__ >= 4) \
  42. log_generic(4, fmt, ##args); \
  43. } while (0)
  44. #define log_notice(fmt, args...) \
  45. do { \
  46. if (__log_level__ >= 5) \
  47. log_generic(5, fmt, ##args); \
  48. } while (0)
  49. #define log_info(fmt, args...) \
  50. do { \
  51. if (__log_level__ >= 6) \
  52. log_generic(6, fmt, ##args); \
  53. } while (0)
  54. #define log_debug(fmt, args...) \
  55. do { \
  56. if (__log_level__ >= 7) \
  57. log_generic(7, fmt, ##args); \
  58. } while (0)
  59. void _init_log_(const char *app, const char *dir);
  60. void _set_log_level_(int l);
  61. void _set_log_switch_(int iSwitch);
  62. void _write_log_(int, char *, const char *, int, const char *, ...)
  63. __attribute__((format(printf, 5, 6)));
  64. int _set_remote_log_fd_();
  65. void remote_log(int type, const char *key, int op_type, int op_result,
  66. char *content, long op_time, int cmd, int magic,
  67. int contentlen);
  68. void write_stderr(const char *fmt, ...);
  69. static inline int da_gettid(void) { return syscall(__NR_gettid); }
  70. #endif /* DA_LOG_H_ */