timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef _ttail_h__
  2. #define _ttail_h__
  3. #include <ctype.h>
  4. #include <errno.h>
  5. #include <getopt.h>
  6. #include <regex.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <sys/types.h>
  11. #include <time.h>
  12. #include <unistd.h>
  13. #define TTAIL_FLAG_PREFIX 1
  14. #define TTAIL_FLAG_DATE_MIN 2
  15. #define TTAIL_FLAG_DATE_MAX 4
  16. #define TTAIL_FLAG_FORMAT 8
  17. #define TTAIL_DEFAULT_FORMATS {"%m", "%A %B %d, %Y %H:%M:%S", "%A", "%B", \
  18. "%m/%d/%y %I %p", "%d,%m,%Y %H:%M", "at %A the %dst of %B in %Y",\
  19. "run job at %I %p,%B %dnd", "%A den %d. %B %Y %H.%M Uhr",\
  20. "%c", "%y/%m/%d", "%Y/%m/%d", "%y-%m-%d", "%Y/%m/%d:%H:%M",NULL}
  21. struct _ttail_s
  22. {
  23. char **logfile_name; /*!< logfiles name */
  24. FILE **logfile; /*!< logfiles pointers */
  25. size_t logfile_sz; /*<! logfiles count */
  26. /*! A regex matching the datetime prefix in loglines */
  27. regex_t date_prefix;
  28. /*! A strptime format matching datetime in logfile */
  29. char *fmt;
  30. struct tm date_min;
  31. struct tm date_max;
  32. int verbose;
  33. int flag;
  34. };
  35. typedef struct _ttail_s ttail_t;
  36. /**@brief Parse cli arguments and return a ttail_t
  37. *@param int argc
  38. *@param char** argv
  39. *@return NULL on error
  40. */
  41. ttail_t *ttail_init(int argc, char **argv);
  42. /**@brief Checks that init lead to a valid runtime
  43. *@param ttail_t* t
  44. *@return 0 if no error -1 if fatal error
  45. */
  46. int ttail_init_check(ttail_t*);
  47. /**@brief Add a logfile
  48. *@param ttail_t*
  49. *@param const char * filename
  50. *@return 0 if no errors 1 if unable to open file -1 if fatal error
  51. */
  52. int ttail_add_logfile(ttail_t*, const char*);
  53. /**@brief Set a date prefix regex
  54. *@param ttail_t*
  55. *@param const char * regex
  56. *@return 0 if no errors 1 if allready set -1 if compilation fails
  57. */
  58. int ttail_set_prefix(ttail_t*, const char*);
  59. /**@brief Set dates min/max
  60. *
  61. *After the call dates are free and set to NULL except if error
  62. *@param ttail_t ttail instance
  63. *@param char*[2] dates {min,max} both can be NULL
  64. *@return -1 if error 0 else
  65. */
  66. int ttail_set_dates(ttail_t*, char*[2]);
  67. /**@brief Attempt to guess a dateformat
  68. *@param ttail_t* ttail if manage to guess set the ttail_t.fmt
  69. *@param const char* date as a dtring
  70. *@param struct tm* if non NULL will be set to detected date
  71. *@return -1 if no guess -2 if fmt already set else id in TTAIL_DEFAULT_FORMATS
  72. */
  73. int ttail_format_guess(ttail_t*, const char*, struct tm*);
  74. void ttail_free(ttail_t*);
  75. #endif