spec.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_spec_h
  9. #define __zlog_spec_h
  10. #include "event.h"
  11. #include "buf.h"
  12. #include "thread.h"
  13. typedef struct zlog_spec_s zlog_spec_t;
  14. /* write buf, according to each spec's Conversion Characters */
  15. typedef int (*zlog_spec_write_fn) (zlog_spec_t * a_spec,
  16. zlog_thread_t * a_thread,
  17. zlog_buf_t * a_buf);
  18. /* gen a_thread->msg or gen a_thread->path by using write_fn */
  19. typedef int (*zlog_spec_gen_fn) (zlog_spec_t * a_spec,
  20. zlog_thread_t * a_thread);
  21. struct zlog_spec_s {
  22. char *str;
  23. int len;
  24. char time_fmt[MAXLEN_CFG_LINE + 1];
  25. int time_cache_index;
  26. char mdc_key[MAXLEN_PATH + 1];
  27. char print_fmt[MAXLEN_CFG_LINE + 1];
  28. int left_adjust;
  29. int left_fill_zeros;
  30. size_t max_width;
  31. size_t min_width;
  32. zlog_spec_write_fn write_buf;
  33. zlog_spec_gen_fn gen_msg;
  34. zlog_spec_gen_fn gen_path;
  35. zlog_spec_gen_fn gen_archive_path;
  36. };
  37. zlog_spec_t *zlog_spec_new(char *pattern_start, char **pattern_end, int * time_cache_count);
  38. void zlog_spec_del(zlog_spec_t * a_spec);
  39. void zlog_spec_profile(zlog_spec_t * a_spec, int flag);
  40. #define zlog_spec_gen_msg(a_spec, a_thread) \
  41. a_spec->gen_msg(a_spec, a_thread)
  42. #define zlog_spec_gen_path(a_spec, a_thread) \
  43. a_spec->gen_path(a_spec, a_thread)
  44. #define zlog_spec_gen_archive_path(a_spec, a_thread) \
  45. a_spec->gen_archive_path(a_spec, a_thread)
  46. #endif