src.ctf.lttng-live: honor component's initial log level and query LL
[babeltrace.git] / src / plugins / ctf / lttng-live / viewer-connection.c
index 4a74ff9ff2a18b7d7946f60307086f8961df17b6..e81ef872e1aee965280807eb37b32be9af247c3a 100644 (file)
@@ -21,8 +21,9 @@
  * SOFTWARE.
  */
 
-#define BT_LOG_TAG "PLUGIN-CTF-LTTNG-LIVE-SRC-VIEWER"
-#include "logging.h"
+#define BT_LOG_OUTPUT_LEVEL (viewer_connection->log_level)
+#define BT_LOG_TAG "PLUGIN/SRC.CTF.LTTNG-LIVE/VIEWER"
+#include "logging/log.h"
 
 #include <stdio.h>
 #include <stdint.h>
@@ -142,7 +143,7 @@ int parse_url(struct live_viewer_connection *viewer_connection)
                lttng_live_url_parts.session_name = NULL;
        }
 
-       BT_LOGD("Connecting to hostname : %s, port : %d, "
+       BT_LOGI("Connecting to hostname : %s, port : %d, "
                        "target hostname : %s, session name : %s, "
                        "proto : %s",
                        viewer_connection->relay_hostname->str,
@@ -204,9 +205,9 @@ int lttng_live_handshake(struct live_viewer_connection *viewer_connection)
        }
        BT_ASSERT(ret_len == sizeof(connect));
 
-       BT_LOGD("Received viewer session ID : %" PRIu64,
+       BT_LOGI("Received viewer session ID : %" PRIu64,
                        (uint64_t) be64toh(connect.viewer_session_id));
-       BT_LOGD("Relayd version : %u.%u", be32toh(connect.major),
+       BT_LOGI("Relayd version : %u.%u", be32toh(connect.major),
                        be32toh(connect.minor));
 
        if (LTTNG_LIVE_MAJOR != be32toh(connect.major)) {
@@ -304,7 +305,7 @@ void connection_release(bt_object *obj)
 static
 int list_update_session(bt_value *results,
                const struct lttng_viewer_session *session,
-               bool *_found)
+               bool *_found, struct live_viewer_connection *viewer_connection)
 {
        int ret = 0;
        bt_value *map = NULL;
@@ -373,7 +374,7 @@ int list_update_session(bt_value *results,
                        }
                        val = bt_value_signed_integer_get(btval);
                        /* max */
-                       val = max_t(int64_t, clients, val);
+                       val = bt_max_t(int64_t, clients, val);
                        bt_value_signed_integer_set(btval, val);
                }
 
@@ -389,7 +390,8 @@ end:
 static
 int list_append_session(bt_value *results,
                GString *base_url,
-               const struct lttng_viewer_session *session)
+               const struct lttng_viewer_session *session,
+               struct live_viewer_connection *viewer_connection)
 {
        int ret = 0;
        bt_value_status ret_status;
@@ -401,7 +403,7 @@ int list_append_session(bt_value *results,
         * If the session already exists, add the stream count to it,
         * and do max of client counts.
         */
-       ret = list_update_session(results, session, &found);
+       ret = list_update_session(results, session, &found, viewer_connection);
        if (ret || found) {
                goto end;
        }
@@ -625,7 +627,7 @@ bt_query_status live_viewer_connection_list_sessions(
                lsession.hostname[LTTNG_VIEWER_HOST_NAME_MAX - 1] = '\0';
                lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0';
                if (list_append_session(result, viewer_connection->url,
-                               &lsession)) {
+                               &lsession, viewer_connection)) {
                        status = BT_QUERY_STATUS_ERROR;
                        goto error;
                }
@@ -690,7 +692,7 @@ int lttng_live_query_session_ids(struct lttng_live_msg_iter *lttng_live_msg_iter
                lsession.session_name[LTTNG_VIEWER_NAME_MAX - 1] = '\0';
                session_id = be64toh(lsession.id);
 
-               BT_LOGD("Adding session %" PRIu64 " hostname: %s session_name: %s",
+               BT_LOGI("Adding session %" PRIu64 " hostname: %s session_name: %s",
                        session_id, lsession.hostname, lsession.session_name);
 
                if ((strncmp(lsession.session_name,
@@ -770,7 +772,7 @@ int receive_streams(struct lttng_live_session *session,
        struct live_viewer_connection *viewer_connection =
                        lttng_live_msg_iter->viewer_connection;
 
-       BT_LOGD("Getting %" PRIu32 " new streams:", stream_count);
+       BT_LOGI("Getting %" PRIu32 " new streams:", stream_count);
        for (i = 0; i < stream_count; i++) {
                struct lttng_viewer_stream stream;
                struct lttng_live_stream_iterator *live_stream;
@@ -793,7 +795,7 @@ int receive_streams(struct lttng_live_session *session,
                ctf_trace_id = be64toh(stream.ctf_trace_id);
 
                if (stream.metadata_flag) {
-                       BT_LOGD("    metadata stream %" PRIu64 " : %s/%s",
+                       BT_LOGI("    metadata stream %" PRIu64 " : %s/%s",
                                        stream_id, stream.path_name,
                                        stream.channel_name);
                        if (lttng_live_metadata_create_stream(session,
@@ -805,7 +807,7 @@ int receive_streams(struct lttng_live_session *session,
                        }
                        session->lazy_stream_msg_init = true;
                } else {
-                       BT_LOGD("    stream %" PRIu64 " : %s/%s",
+                       BT_LOGI("    stream %" PRIu64 " : %s/%s",
                                        stream_id, stream.path_name,
                                        stream.channel_name);
                        live_stream = lttng_live_stream_iterator_create(session,
@@ -1050,9 +1052,9 @@ ssize_t lttng_live_get_one_metadata_packet(struct lttng_live_trace *trace,
                goto error;
        }
 
-       data = zmalloc(len);
+       data = calloc(1, len);
        if (!data) {
-               BT_LOGE("relay data zmalloc: %s", strerror(errno));
+               BT_LOGE("relay data calloc: %s", strerror(errno));
                goto error;
        }
        ret_len = lttng_live_recv(viewer_connection, data, len);
@@ -1478,6 +1480,7 @@ struct live_viewer_connection *live_viewer_connection_create(
                goto error;
        }
 
+       viewer_connection->log_level = lttng_live_msg_iter->log_level;
        bt_object_init_shared(&viewer_connection->obj, connection_release);
        viewer_connection->control_sock = BT_INVALID_SOCKET;
        viewer_connection->port = -1;
@@ -1488,11 +1491,11 @@ struct live_viewer_connection *live_viewer_connection_create(
                goto error;
        }
 
-       BT_LOGD("Establishing connection to url \"%s\"...", url);
+       BT_LOGI("Establishing connection to url \"%s\"...", url);
        if (lttng_live_connect_viewer(viewer_connection)) {
                goto error_report;
        }
-       BT_LOGD("Connection to url \"%s\" is established", url);
+       BT_LOGI("Connection to url \"%s\" is established", url);
        return viewer_connection;
 
 error_report:
@@ -1506,7 +1509,7 @@ BT_HIDDEN
 void live_viewer_connection_destroy(
                struct live_viewer_connection *viewer_connection)
 {
-       BT_LOGD("Closing connection to url \"%s\"", viewer_connection->url->str);
+       BT_LOGI("Closing connection to url \"%s\"", viewer_connection->url->str);
        lttng_live_disconnect_viewer(viewer_connection);
        g_string_free(viewer_connection->url, true);
        if (viewer_connection->relay_hostname) {
This page took 0.026721 seconds and 4 git commands to generate.