Browse Source

ttail_logline2date() implementation

Yann Weber 7 years ago
parent
commit
e2d2d7f0db
3 changed files with 18 additions and 17 deletions
  1. 1
    15
      src/include/ttail_search.h
  2. 5
    0
      src/ttail_init.c
  3. 12
    2
      src/ttail_search.c

+ 1
- 15
src/include/ttail_search.h View File

74
  *@param ttail_t* ttail
74
  *@param ttail_t* ttail
75
  *@param const char* logline
75
  *@param const char* logline
76
  *@param struct tm* tm will be set to extracted date if not NULL
76
  *@param struct tm* tm will be set to extracted date if not NULL
77
- *@return 0 if ok, -1 if error
77
+ *@return 0 if ok, -1 if error 1 if no date found
78
  */
78
  */
79
 int ttail_logline2date(ttail_t*, const char*, struct tm*);
79
 int ttail_logline2date(ttail_t*, const char*, struct tm*);
80
 
80
 
85
  */
85
  */
86
 const char* ttail_logline_subst(ttail_t*, const char*);
86
 const char* ttail_logline_subst(ttail_t*, const char*);
87
 
87
 
88
-/**@brief Regex logline prefix substitution
89
- *@param ttail_t* ttail
90
- *@param const char* logline
91
- *@return a pointer on the end of the subst string
92
- */
93
-const char* _ttail_logline_subst_re(ttail_t*, const char*);
94
-
95
-/**@brief Static len logline prefix substitution
96
- *@param ttail_t* ttail
97
- *@param const char* logline
98
- *@return a pointer on the end of the subst string
99
- */
100
-const char* _ttail_logline_subst_len(ttail_t*, const char*);
101
-
102
 #endif
88
 #endif

+ 5
- 0
src/ttail_init.c View File

159
 		fprintf(stderr, "No date format set nor detected. Abording.\n");
159
 		fprintf(stderr, "No date format set nor detected. Abording.\n");
160
 		return -1;
160
 		return -1;
161
 	}
161
 	}
162
+	else if(!t->fmt)
163
+	{
164
+		fprintf(stderr, "Date format flag set but no format found\n");
165
+		return -1;
166
+	}
162
 	return 0;
167
 	return 0;
163
 }
168
 }
164
 
169
 

+ 12
- 2
src/ttail_search.c View File

28
 
28
 
29
 int ttail_logline2date(ttail_t* ttail, const char* logline, struct tm* tm)
29
 int ttail_logline2date(ttail_t* ttail, const char* logline, struct tm* tm)
30
 {
30
 {
31
-	ttail_logline_subst(ttail, logline);
32
-	return 0;
31
+	const char *subst, *ret;
32
+
33
+	memset(tm, 0,sizeof(struct tm));
34
+
35
+	subst = ttail_logline_subst(ttail, logline);
36
+	if(!subst)
37
+	{
38
+		return 1;
39
+	}
40
+	fprintf(stderr, "FORMAT : %s\n", ttail->fmt);
41
+	ret = strptime(subst, ttail->fmt, tm);
42
+	return ret?0:1;
33
 }
43
 }
34
 
44
 
35
 const char* ttail_logline_subst(ttail_t* t, const char* logline)
45
 const char* ttail_logline_subst(ttail_t* t, const char* logline)

Loading…
Cancel
Save