mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Logging improvements
This commit is contained in:
parent
2e6debc04b
commit
c9af4e50ce
5 changed files with 34 additions and 27 deletions
|
|
@ -56,7 +56,7 @@ static void service_request_timeout(struct uloop_timeout *timeout)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BBFDM_ERR("Timeout occurred for request: '%s get'", tracker->service ? tracker->service->name : "unknown");
|
BBFDM_WARNING("Timeout occurred for request: '%s get'", tracker->service ? tracker->service->name : "unknown");
|
||||||
ubus_abort_request(tracker->ubus_ctx, &tracker->async_request);
|
ubus_abort_request(tracker->ubus_ctx, &tracker->async_request);
|
||||||
BBFDM_FREE(tracker);
|
BBFDM_FREE(tracker);
|
||||||
}
|
}
|
||||||
|
|
@ -89,12 +89,12 @@ static void verify_service(struct ubus_context *ubus_ctx, service_entry_t *servi
|
||||||
uint32_t id = 0;
|
uint32_t id = 0;
|
||||||
|
|
||||||
if (!ubus_ctx || !service || !service->name) {
|
if (!ubus_ctx || !service || !service->name) {
|
||||||
BBFDM_ERR("Invalid arguments");
|
BBFDM_WARNING("Invalid arguments");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ubus_lookup_id(ubus_ctx, service->name, &id)) {
|
if (ubus_lookup_id(ubus_ctx, service->name, &id)) {
|
||||||
BBFDM_ERR("Failed to lookup object: %s", service->name);
|
BBFDM_INFO("Failed to lookup object: %s", service->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,7 +116,7 @@ static void verify_service(struct ubus_context *ubus_ctx, service_entry_t *servi
|
||||||
blobmsg_add_string(&req_buf, "path", BBFDM_ROOT_OBJECT);
|
blobmsg_add_string(&req_buf, "path", BBFDM_ROOT_OBJECT);
|
||||||
|
|
||||||
if (ubus_invoke_async(ubus_ctx, id, "get", req_buf.head, &tracker->async_request)) {
|
if (ubus_invoke_async(ubus_ctx, id, "get", req_buf.head, &tracker->async_request)) {
|
||||||
BBFDM_ERR("Failed to invoke async method for object: '%s get'", service->name);
|
BBFDM_WARNING("Failed to invoke async method for object: '%s get'", service->name);
|
||||||
uloop_timeout_cancel(&tracker->timeout);
|
uloop_timeout_cancel(&tracker->timeout);
|
||||||
BBFDM_FREE(tracker);
|
BBFDM_FREE(tracker);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -169,7 +169,7 @@ static void bbfdm_ubus_add_event_cb(struct ubus_context *ctx, struct ubus_event_
|
||||||
|
|
||||||
if (path && strncmp(path, BBFDM_UBUS_OBJECT".", strlen(BBFDM_UBUS_OBJECT) + 1) == 0) {
|
if (path && strncmp(path, BBFDM_UBUS_OBJECT".", strlen(BBFDM_UBUS_OBJECT) + 1) == 0) {
|
||||||
|
|
||||||
BBFDM_ERR("Detected new service registration: '%s'", path);
|
BBFDM_INFO("Detected new service registration: '%s'", path);
|
||||||
|
|
||||||
list_for_each_entry(service, ®istered_services, list) {
|
list_for_each_entry(service, ®istered_services, list) {
|
||||||
// Check if the service is present in the registred services list
|
// Check if the service is present in the registred services list
|
||||||
|
|
@ -178,13 +178,13 @@ static void bbfdm_ubus_add_event_cb(struct ubus_context *ctx, struct ubus_event_
|
||||||
service->consecutive_timeouts = 0;
|
service->consecutive_timeouts = 0;
|
||||||
service_found = true;
|
service_found = true;
|
||||||
fill_service_schema(ctx, 5000, service->name, &service->dm_schema);
|
fill_service_schema(ctx, 5000, service->name, &service->dm_schema);
|
||||||
BBFDM_ERR("Service '%s' found in registry. Resetting blacklist and timeout counters.", path);
|
BBFDM_INFO("Service '%s' found in registry. Resetting blacklist and timeout counters.", path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!service_found) {
|
if (!service_found) {
|
||||||
BBFDM_ERR("Newly registered service '%s' is not recognized in the registry."
|
BBFDM_WARNING("Newly registered service '%s' is not recognized in the registry."
|
||||||
" Possible missing configuration JSON file under '%s'.",
|
" Possible missing configuration JSON file under '%s'.",
|
||||||
path, BBFDM_MICROSERVICE_INPUT_PATH);
|
path, BBFDM_MICROSERVICE_INPUT_PATH);
|
||||||
}
|
}
|
||||||
|
|
@ -261,12 +261,12 @@ static int bbfdm_handler_async(struct ubus_context *ctx, struct ubus_object *obj
|
||||||
bool raw_format = false;
|
bool raw_format = false;
|
||||||
|
|
||||||
if (blobmsg_parse(bbfdm_policy, __BBFDM_MAX, tb, blob_data(msg), blob_len(msg))) {
|
if (blobmsg_parse(bbfdm_policy, __BBFDM_MAX, tb, blob_data(msg), blob_len(msg))) {
|
||||||
BBFDM_ERR("Failed to parse input message");
|
BBFDM_WARNING("Failed to parse input message");
|
||||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tb[BBFDM_PATH]) {
|
if (!tb[BBFDM_PATH]) {
|
||||||
BBFDM_ERR("%s: path must be defined", method);
|
BBFDM_WARNING("%s: path must be defined", method);
|
||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,7 +282,7 @@ static int bbfdm_handler_async(struct ubus_context *ctx, struct ubus_object *obj
|
||||||
|
|
||||||
struct async_request_context *context = (struct async_request_context *)calloc(1, sizeof(struct async_request_context));
|
struct async_request_context *context = (struct async_request_context *)calloc(1, sizeof(struct async_request_context));
|
||||||
if (!context) {
|
if (!context) {
|
||||||
BBFDM_ERR("Failed to allocate memory");
|
BBFDM_WARNING("Failed to allocate memory");
|
||||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -331,12 +331,12 @@ static int bbfdm_handler_sync(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
struct blob_buf bb = {0};
|
struct blob_buf bb = {0};
|
||||||
|
|
||||||
if (blobmsg_parse(bbfdm_policy, __BBFDM_MAX, tb, blob_data(msg), blob_len(msg))) {
|
if (blobmsg_parse(bbfdm_policy, __BBFDM_MAX, tb, blob_data(msg), blob_len(msg))) {
|
||||||
BBFDM_ERR("Failed to parse input message");
|
BBFDM_WARNING("Failed to parse input message");
|
||||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tb[BBFDM_PATH]) {
|
if (!tb[BBFDM_PATH]) {
|
||||||
BBFDM_ERR("%s: path must be defined", method);
|
BBFDM_WARNING("%s: path must be defined", method);
|
||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ static void append_response_data(struct ubus_request_tracker *tracker, struct bl
|
||||||
static void handle_request_timeout(struct uloop_timeout *timeout)
|
static void handle_request_timeout(struct uloop_timeout *timeout)
|
||||||
{
|
{
|
||||||
struct ubus_request_tracker *tracker = container_of(timeout, struct ubus_request_tracker, timeout);
|
struct ubus_request_tracker *tracker = container_of(timeout, struct ubus_request_tracker, timeout);
|
||||||
BBFDM_ERR("Timeout occurred for request: '%s %s'", tracker->request_name, tracker->ctx->requested_path);
|
BBFDM_WARNING("Timeout occurred for request: '%s %s'", tracker->request_name, tracker->ctx->requested_path);
|
||||||
|
|
||||||
ubus_abort_request(tracker->ctx->ubus_ctx, &tracker->async_request);
|
ubus_abort_request(tracker->ctx->ubus_ctx, &tracker->async_request);
|
||||||
tracker->ctx->pending_requests--;
|
tracker->ctx->pending_requests--;
|
||||||
|
|
@ -92,7 +92,7 @@ static void handle_request_timeout(struct uloop_timeout *timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tracker->ctx->pending_requests == 0 && tracker->ctx->service_list_processed) {
|
if (tracker->ctx->pending_requests == 0 && tracker->ctx->service_list_processed) {
|
||||||
BBFDM_ERR("All requests completed after timeout");
|
BBFDM_WARNING("All requests completed after timeout");
|
||||||
send_response(tracker->ctx);
|
send_response(tracker->ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +141,7 @@ void run_async_call(struct async_request_context *ctx, service_entry_t *service,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ubus_lookup_id(ctx->ubus_ctx, service->name, &id)) {
|
if (ubus_lookup_id(ctx->ubus_ctx, service->name, &id)) {
|
||||||
BBFDM_ERR("Failed to lookup object: %s", service->name);
|
BBFDM_INFO("Failed to lookup object: %s", service->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +175,7 @@ void run_async_call(struct async_request_context *ctx, service_entry_t *service,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ubus_invoke_async(ctx->ubus_ctx, id, ctx->ubus_method, req_buf.head, &tracker->async_request)) {
|
if (ubus_invoke_async(ctx->ubus_ctx, id, ctx->ubus_method, req_buf.head, &tracker->async_request)) {
|
||||||
BBFDM_ERR("Failed to invoke async method for object: %s", tracker->request_name);
|
BBFDM_WARNING("Failed to invoke async method for object: %s", tracker->request_name);
|
||||||
uloop_timeout_cancel(&tracker->timeout);
|
uloop_timeout_cancel(&tracker->timeout);
|
||||||
BBFDM_FREE(tracker);
|
BBFDM_FREE(tracker);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -123,13 +123,13 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object *json_root = json_object_from_file(file_path);
|
json_object *json_root = json_object_from_file(file_path);
|
||||||
if (!json_root) {
|
if (!json_root) {
|
||||||
BBFDM_ERR("Failed to read JSON file: %s", file_path);
|
BBFDM_ERR("Failed to read JSON file: %s", file_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object *daemon_config = NULL;
|
json_object *daemon_config = NULL;
|
||||||
json_object_object_get_ex(json_root, "daemon", &daemon_config);
|
json_object_object_get_ex(json_root, "daemon", &daemon_config);
|
||||||
if (!daemon_config) {
|
if (!daemon_config) {
|
||||||
BBFDM_ERR("Failed to find daemon object");
|
BBFDM_ERR("Failed to find daemon object");
|
||||||
|
|
@ -137,7 +137,7 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object *enable_jobj = NULL;
|
json_object *enable_jobj = NULL;
|
||||||
json_object_object_get_ex(daemon_config, "enable", &enable_jobj);
|
json_object_object_get_ex(daemon_config, "enable", &enable_jobj);
|
||||||
bool enable = enable_jobj ? json_object_get_boolean(enable_jobj) : false;
|
bool enable = enable_jobj ? json_object_get_boolean(enable_jobj) : false;
|
||||||
if (!enable) {
|
if (!enable) {
|
||||||
|
|
@ -172,7 +172,7 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil
|
||||||
|
|
||||||
size_t service_count = json_object_array_length(services_array);
|
size_t service_count = json_object_array_length(services_array);
|
||||||
if (service_count == 0) {
|
if (service_count == 0) {
|
||||||
BBFDM_ERR("Skipping service '%s' due to no objects defined", service_name);
|
BBFDM_WARNING("Skipping service '%s' due to no objects defined", service_name);
|
||||||
json_object_put(json_root);
|
json_object_put(json_root);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +196,7 @@ static int load_service_from_file(struct ubus_context *ubus_ctx, const char *fil
|
||||||
snprintf(objects[num_objs].object_name, sizeof(objects[num_objs].object_name), "%s", object ? json_object_get_string(object) : "");
|
snprintf(objects[num_objs].object_name, sizeof(objects[num_objs].object_name), "%s", object ? json_object_get_string(object) : "");
|
||||||
|
|
||||||
if (strlen(objects[num_objs].parent_path) == 0 || strlen(objects[num_objs].object_name) == 0) {
|
if (strlen(objects[num_objs].parent_path) == 0 || strlen(objects[num_objs].object_name) == 0) {
|
||||||
BBFDM_ERR("Skip empty registration parent_dm[%s] or object[%s]", objects[num_objs].parent_path, objects[num_objs].object_name);
|
BBFDM_WARNING("Skip empty registration parent_dm[%s] or object[%s]", objects[num_objs].parent_path, objects[num_objs].object_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,11 +66,11 @@ int main(int argc, char **argv)
|
||||||
int res = bbfdm_print_data_model_schema(&bbfdm_ctx, dm_type);
|
int res = bbfdm_print_data_model_schema(&bbfdm_ctx, dm_type);
|
||||||
exit(res);
|
exit(res);
|
||||||
}
|
}
|
||||||
|
openlog(bbfdm_ctx.config.service_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||||
|
|
||||||
bbfdm_ubus_set_log_level(log_level);
|
bbfdm_ubus_set_log_level(log_level);
|
||||||
bbfdm_ubus_load_data_model(NULL);
|
bbfdm_ubus_load_data_model(NULL);
|
||||||
|
|
||||||
openlog(bbfdm_ctx.config.service_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
|
||||||
|
|
||||||
err = bbfdm_ubus_regiter_init(&bbfdm_ctx);
|
err = bbfdm_ubus_regiter_init(&bbfdm_ctx);
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
|
|
|
||||||
|
|
@ -779,7 +779,7 @@ int bbfdm_print_data_model_schema(struct bbfdm_context *bbfdm_ctx, const enum bb
|
||||||
|
|
||||||
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx)
|
int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0, cur_log_mask=0;
|
||||||
|
|
||||||
err = ubus_connect_ctx(&bbfdm_ctx->ubus_ctx, NULL);
|
err = ubus_connect_ctx(&bbfdm_ctx->ubus_ctx, NULL);
|
||||||
if (err != UBUS_STATUS_OK) {
|
if (err != UBUS_STATUS_OK) {
|
||||||
|
|
@ -787,6 +787,13 @@ int bbfdm_ubus_regiter_init(struct bbfdm_context *bbfdm_ctx)
|
||||||
return -5; // Error code -5 indicating that ubus_ctx is not connected
|
return -5; // Error code -5 indicating that ubus_ctx is not connected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the logmask with default, if not already set by api
|
||||||
|
cur_log_mask = setlogmask(0);
|
||||||
|
if (cur_log_mask == 0xff) {
|
||||||
|
BBF_INFO("Log level not set, setting default value %d", LOG_ERR);
|
||||||
|
bbfdm_ubus_set_log_level(LOG_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
uloop_init();
|
uloop_init();
|
||||||
ubus_add_uloop(&bbfdm_ctx->ubus_ctx);
|
ubus_add_uloop(&bbfdm_ctx->ubus_ctx);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue