summaryrefslogtreecommitdiffstats
path: root/src/util.cpp
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-10-15 11:35:51 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2019-01-29 10:54:56 +0900
commitb72e372690e677c38fa9b5ae90fb7fbe5a575c76 (patch)
tree5e1951052e50ef8466c8ce9ecfe7b523cb173a57 /src/util.cpp
parent231c489591095d294b93244e388abdf39debd983 (diff)
Migrate hmi-debug into util
Migrate hmi-debug into util for * simplicity * remove warnings error `-Wunused-function` Change-Id: I7d061849429e5d50cc7d19d2051c7f5d0f0ef169 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp95
1 files changed, 70 insertions, 25 deletions
diff --git a/src/util.cpp b/src/util.cpp
index e4cc2ef..26d0ef6 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -17,33 +17,15 @@
#include "util.hpp"
-#include <cerrno>
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
-#include <ctime>
+#include <time.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
#include <fstream>
#include <unistd.h>
-#include "hmi-debug.h"
-
-#ifdef SCOPE_TRACING
-thread_local int ScopeTrace::indent = 0;
-ScopeTrace::ScopeTrace(char const *func) : f(func)
-{
- fprintf(stderr, "%lu %*s%s -->\n", pthread_self(), 2 * indent++, "", this->f);
-}
-ScopeTrace::~ScopeTrace() { fprintf(stderr, "%lu %*s%s <--\n", pthread_self(), 2 * --indent, "", this->f); }
-#endif
-
-unique_fd::~unique_fd()
-{
- if (this->fd != -1)
- {
- close(this->fd);
- }
-}
+static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
void rectangle::fit(unsigned long to_width, unsigned long to_height)
{
@@ -108,7 +90,7 @@ std::string get_file_path(const char *file_name, const char *log_category)
if (!default_base_path)
{
- HMI_ERROR(log_category, "AFM_APP_INSTALL_DIR is not defined");
+ HMI_ERROR("AFM_APP_INSTALL_DIR is not defined");
}
else
{
@@ -127,6 +109,69 @@ std::string get_file_path(const char *file_name, const char *log_category)
}
i.close();
- HMI_INFO(log_category, "Using %s", path.c_str());
+ HMI_INFO("Using %s", path.c_str());
return path;
}
+void _HMI_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, const char* prefix, const char* log, ...)
+{
+ const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
+ if(log_level < level)
+ {
+ return;
+ }
+
+ char *message;
+ struct timespec tp;
+ unsigned int time;
+
+ clock_gettime(CLOCK_REALTIME, &tp);
+ time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
+
+ va_list args;
+ va_start(args, log);
+ if (log == NULL || vasprintf(&message, log, args) < 0)
+ message = NULL;
+ fprintf(stderr, "[%10.3f] [%s %s] [%s, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message);
+ va_end(args);
+ free(message);
+}
+
+void _HMI_SEQ_LOG(enum LOG_LEVEL level, const char* file, const char* func, const int line, unsigned seq_num, const char* log, ...){
+ const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR:atoi(getenv("USE_HMI_DEBUG"));
+ if(log_level < level)
+ {
+ return;
+ }
+
+ char *message;
+ struct timespec tp;
+ unsigned int time;
+
+ clock_gettime(CLOCK_REALTIME, &tp);
+ time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
+
+ va_list args;
+ va_start(args, log);
+ if (log == NULL || vasprintf(&message, log, args) < 0)
+ message = NULL;
+ fprintf(stderr, "[%10.3f] [wm %s] [%s, %s(), Line:%d] >>> req %d: %s \n", time / 1000.0, ERROR_FLAG[level], file, func, line, seq_num, message);
+ va_end(args);
+ free(message);
+}
+
+void _DUMP(enum LOG_LEVEL level, const char *log, ...)
+{
+ const int log_level = (getenv("USE_HMI_DEBUG") == NULL) ? LOG_LEVEL_ERROR : atoi(getenv("USE_HMI_DEBUG"));
+ if (log_level < level)
+ {
+ return;
+ }
+ char *message;
+ va_list args;
+ va_start(args, log);
+ if (log == NULL || vasprintf(&message, log, args) < 0)
+ message = NULL;
+ fprintf(stderr, "%s \n", message);
+ va_end(args);
+ free(message);
+}