Add new function to set log level.
Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
NNS_EDGE_NODE_TYPE_UNKNOWN,
} nns_edge_node_type_e;
+/**
+ * @brief Enumeration for log message.
+ */
+typedef enum {
+ NNS_EDGE_LOG_DEBUG = 0,
+ NNS_EDGE_LOG_INFO,
+ NNS_EDGE_LOG_WARNING,
+ NNS_EDGE_LOG_ERROR,
+ NNS_EDGE_LOG_FATAL,
+ NNS_EDGE_LOG_NONE
+} nns_edge_log_level_e;
+
/**
* @brief Callback for the nnstreamer edge event.
* @note This callback will suspend data stream. Do not spend too much time in the callback.
*/
int nns_edge_data_get_info (nns_edge_data_h data_h, const char *key, char **value);
+/**
+ * @brief Set the logging level. Default value is NNS_EDGE_LOG_INFO.
+ * @param[in] level The log level to print out.
+ */
+void nns_edge_set_log_level (nns_edge_log_level_e level);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-data.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-event.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-internal.c
+ ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-log.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-util.c
${NNS_EDGE_SRC_DIR}/nnstreamer-edge-queue.c
)
nns_edge_loge ("Failed to receive command, invalid command.");
return NNS_EDGE_ERROR_IO;
}
- /**
- * @todo Too many unnecessary debug messages are printed. Currently, all messages,
- * including debugs and info, are printed regardless of the log level.
- * Let's print the log message according to the log level later.
- */
- // nns_edge_logd ("Received command:%d (num:%u)", cmd->info.cmd, cmd->info.num);
+
+ nns_edge_logd ("Received command:%d (num:%u)", cmd->info.cmd, cmd->info.num);
if (cmd->info.num >= NNS_EDGE_DATA_LIMIT) {
nns_edge_loge ("Invalid request, the max memories for data transfer is %d.",
NNS_EDGE_DATA_LIMIT);
--- /dev/null
+/* SPDX-License-Identifier: Apache-2.0 */
+/**
+ * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
+ *
+ * @file nnstreamer-edge-log.c
+ * @date 20 October 2022
+ * @brief Logging functions
+ * @see https://github.com/nnstreamer/nnstreamer-edge
+ * @author Jaeyun Jung <jy1210.jung@samsung.com>
+ * @bug No known bugs except for NYI items.
+ */
+
+#include <stdarg.h>
+#include "nnstreamer-edge-log.h"
+
+#if defined(__TIZEN__)
+#include <dlog.h>
+
+#define _print_logd(...) dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__)
+#define _print_logi(...) dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__)
+#define _print_logw(...) dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__)
+#define _print_loge(...) dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__)
+#define _print_logf(...) dlog_print (DLOG_FATAL, TAG_NAME, __VA_ARGS__)
+#elif defined(__ANDROID__)
+#include <android/log.h>
+
+#define _print_logd(...) __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__)
+#define _print_logi(...) __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__)
+#define _print_logw(...) __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__)
+#define _print_loge(...) __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__)
+#define _print_logf(...) __android_log_print (ANDROID_LOG_FATAL, TAG_NAME, __VA_ARGS__)
+#else
+/**
+ * @brief Internal util function to print log message.
+ */
+static inline void
+_ne_log_print (nns_edge_log_level_e level, const char *fmt, va_list args)
+{
+ const char *level_str[] = {
+ [NNS_EDGE_LOG_DEBUG] = "DEBUG",
+ [NNS_EDGE_LOG_INFO] = "INFO",
+ [NNS_EDGE_LOG_WARNING] = "WARNING",
+ [NNS_EDGE_LOG_ERROR] = "ERROR",
+ [NNS_EDGE_LOG_FATAL] = "FATAL",
+ [NNS_EDGE_LOG_NONE] = NULL,
+ };
+
+ switch (level) {
+ case NNS_EDGE_LOG_WARNING:
+ printf ("\033[33m");
+ break;
+ case NNS_EDGE_LOG_ERROR:
+ printf ("\033[31m");
+ break;
+ case NNS_EDGE_LOG_FATAL:
+ printf ("\033[1;31m");
+ break;
+ default:
+ printf ("\033[20m");
+ break;
+ }
+
+ printf ("[%s][%s] ", level_str[level], TAG_NAME);
+ vprintf (fmt, args);
+ printf ("\n");
+ printf ("\033[0m");
+}
+
+#define _print_logd(...) _ne_log_print (NNS_EDGE_LOG_DEBUG, __VA_ARGS__)
+#define _print_logi(...) _ne_log_print (NNS_EDGE_LOG_INFO, __VA_ARGS__)
+#define _print_logw(...) _ne_log_print (NNS_EDGE_LOG_WARNING, __VA_ARGS__)
+#define _print_loge(...) _ne_log_print (NNS_EDGE_LOG_ERROR, __VA_ARGS__)
+#define _print_logf(...) _ne_log_print (NNS_EDGE_LOG_FATAL, __VA_ARGS__)
+#endif
+
+/**
+ * @brief Internal logging level.
+ */
+static nns_edge_log_level_e g_ne_log_level =
+ (DEBUG) ? NNS_EDGE_LOG_DEBUG : NNS_EDGE_LOG_INFO;
+
+/**
+ * @brief Set the logging level.
+ */
+void
+nns_edge_set_log_level (nns_edge_log_level_e level)
+{
+ g_ne_log_level = level;
+}
+
+/**
+ * @brief Internal util function to print log message.
+ */
+void
+nns_edge_print_log (nns_edge_log_level_e level, const char *fmt, ...)
+{
+ va_list args;
+
+ if (level < g_ne_log_level)
+ return;
+
+ va_start (args, fmt);
+
+ switch (level) {
+ case NNS_EDGE_LOG_DEBUG:
+ _print_logd (fmt, args);
+ break;
+ case NNS_EDGE_LOG_INFO:
+ _print_logi (fmt, args);
+ break;
+ case NNS_EDGE_LOG_WARNING:
+ _print_logw (fmt, args);
+ break;
+ case NNS_EDGE_LOG_ERROR:
+ _print_loge (fmt, args);
+ break;
+ case NNS_EDGE_LOG_FATAL:
+ _print_logf (fmt, args);
+ break;
+ default:
+ break;
+ }
+
+ va_end (args);
+}
* @see https://github.com/nnstreamer/nnstreamer-edge
* @author Jaeyun Jung <jy1210.jung@samsung.com>
* @note This file is internal header for nnstreamer-edge. DO NOT export this file.
+ * @bug No known bugs except for NYI items.
*/
#ifndef __NNSTREAMER_EDGE_LOG_H__
#define __NNSTREAMER_EDGE_LOG_H__
-#include <stdio.h>
-#include <stdarg.h>
+#include "nnstreamer-edge.h"
#ifdef __cplusplus
extern "C" {
#define TAG_NAME "nnstreamer-edge"
-#if defined(__TIZEN__)
-#include <dlog.h>
-
-#define nns_edge_logd(...) dlog_print (DLOG_DEBUG, TAG_NAME, __VA_ARGS__)
-#define nns_edge_logi(...) dlog_print (DLOG_INFO, TAG_NAME, __VA_ARGS__)
-#define nns_edge_logw(...) dlog_print (DLOG_WARN, TAG_NAME, __VA_ARGS__)
-#define nns_edge_loge(...) dlog_print (DLOG_ERROR, TAG_NAME, __VA_ARGS__)
-#define nns_edge_logf(...) dlog_print (DLOG_FATAL, TAG_NAME, __VA_ARGS__)
-#elif defined(__ANDROID__)
-#include <android/log.h>
-
-#define nns_edge_logd(...) __android_log_print (ANDROID_LOG_DEBUG, TAG_NAME, __VA_ARGS__)
-#define nns_edge_logi(...) __android_log_print (ANDROID_LOG_INFO, TAG_NAME, __VA_ARGS__)
-#define nns_edge_logw(...) __android_log_print (ANDROID_LOG_WARN, TAG_NAME, __VA_ARGS__)
-#define nns_edge_loge(...) __android_log_print (ANDROID_LOG_ERROR, TAG_NAME, __VA_ARGS__)
-#define nns_edge_logf(...) __android_log_print (ANDROID_LOG_FATAL, TAG_NAME, __VA_ARGS__)
-#else
-/**
- * @brief Internal enumeration for log message.
- */
-typedef enum {
- NE_LOG_DEBUG = 0,
- NE_LOG_INFO,
- NE_LOG_WARNING,
- NE_LOG_ERROR,
- NE_LOG_FATAL,
- NE_LOG_NONE
-} nns_edge_log_level_e;
-
/**
* @brief Internal util function to print log message.
*/
-static inline void
-nns_edge_print_log (nns_edge_log_level_e level, const char *fmt, ...)
-{
- const char *level_str[] = {
- [NE_LOG_DEBUG] = "DEBUG",
- [NE_LOG_INFO] = "INFO",
- [NE_LOG_WARNING] = "WARNING",
- [NE_LOG_ERROR] = "ERROR",
- [NE_LOG_FATAL] = "FATAL",
- [NE_LOG_NONE] = "DEBUG",
- };
-
- va_list args;
-
- /** @todo expand log util and handle log level (debug, release) */
- va_start (args, fmt);
-
- printf ("[%s][%s] ", level_str[level], TAG_NAME);
- vprintf (fmt, args);
- printf ("\n");
-
- va_end (args);
-}
+void nns_edge_print_log (nns_edge_log_level_e level, const char *fmt, ...);
-#define nns_edge_logi(...) nns_edge_print_log (NE_LOG_INFO, __VA_ARGS__)
-#define nns_edge_logw(...) nns_edge_print_log (NE_LOG_WARNING, __VA_ARGS__)
-#define nns_edge_loge(...) nns_edge_print_log (NE_LOG_ERROR, __VA_ARGS__)
-#define nns_edge_logd(...) nns_edge_print_log (NE_LOG_DEBUG, __VA_ARGS__)
-#define nns_edge_logf(...) nns_edge_print_log (NE_LOG_FATAL, __VA_ARGS__)
-#endif
+#define nns_edge_logi(...) nns_edge_print_log (NNS_EDGE_LOG_INFO, __VA_ARGS__)
+#define nns_edge_logw(...) nns_edge_print_log (NNS_EDGE_LOG_WARNING, __VA_ARGS__)
+#define nns_edge_loge(...) nns_edge_print_log (NNS_EDGE_LOG_ERROR, __VA_ARGS__)
+#define nns_edge_logd(...) nns_edge_print_log (NNS_EDGE_LOG_DEBUG, __VA_ARGS__)
+#define nns_edge_logf(...) nns_edge_print_log (NNS_EDGE_LOG_FATAL, __VA_ARGS__)
#ifdef __cplusplus
}
#define _GNU_SOURCE
#include <stdio.h>
+#include <stdarg.h>
#include "nnstreamer-edge-log.h"
#include "nnstreamer-edge-util.h"
CSRCS = src/libnnstreamer-edge/nnstreamer-edge-data.c \
src/libnnstreamer-edge/nnstreamer-edge-event.c \
src/libnnstreamer-edge/nnstreamer-edge-internal.c \
+ src/libnnstreamer-edge/nnstreamer-edge-log.c \
src/libnnstreamer-edge/nnstreamer-edge-metadata.c \
src/libnnstreamer-edge/nnstreamer-edge-queue.c \
src/libnnstreamer-edge/nnstreamer-edge-util.c
-CFLAGS += -I ./include
+CFLAGS += -I ./include -DDEBUG=0
# TODO Include sources - Paho MQTT and AITT library.
# Paho MQTT library