Commit 3fd32d95 authored by Hardy Simpson's avatar Hardy Simpson

bugfix: the last fix for check for time cache is not correct

still https://github.com/HardySimpson/zlog/issues/13
parent 76100a06
......@@ -540,20 +540,19 @@ $ sudo ldconfig
\end_layout
\begin_layout LyX-Code
$ make 32bit /* 32bit version on 64bit machine, libc6-dev-i386 is needed
*/
$ make 32bit # 32bit version on 64bit machine, libc6-dev-i386 is needed
\end_layout
\begin_layout LyX-Code
$ make noopt /* without gcc optimization */
$ make noopt # without gcc optimization
\end_layout
\begin_layout LyX-Code
$ make doc /* lyx is needed */
$ make doc # lyx and hevea is needed
\end_layout
\begin_layout LyX-Code
$ make test /* test code, which is also good example for zlog */
$ make test # test code, which is also good example for zlog
\end_layout
\begin_layout Itemize
......
......@@ -568,20 +568,19 @@ Beside normal make, these are also available:
\end_layout
\begin_layout LyX-Code
$ make 32bit /* 32bit version on 64bit machine, libc6-dev-i386 is needed
*/
$ make 32bit # 32bit version on 64bit machine, libc6-dev-i386 is needed
\end_layout
\begin_layout LyX-Code
$ make noopt /* without gcc optimization */
$ make noopt # without gcc optimization
\end_layout
\begin_layout LyX-Code
$ make doc /* lyx is needed */
$ make doc # lyx and hevea is needed
\end_layout
\begin_layout LyX-Code
$ make test /* test code, which is also good example for zlog */
$ make test # test code, which is also good example for zlog
\end_layout
\begin_layout Itemize
......@@ -1205,7 +1204,7 @@ rotate lock file = /tmp/zlog.lock
\end_layout
\begin_layout LyX-Code
default format = "%D.%ms %-6V (%c:%F:%L) - %m%n"
default format = "%d.%ms %-6V (%c:%F:%L) - %m%n"
\end_layout
\begin_layout LyX-Code
......@@ -1465,7 +1464,7 @@ This parameter is used by rules without format specified.
\end_layout
\begin_layout LyX-Code
"%D %V [%p:%F:%L] %m%n"
"%d %V [%p:%F:%L] %m%n"
\end_layout
\begin_layout Standard
......
......@@ -131,11 +131,6 @@ void zlog_event_set_fmt(zlog_event_t * a_event,
*/
a_event->pid = (pid_t) 0;
/*
* zlog_spec_write_time localtime_r & strftime
*/
a_event->time_last = a_event->time_stamp.tv_sec;
/* in a event's life cycle, time will be get when spec need,
* and keep unchange though all event's life cycle
* zlog_spec_write_time gettimeofday
......@@ -172,11 +167,9 @@ void zlog_event_set_hex(zlog_event_t * a_event,
*/
a_event->pid = (pid_t) 0;
a_event->time_last = a_event->time_stamp.tv_sec;
/* in a event's life cycle, time will be get when spec need,
* and keep unchange though all event's life cycle
*/
memset(&(a_event->time_stamp), 0x00, sizeof(a_event->time_stamp));
a_event->time_stamp.tv_sec = 0;
return;
}
......@@ -34,6 +34,7 @@ typedef enum {
typedef struct zlog_time_cache_s {
char str[MAXLEN_CFG_LINE + 1];
size_t len;
time_t sec;
} zlog_time_cache_t;
typedef struct {
......@@ -56,8 +57,9 @@ typedef struct {
zlog_event_cmd generate_cmd;
struct timeval time_stamp;
time_t time_local_sec;
struct tm time_local;
time_t time_last;
zlog_time_cache_t *time_caches;
int time_cache_count;
......
#define ZLOG_GIT_SHA1 "b5597e79"
#define ZLOG_GIT_SHA1 "b8d15750"
#define ZLOG_GIT_DIRTY "0"
......@@ -58,22 +58,26 @@ void zlog_spec_profile(zlog_spec_t * a_spec, int flag)
static int zlog_spec_write_time(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
{
zlog_time_cache_t * a_cache;
zlog_time_cache_t * a_cache = a_thread->event->time_caches + a_spec->time_cache_index;
time_t now_sec = a_thread->event->time_stamp.tv_sec;
struct tm *time_local = &(a_thread->event->time_local);
a_cache = a_thread->event->time_caches + a_spec->time_cache_index;
if (!a_thread->event->time_stamp.tv_sec) {
/* the event meet the 1st time_spec in his life cycle */
if (!now_sec) {
gettimeofday(&(a_thread->event->time_stamp), NULL);
now_sec = a_thread->event->time_stamp.tv_sec;
}
/*
* When time slips one second, or cache is not warmed up
*/
if (a_thread->event->time_stamp.tv_sec != a_thread->event->time_last
|| a_cache->len == 0) {
localtime_r(&(a_thread->event->time_stamp.tv_sec), &(a_thread->event->time_local));
a_cache->len = strftime(a_cache->str, sizeof(a_cache->str),
a_spec->time_fmt, &(a_thread->event->time_local));
/* When this event's last cached time_local is not now */
if (a_thread->event->time_local_sec != now_sec) {
localtime_r(&(now_sec), time_local);
a_thread->event->time_local_sec = now_sec;
}
/* When this spec's last cache time string is not now */
if (a_cache->sec != now_sec) {
a_cache->len = strftime(a_cache->str, sizeof(a_cache->str), a_spec->time_fmt, time_local);
a_cache->sec = now_sec;
}
return zlog_buf_append(a_buf, a_cache->str, a_cache->len);
......
......@@ -19,6 +19,7 @@
#include <stdio.h>
#include "zlog.h"
#include <unistd.h>
int main(int argc, char** argv)
{
......@@ -38,8 +39,15 @@ int main(int argc, char** argv)
return -2;
}
zlog_info(zc, "hello, zlog");
zlog_profile();
zlog_debug(zc, "hello, zlog 1");
zlog_info(zc, "hello, zlog 2");
sleep(1);
zlog_info(zc, "hello, zlog 3");
zlog_debug(zc, "hello, zlog 4");
// zlog_profile();
zlog_fini();
......
......@@ -5,7 +5,9 @@ buffer max = 0
rotate lock file = /tmp/zlog.lock
[formats]
simple = "[%-6V]%n"
simple = "%d %V %m%n"
simple2 = "%d %V %m%n"
[rules ]
my_cat.* >stdout;simple
*.=debug >stdout;simple
*.=info >stdout;simple2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment