switch to libosmocore multihread-logging
When osmo-remsim was originally developed, libosmocore logging was not yet thread-safe. This meant that the worker threads of remsim-bankd and remsim-server could not log via the libosmocore logging framework but directly used stderr/stdout, which produced rather inconsistent log output. However, since 1.3.0, libosmocore has received support for multi-threaded applications. Let's make use of this and consistently use it in remsim-server and remsim-bankd. This obviously also means adding some more log categories. Change-Id: I7bd5264c559b756927046563a2d00c54826bee9b
This commit is contained in:
parent
46122ab94e
commit
a9d7ad1175
|
@ -20,8 +20,8 @@
|
||||||
extern struct value_string worker_state_names[];
|
extern struct value_string worker_state_names[];
|
||||||
|
|
||||||
#define LOGW(w, fmt, args...) \
|
#define LOGW(w, fmt, args...) \
|
||||||
printf("[%03u %s] %s:%u " fmt, (w)->num, get_value_string(worker_state_names, (w)->state), \
|
LOGP(DBANKDW, LOGL_INFO, "[%03u %s] " fmt, (w)->num, get_value_string(worker_state_names, (w)->state), \
|
||||||
__FILE__, __LINE__, ## args)
|
## args)
|
||||||
|
|
||||||
struct bankd;
|
struct bankd;
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ static void bankd_init(struct bankd *bankd)
|
||||||
log_set_print_category(osmo_stderr_target, 1);
|
log_set_print_category(osmo_stderr_target, 1);
|
||||||
log_set_print_category_hex(osmo_stderr_target, 0);
|
log_set_print_category_hex(osmo_stderr_target, 0);
|
||||||
osmo_fsm_log_addr(0);
|
osmo_fsm_log_addr(0);
|
||||||
|
log_set_print_tid(osmo_stderr_target, 1);
|
||||||
|
log_enable_multithread();
|
||||||
|
|
||||||
asn_debug = 0;
|
asn_debug = 0;
|
||||||
|
|
||||||
|
|
15
src/debug.c
15
src/debug.c
|
@ -41,6 +41,21 @@ static const struct log_info_cat default_categories[] = {
|
||||||
.loglevel = LOGL_INFO,
|
.loglevel = LOGL_INFO,
|
||||||
.enabled = 1,
|
.enabled = 1,
|
||||||
},
|
},
|
||||||
|
[DREST] = {
|
||||||
|
.name = "DREST",
|
||||||
|
.loglevel = LOGL_INFO,
|
||||||
|
.enabled = 1,
|
||||||
|
},
|
||||||
|
[DSLOTMAP] = {
|
||||||
|
.name = "DSLOTMAP",
|
||||||
|
.loglevel = LOGL_INFO,
|
||||||
|
.enabled = 1,
|
||||||
|
},
|
||||||
|
[DBANKDW] = {
|
||||||
|
.name = "DBANKDW",
|
||||||
|
.loglevel = LOGL_INFO,
|
||||||
|
.enabled = 1,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct log_info log_info = {
|
const struct log_info log_info = {
|
||||||
|
|
|
@ -5,6 +5,9 @@ enum {
|
||||||
DMAIN,
|
DMAIN,
|
||||||
DST2,
|
DST2,
|
||||||
DRSPRO,
|
DRSPRO,
|
||||||
|
DREST,
|
||||||
|
DSLOTMAP,
|
||||||
|
DBANKDW,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct log_info log_info;
|
extern const struct log_info log_info;
|
||||||
|
|
|
@ -93,6 +93,8 @@ int main(int argc, char **argv)
|
||||||
log_set_print_category(osmo_stderr_target, 1);
|
log_set_print_category(osmo_stderr_target, 1);
|
||||||
log_set_print_category_hex(osmo_stderr_target, 0);
|
log_set_print_category_hex(osmo_stderr_target, 0);
|
||||||
osmo_fsm_log_addr(0);
|
osmo_fsm_log_addr(0);
|
||||||
|
log_set_print_tid(osmo_stderr_target, 1);
|
||||||
|
log_enable_multithread();
|
||||||
|
|
||||||
handle_options(argc, argv);
|
handle_options(argc, argv);
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,7 @@ static void trigger_main_thread_via_eventfd(void)
|
||||||
|
|
||||||
rc = write(g_event_ofd.fd, &one, sizeof(one));
|
rc = write(g_event_ofd.fd, &one, sizeof(one));
|
||||||
if (rc < 8)
|
if (rc < 8)
|
||||||
fprintf(stderr, "Error writing to eventfd(): %d\n", rc);
|
LOGP(DREST, LOGL_ERROR, "Error writing to eventfd(): %d\n", rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response *resp, void *user_data)
|
static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response *resp, void *user_data)
|
||||||
|
@ -318,7 +318,7 @@ static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response
|
||||||
|
|
||||||
json_req = ulfius_get_json_body_request(req, &json_err);
|
json_req = ulfius_get_json_body_request(req, &json_err);
|
||||||
if (!json_req) {
|
if (!json_req) {
|
||||||
fprintf(stderr, "REST: No JSON Body\n");
|
LOGP(DREST, LOGL_NOTICE, "REST: No JSON Body\n");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ static int api_cb_slotmaps_post(const struct _u_request *req, struct _u_response
|
||||||
goto err;
|
goto err;
|
||||||
map = slotmap_add(g_rps->slotmaps, &slotmap.bank, &slotmap.client);
|
map = slotmap_add(g_rps->slotmaps, &slotmap.bank, &slotmap.client);
|
||||||
if (!map) {
|
if (!map) {
|
||||||
fprintf(stderr, "REST: Cannot add slotmap\n");
|
LOGP(DREST, LOGL_NOTICE, "REST: Cannot add slotmap\n");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
slotmap_state_change(map, SLMAP_S_NEW, NULL);
|
slotmap_state_change(map, SLMAP_S_NEW, NULL);
|
||||||
|
@ -511,7 +511,7 @@ int rest_api_init(void *ctx, uint16_t port)
|
||||||
ulfius_add_endpoint(&g_instance, &api_endpoints[i]);
|
ulfius_add_endpoint(&g_instance, &api_endpoints[i]);
|
||||||
|
|
||||||
if (ulfius_start_framework(&g_instance) != U_OK) {
|
if (ulfius_start_framework(&g_instance) != U_OK) {
|
||||||
fprintf(stderr, "Cannot start REST API on port %u\n", port);
|
LOGP(DREST, LOGL_FATAL, "Cannot start REST API on port %u\n", port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -709,11 +709,11 @@ int event_fd_cb(struct osmo_fd *ofd, unsigned int what)
|
||||||
/* read from the socket to "confirm" the event and make it non-readable again */
|
/* read from the socket to "confirm" the event and make it non-readable again */
|
||||||
rc = read(ofd->fd, &value, 8);
|
rc = read(ofd->fd, &value, 8);
|
||||||
if (rc < 8) {
|
if (rc < 8) {
|
||||||
fprintf(stderr, "Error reading eventfd: %d\n", rc);
|
LOGP(DMAIN, LOGL_ERROR, "Error reading eventfd: %d\n", rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("rspro_server: Event FD arrived, checking for any pending work\n");
|
LOGP(DMAIN, LOGL_INFO, "Event FD arrived, checking for any pending work\n");
|
||||||
|
|
||||||
pthread_rwlock_rdlock(&srv->rwlock);
|
pthread_rwlock_rdlock(&srv->rwlock);
|
||||||
llist_for_each_entry(conn, &srv->banks, list) {
|
llist_for_each_entry(conn, &srv->banks, list) {
|
||||||
|
|
|
@ -103,14 +103,14 @@ struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *
|
||||||
|
|
||||||
map = slotmap_by_bank(maps, bank);
|
map = slotmap_by_bank(maps, bank);
|
||||||
if (map) {
|
if (map) {
|
||||||
fprintf(stderr, "BANKD %u:%u already in use, cannot add new map\n",
|
LOGP(DSLOTMAP, LOGL_ERROR, "BANKD %u:%u already in use, cannot add new map\n",
|
||||||
bank->bank_id, bank->slot_nr);
|
bank->bank_id, bank->slot_nr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
map = slotmap_by_client(maps, client);
|
map = slotmap_by_client(maps, client);
|
||||||
if (map) {
|
if (map) {
|
||||||
fprintf(stderr, "CLIENT %u:%u already in use, cannot add new map\n",
|
LOGP(DSLOTMAP, LOGL_ERROR, "CLIENT %u:%u already in use, cannot add new map\n",
|
||||||
client->client_id, client->slot_nr);
|
client->client_id, client->slot_nr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ struct slot_mapping *slotmap_add(struct slotmaps *maps, const struct bank_slot *
|
||||||
#endif
|
#endif
|
||||||
slotmaps_unlock(maps);
|
slotmaps_unlock(maps);
|
||||||
|
|
||||||
printf("Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map));
|
LOGP(DSLOTMAP, LOGL_INFO, "Slot Map %s added\n", slotmap_name(mapname, sizeof(mapname), map));
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ void _slotmap_del(struct slotmaps *maps, struct slot_mapping *map)
|
||||||
{
|
{
|
||||||
char mapname[64];
|
char mapname[64];
|
||||||
|
|
||||||
printf("Slot Map %s deleted\n", slotmap_name(mapname, sizeof(mapname), map));
|
LOGP(DSLOTMAP, LOGL_INFO, "Slot Map %s deleted\n", slotmap_name(mapname, sizeof(mapname), map));
|
||||||
|
|
||||||
llist_del(&map->list);
|
llist_del(&map->list);
|
||||||
#ifdef REMSIM_SERVER
|
#ifdef REMSIM_SERVER
|
||||||
|
|
Loading…
Reference in New Issue