|
|
@ -1,15 +1,15 @@ |
|
|
|
|
|
|
|
#ifndef _GNU_SOURCE |
|
|
|
#define _GNU_SOURCE |
|
|
|
#define _GNU_SOURCE |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <string> |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
#include <stdarg.h> |
|
|
|
|
|
|
|
#include <stdbool.h> |
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
#include <string.h> |
|
|
|
#include <assert.h> |
|
|
|
#include <assert.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <pthread.h> |
|
|
|
#include <pthread.h> |
|
|
|
#include <zmq.h> |
|
|
|
#include <zmq.h> |
|
|
|
#include <json.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "json11.hpp" |
|
|
|
|
|
|
|
|
|
|
|
#include "common/timing.h" |
|
|
|
#include "common/timing.h" |
|
|
|
#include "common/version.h" |
|
|
|
#include "common/version.h" |
|
|
@ -19,7 +19,7 @@ |
|
|
|
typedef struct LogState { |
|
|
|
typedef struct LogState { |
|
|
|
pthread_mutex_t lock; |
|
|
|
pthread_mutex_t lock; |
|
|
|
bool inited; |
|
|
|
bool inited; |
|
|
|
JsonNode *ctx_j; |
|
|
|
json11::Json::object ctx_j; |
|
|
|
void *zctx; |
|
|
|
void *zctx; |
|
|
|
void *sock; |
|
|
|
void *sock; |
|
|
|
int print_level; |
|
|
|
int print_level; |
|
|
@ -30,12 +30,12 @@ static LogState s = { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static void cloudlog_bind_locked(const char* k, const char* v) { |
|
|
|
static void cloudlog_bind_locked(const char* k, const char* v) { |
|
|
|
json_append_member(s.ctx_j, k, json_mkstring(v)); |
|
|
|
s.ctx_j[k] = v; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void cloudlog_init() { |
|
|
|
static void cloudlog_init() { |
|
|
|
if (s.inited) return; |
|
|
|
if (s.inited) return; |
|
|
|
s.ctx_j = json_mkobject(); |
|
|
|
s.ctx_j = json11::Json::object {}; |
|
|
|
s.zctx = zmq_ctx_new(); |
|
|
|
s.zctx = zmq_ctx_new(); |
|
|
|
s.sock = zmq_socket(s.zctx, ZMQ_PUSH); |
|
|
|
s.sock = zmq_socket(s.zctx, ZMQ_PUSH); |
|
|
|
zmq_connect(s.sock, "ipc:///tmp/logmessage"); |
|
|
|
zmq_connect(s.sock, "ipc:///tmp/logmessage"); |
|
|
@ -58,8 +58,7 @@ static void cloudlog_init() { |
|
|
|
cloudlog_bind_locked("dongle_id", dongle_id); |
|
|
|
cloudlog_bind_locked("dongle_id", dongle_id); |
|
|
|
} |
|
|
|
} |
|
|
|
cloudlog_bind_locked("version", COMMA_VERSION); |
|
|
|
cloudlog_bind_locked("version", COMMA_VERSION); |
|
|
|
bool dirty = !getenv("CLEAN"); |
|
|
|
s.ctx_j["dirty"] = !getenv("CLEAN"); |
|
|
|
json_append_member(s.ctx_j, "dirty", json_mkbool(dirty)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s.inited = true; |
|
|
|
s.inited = true; |
|
|
|
} |
|
|
|
} |
|
|
@ -84,23 +83,19 @@ void cloudlog_e(int levelnum, const char* filename, int lineno, const char* func |
|
|
|
printf("%s: %s\n", filename, msg_buf); |
|
|
|
printf("%s: %s\n", filename, msg_buf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JsonNode *log_j = json_mkobject(); |
|
|
|
json11::Json log_j = json11::Json::object { |
|
|
|
assert(log_j); |
|
|
|
{"msg", msg_buf}, |
|
|
|
|
|
|
|
{"ctx", s.ctx_j}, |
|
|
|
json_append_member(log_j, "msg", json_mkstring(msg_buf)); |
|
|
|
{"levelnum", levelnum}, |
|
|
|
json_append_member(log_j, "ctx", s.ctx_j); |
|
|
|
{"filename", filename}, |
|
|
|
json_append_member(log_j, "levelnum", json_mknumber(levelnum)); |
|
|
|
{"lineno", lineno}, |
|
|
|
json_append_member(log_j, "filename", json_mkstring(filename)); |
|
|
|
{"funcname", func}, |
|
|
|
json_append_member(log_j, "lineno", json_mknumber(lineno)); |
|
|
|
{"created", seconds_since_epoch()} |
|
|
|
json_append_member(log_j, "funcname", json_mkstring(func)); |
|
|
|
}; |
|
|
|
json_append_member(log_j, "created", json_mknumber(seconds_since_epoch())); |
|
|
|
|
|
|
|
|
|
|
|
char* log_s = strdup(log_j.dump().c_str()); |
|
|
|
char* log_s = json_encode(log_j); |
|
|
|
|
|
|
|
assert(log_s); |
|
|
|
assert(log_s); |
|
|
|
|
|
|
|
|
|
|
|
json_remove_from_parent(s.ctx_j);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json_delete(log_j); |
|
|
|
|
|
|
|
free(msg_buf); |
|
|
|
free(msg_buf); |
|
|
|
|
|
|
|
|
|
|
|
char levelnum_c = levelnum; |
|
|
|
char levelnum_c = levelnum; |