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.

ttail.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2017 Yann Weber
  3. *
  4. * This file is part of Ttail.
  5. *
  6. * Ttail is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * Ttail is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Ttail. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _ttail_h__
  20. #define _ttail_h__
  21. #include <ctype.h>
  22. #include <errno.h>
  23. #include <getopt.h>
  24. #include <regex.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <sys/types.h>
  29. #include <time.h>
  30. #include <unistd.h>
  31. typedef struct _ttail_s ttail_t;
  32. #include "config.h"
  33. #include "ttail_search.h"
  34. #define TTAIL_FLAG_PREFIX 1
  35. #define TTAIL_FLAG_DATE_MIN 2
  36. #define TTAIL_FLAG_DATE_MAX 4
  37. #define TTAIL_FLAG_FORMAT 8
  38. #define TTAIL_FLAG_EXTENDED_RE 16
  39. #define TTAIL_FLAG_CI_RE 32
  40. /**! When set indicate that ttail is in permissive mode */
  41. #define TTAIL_FLAG_PERMISSIVE 64
  42. #define TTAIL_DEFAULT_FORMATS {"%m",\
  43. "%A %B %d, %Y %H:%M:%S",\
  44. "%A",\
  45. "%B%n%d %H:%M:%S",\
  46. "%B%n%d %H:%M",\
  47. "%m/%d/%y %I %p",\
  48. "%d,%m,%Y %H:%M",\
  49. "at %A the %dst of %B in %Y",\
  50. "run job at %I %p,%B %dnd",\
  51. "%A den %d. %B %Y %H.%M Uhr",\
  52. "%c",\
  53. "%d/%B/%Y:%H:%M:%S",\
  54. "%d/%B/%Y:%H:%M",\
  55. "%d/%m/%Y:%H:%M:%S",\
  56. "%d/%m/%Y:%H:%M",\
  57. "%y/%m/%d",\
  58. "%Y/%m/%d",\
  59. "%y-%m-%d",\
  60. "%Y/%m/%d:%H:%M",NULL}
  61. #define ttail_permissive(t) ( t->flag & TTAIL_FLAG_PERMISSIVE )
  62. #define ttail_strict_msg() fprintf(stderr, "This error can be non-fatal using \
  63. -P --permissive flag\n")
  64. struct _ttail_s
  65. {
  66. char **logfile_name; /*!< logfiles name */
  67. FILE **logfile; /*!< logfiles pointers */
  68. size_t logfile_sz; /*<! logfiles count */
  69. /*! A regex matching the datetime prefix in loglines */
  70. regex_t date_prefix;
  71. /*! An alternative to regex is to give a constant number of char
  72. to delete */
  73. int prefix_sz;
  74. /*! A strptime format matching datetime in logfile */
  75. char *fmt;
  76. /*! Date min set from cli */
  77. struct tm date_min;
  78. struct tm date_max;
  79. int verbose;
  80. /**@brief Status flag
  81. *
  82. *see TTAIL_FLAG_*
  83. */
  84. int flag;
  85. ttail_search_t *session;
  86. };
  87. #endif