use skynet_now for timestamp

This commit is contained in:
Cloud Wu
2020-08-11 11:47:33 +08:00
parent c7386fe768
commit 446dafdc0b

View File

@@ -9,6 +9,7 @@
struct logger {
FILE * handle;
char * filename;
uint32_t starttime;
int close;
};
@@ -33,13 +34,14 @@ logger_release(struct logger * inst) {
#define SIZETIMEFMT 250
static const char *
timestring(char tmp[SIZETIMEFMT]) {
time_t ti;
static int
timestring(struct logger *inst, char tmp[SIZETIMEFMT]) {
uint64_t now = skynet_now();
time_t ti = now/100 + inst->starttime;
time(&ti);
struct tm *info = localtime(&ti);
strftime(tmp, SIZETIMEFMT, "%D %T ", info);
return tmp;
strftime(tmp, SIZETIMEFMT, "%D %T", info);
return now % 100;
}
static int
@@ -54,7 +56,8 @@ logger_cb(struct skynet_context * context, void *ud, int type, int session, uint
case PTYPE_TEXT:
if (inst->filename) {
char tmp[SIZETIMEFMT];
fprintf(inst->handle, "%s", timestring(tmp));
int msec = timestring(ud, tmp);
fprintf(inst->handle, "%s.%02d ", tmp, msec);
}
fprintf(inst->handle, "[:%08x] ", source);
fwrite(msg, sz , 1, inst->handle);
@@ -68,6 +71,8 @@ logger_cb(struct skynet_context * context, void *ud, int type, int session, uint
int
logger_init(struct logger * inst, struct skynet_context *ctx, const char * parm) {
const char * r = skynet_command(ctx, "STARTTIME", NULL);
inst->starttime = strtoul(r, NULL, 10);
if (parm) {
inst->handle = fopen(parm,"a");
if (inst->handle == NULL) {