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
fd01662127
commit
aa48055446
5 changed files with 34 additions and 27 deletions
|
|
@ -56,7 +56,7 @@ static void service_request_timeout(struct uloop_timeout *timeout)
|
|||
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);
|
||||
BBFDM_FREE(tracker);
|
||||
}
|
||||
|
|
@ -89,12 +89,12 @@ static void verify_service(struct ubus_context *ubus_ctx, service_entry_t *servi
|
|||
uint32_t id = 0;
|
||||
|
||||
if (!ubus_ctx || !service || !service->name) {
|
||||
BBFDM_ERR("Invalid arguments");
|
||||
BBFDM_WARNING("Invalid arguments");
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
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);
|
||||
BBFDM_FREE(tracker);
|
||||
} 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) {
|
||||
|
||||
BBFDM_ERR("Detected new service registration: '%s'", path);
|
||||
BBFDM_INFO("Detected new service registration: '%s'", path);
|
||||
|
||||
list_for_each_entry(service, ®istered_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_found = true;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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'.",
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -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));
|
||||
if (!context) {
|
||||
BBFDM_ERR("Failed to allocate memory");
|
||||
BBFDM_WARNING("Failed to allocate memory");
|
||||
return UBUS_STATUS_UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -329,12 +329,12 @@ static int bbfdm_handler_sync(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
struct blob_buf bb = {0};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ static void append_response_data(struct ubus_request_tracker *tracker, struct bl
|
|||
static void handle_request_timeout(struct uloop_timeout *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);
|
||||
tracker->ctx->pending_requests--;
|
||||
|
|
@ -330,7 +330,7 @@ static void handle_request_timeout(struct uloop_timeout *timeout)
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ void run_async_call(struct async_request_context *ctx, service_entry_t *service,
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -413,7 +413,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)) {
|
||||
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);
|
||||
BBFDM_FREE(tracker);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
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);
|
||||
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) : "");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ int main(int argc, char **argv)
|
|||
int res = bbfdm_print_data_model_schema(&bbfdm_ctx, dm_type);
|
||||
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_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);
|
||||
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 err = 0;
|
||||
int err = 0, cur_log_mask=0;
|
||||
|
||||
err = ubus_connect_ctx(&bbfdm_ctx->ubus_ctx, NULL);
|
||||
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
|
||||
}
|
||||
|
||||
// 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();
|
||||
ubus_add_uloop(&bbfdm_ctx->ubus_ctx);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue