Added optional millisecond precision to logfiles and created the changelog document.
This commit is contained in:
@ -27,12 +27,18 @@
|
||||
#include <regex.h>
|
||||
#include "skygw_debug.h"
|
||||
#include <skygw_types.h>
|
||||
#include <sys/time.h>
|
||||
#include "skygw_utils.h"
|
||||
|
||||
const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
|
||||
/** One for terminating '\0' */
|
||||
const size_t timestamp_len = (4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1) * sizeof(char);
|
||||
|
||||
|
||||
const char* timestamp_formatstr_hp = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
|
||||
/** One for terminating '\0' */
|
||||
const size_t timestamp_len_hp = (4+1 +2+1 +2+1 +2+1 +2+1 +2+1+3+3 +1) * sizeof(char);
|
||||
|
||||
/** Single-linked list for storing test cases */
|
||||
|
||||
struct slist_node_st {
|
||||
@ -667,6 +673,10 @@ size_t get_timestamp_len(void)
|
||||
return timestamp_len;
|
||||
}
|
||||
|
||||
size_t get_timestamp_len_hp(void)
|
||||
{
|
||||
return timestamp_len_hp;
|
||||
}
|
||||
/**
|
||||
* @node Generate and write a timestamp to location passed as argument
|
||||
* by using at most tslen characters.
|
||||
@ -689,15 +699,16 @@ size_t snprint_timestamp(
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
size_t rval;
|
||||
|
||||
struct timeval tv;
|
||||
if (p_ts == NULL) {
|
||||
rval = 0;
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
/** Generate timestamp */
|
||||
t = time(NULL);
|
||||
tm = *(localtime(&t));
|
||||
|
||||
gettimeofday(&tv,NULL);
|
||||
tm = *(localtime(&tv.tv_sec));
|
||||
snprintf(p_ts,
|
||||
MIN(tslen,timestamp_len),
|
||||
timestamp_formatstr,
|
||||
@ -707,7 +718,56 @@ size_t snprint_timestamp(
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec);
|
||||
rval = strlen(p_ts)*sizeof(char);
|
||||
retblock:
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @node Generate and write a timestamp to location passed as argument
|
||||
* by using at most tslen characters. This will use millisecond precision.
|
||||
*
|
||||
* Parameters:
|
||||
* @param p_ts - in, use
|
||||
* Write position in memory. Must be filled with at least
|
||||
* <timestamp_len> zeroes
|
||||
*
|
||||
* @return Length of string written to p_ts. Length includes terminating '\0'.
|
||||
*
|
||||
*
|
||||
* @details (write detailed description here)
|
||||
*
|
||||
*/
|
||||
size_t snprint_timestamp_hp(
|
||||
char* p_ts,
|
||||
size_t tslen)
|
||||
{
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
size_t rval;
|
||||
struct timeval tv;
|
||||
int usec;
|
||||
if (p_ts == NULL) {
|
||||
rval = 0;
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
/** Generate timestamp */
|
||||
|
||||
gettimeofday(&tv,NULL);
|
||||
tm = *(localtime(&tv.tv_sec));
|
||||
usec = tv.tv_usec/1000;
|
||||
snprintf(p_ts,
|
||||
MIN(tslen,timestamp_len_hp),
|
||||
timestamp_formatstr_hp,
|
||||
tm.tm_year+1900,
|
||||
tm.tm_mon+1,
|
||||
tm.tm_mday,
|
||||
tm.tm_hour,
|
||||
tm.tm_min,
|
||||
tm.tm_sec,
|
||||
usec);
|
||||
rval = strlen(p_ts)*sizeof(char);
|
||||
retblock:
|
||||
return rval;
|
||||
|
Reference in New Issue
Block a user