rule.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  9. * @file rule.h
  10. * @brief rule decide to output in format by category & level
  11. */
  12. #ifndef __zlog_rule_h
  13. #define __zlog_rule_h
  14. #include <stdio.h>
  15. #include <pthread.h>
  16. #include "zc_defs.h"
  17. #include "format.h"
  18. #include "thread.h"
  19. #include "rotater.h"
  20. #include "record.h"
  21. typedef struct zlog_rule_s zlog_rule_t;
  22. typedef int (*zlog_rule_output_fn) (zlog_rule_t * a_rule, zlog_thread_t * a_thread);
  23. struct zlog_rule_s {
  24. char category[MAXLEN_CFG_LINE + 1];
  25. char compare_char;
  26. /*
  27. * [*] log all level
  28. * [.] log level >= rule level, default
  29. * [=] log level == rule level
  30. * [!] log level != rule level
  31. */
  32. int level;
  33. unsigned char level_bitmap[32]; /* for category determine whether ouput or not */
  34. unsigned int file_perms;
  35. int file_open_flags;
  36. char file_path[MAXLEN_PATH + 1];
  37. zc_arraylist_t *dynamic_specs;
  38. int static_fd;
  39. dev_t static_dev;
  40. ino_t static_ino;
  41. long archive_max_size;
  42. int archive_max_count;
  43. char archive_path[MAXLEN_PATH + 1];
  44. zc_arraylist_t *archive_specs;
  45. FILE *pipe_fp;
  46. int pipe_fd;
  47. size_t fsync_period;
  48. size_t fsync_count;
  49. zc_arraylist_t *levels;
  50. int syslog_facility;
  51. zlog_format_t *format;
  52. zlog_rule_output_fn output;
  53. char record_name[MAXLEN_PATH + 1];
  54. char record_path[MAXLEN_PATH + 1];
  55. zlog_record_fn record_func;
  56. };
  57. zlog_rule_t *zlog_rule_new(char * line,
  58. zc_arraylist_t * levels,
  59. zlog_format_t * default_format,
  60. zc_arraylist_t * formats,
  61. unsigned int file_perms,
  62. size_t fsync_period,
  63. int * time_cache_count);
  64. void zlog_rule_del(zlog_rule_t * a_rule);
  65. void zlog_rule_profile(zlog_rule_t * a_rule, int flag);
  66. int zlog_rule_match_category(zlog_rule_t * a_rule, char *category);
  67. int zlog_rule_is_wastebin(zlog_rule_t * a_rule);
  68. int zlog_rule_set_record(zlog_rule_t * a_rule, zc_hashtable_t *records);
  69. int zlog_rule_output(zlog_rule_t * a_rule, zlog_thread_t * a_thread);
  70. #endif