event.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * This file is part of the zlog Library.
  3. *
  4. * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING in base directory.
  7. */
  8. #ifndef __zlog_event_h
  9. #define __zlog_event_h
  10. #include <sys/types.h> /* for pid_t */
  11. #include <sys/time.h> /* for struct timeval */
  12. #include <pthread.h> /* for pthread_t */
  13. #include <stdarg.h> /* for va_list */
  14. #include "zc_defs.h"
  15. typedef enum {
  16. ZLOG_FMT = 0,
  17. ZLOG_HEX = 1,
  18. } zlog_event_cmd;
  19. typedef struct zlog_time_cache_s {
  20. char str[MAXLEN_CFG_LINE + 1];
  21. size_t len;
  22. time_t sec;
  23. } zlog_time_cache_t;
  24. typedef struct {
  25. char *category_name;
  26. size_t category_name_len;
  27. char host_name[256 + 1];
  28. size_t host_name_len;
  29. const char *file;
  30. size_t file_len;
  31. const char *func;
  32. size_t func_len;
  33. long line;
  34. int level;
  35. const void *hex_buf;
  36. size_t hex_buf_len;
  37. const char *str_format;
  38. va_list str_args;
  39. zlog_event_cmd generate_cmd;
  40. struct timeval time_stamp;
  41. time_t time_local_sec;
  42. struct tm time_local;
  43. zlog_time_cache_t *time_caches;
  44. int time_cache_count;
  45. pid_t pid;
  46. pid_t last_pid;
  47. char pid_str[30 + 1];
  48. size_t pid_str_len;
  49. pthread_t tid;
  50. char tid_str[30 + 1];
  51. size_t tid_str_len;
  52. char tid_hex_str[30 + 1];
  53. size_t tid_hex_str_len;
  54. #if defined __linux__ || __APPLE__
  55. pid_t ktid;
  56. char ktid_str[30+1];
  57. size_t ktid_str_len;
  58. #endif
  59. } zlog_event_t;
  60. zlog_event_t *zlog_event_new(int time_cache_count);
  61. void zlog_event_del(zlog_event_t * a_event);
  62. void zlog_event_profile(zlog_event_t * a_event, int flag);
  63. void zlog_event_set_fmt(zlog_event_t * a_event,
  64. char *category_name, size_t category_name_len,
  65. const char *file, size_t file_len, const char *func, size_t func_len, long line, int level,
  66. const char *str_format, va_list str_args);
  67. void zlog_event_set_hex(zlog_event_t * a_event,
  68. char *category_name, size_t category_name_len,
  69. const char *file, size_t file_len, const char *func, size_t func_len, long line, int level,
  70. const void *hex_buf, size_t hex_buf_len);
  71. #endif