From 230ece96a711627eb134f5476cda12eff631706a Mon Sep 17 00:00:00 2001 From: irov Date: Mon, 5 Feb 2024 13:58:55 +0200 Subject: [PATCH] rework hb_log_stderr --- src/CMakeLists.txt | 2 +- src/hb_json/hb_json.c | 4 ++-- src/hb_log_console/hb_log_console.h | 9 -------- .../CMakeLists.txt | 6 ++--- .../hb_log_stderr.c} | 22 +++++++++++++++---- src/hb_log_stderr/hb_log_stderr.h | 9 ++++++++ 6 files changed, 33 insertions(+), 19 deletions(-) delete mode 100644 src/hb_log_console/hb_log_console.h rename src/{hb_log_console => hb_log_stderr}/CMakeLists.txt (66%) rename src/{hb_log_console/hb_log_console.c => hb_log_stderr/hb_log_stderr.c} (61%) create mode 100644 src/hb_log_stderr/hb_log_stderr.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e1f1a6f..a1ff5d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ ADD_SUBDIRECTORY(hb_config) ADD_SUBDIRECTORY(hb_memory) ADD_SUBDIRECTORY(hb_utils) ADD_SUBDIRECTORY(hb_log) -ADD_SUBDIRECTORY(hb_log_console) +ADD_SUBDIRECTORY(hb_log_stderr) ADD_SUBDIRECTORY(hb_log_file) ADD_SUBDIRECTORY(hb_log_tcp) ADD_SUBDIRECTORY(hb_thread) diff --git a/src/hb_json/hb_json.c b/src/hb_json/hb_json.c index 029e25e..b0d6d07 100644 --- a/src/hb_json/hb_json.c +++ b/src/hb_json/hb_json.c @@ -5,8 +5,8 @@ #include "hb_utils/hb_file.h" #include "hb_utils/hb_strncpyn.h" -#include "json.h" -#include "json_dump.h" +#include "json/json.h" +#include "json/json_dump.h" #include #include diff --git a/src/hb_log_console/hb_log_console.h b/src/hb_log_console/hb_log_console.h deleted file mode 100644 index 4bf767a..0000000 --- a/src/hb_log_console/hb_log_console.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef HB_LOG_CONSOLE_H_ -#define HB_LOG_CONSOLE_H_ - -#include "hb_log/hb_log.h" - -hb_result_t hb_log_console_initialize(); -void hb_log_console_finalize(); - -#endif diff --git a/src/hb_log_console/CMakeLists.txt b/src/hb_log_stderr/CMakeLists.txt similarity index 66% rename from src/hb_log_console/CMakeLists.txt rename to src/hb_log_stderr/CMakeLists.txt index f23e4e8..f0a9443 100644 --- a/src/hb_log_console/CMakeLists.txt +++ b/src/hb_log_stderr/CMakeLists.txt @@ -1,9 +1,9 @@ -PROJECT(hb_log_console LANGUAGES C) +PROJECT(hb_log_stderr LANGUAGES C) HUMMINGBIRD_ADD_FILTER( src - hb_log_console.h - hb_log_console.c + hb_log_stderr.h + hb_log_stderr.c ) HUMMINGBIRD_ADD_LIBRARY() diff --git a/src/hb_log_console/hb_log_console.c b/src/hb_log_stderr/hb_log_stderr.c similarity index 61% rename from src/hb_log_console/hb_log_console.c rename to src/hb_log_stderr/hb_log_stderr.c index 1523e0b..670d9af 100644 --- a/src/hb_log_console/hb_log_console.c +++ b/src/hb_log_stderr/hb_log_stderr.c @@ -1,4 +1,4 @@ -#include "hb_log_console.h" +#include "hb_log_stderr.h" #include @@ -9,10 +9,24 @@ static void __hb_log_observer( const char * _category, hb_log_level_t _level, co const char * ls = hb_log_level_string[_level]; - printf( "%s [%s:%u] %s: %s\n", ls, _file, _line, _category, _message ); + switch( _level ) + { + case HB_LOG_INFO: + case HB_LOG_WARNING: + { + fprintf( stdout, "%s [%s:%u] %s: %s\n", ls, _file, _line, _category, _message ); + }break; + case HB_LOG_ERROR: + case HB_LOG_CRITICAL: + { + fprintf( stderr, "%s [%s:%u] %s: %s\n", ls, _file, _line, _category, _message ); + }break; + default: + break; + } } ////////////////////////////////////////////////////////////////////////// -hb_result_t hb_log_console_initialize() +hb_result_t hb_log_stderr_initialize() { if( hb_log_add_observer( HB_NULLPTR, HB_LOG_ALL, &__hb_log_observer, HB_NULLPTR ) == HB_FAILURE ) { @@ -22,7 +36,7 @@ hb_result_t hb_log_console_initialize() return HB_SUCCESSFUL; } ////////////////////////////////////////////////////////////////////////// -void hb_log_console_finalize() +void hb_log_stderr_finalize() { hb_log_remove_observer( &__hb_log_observer, HB_NULLPTR ); } diff --git a/src/hb_log_stderr/hb_log_stderr.h b/src/hb_log_stderr/hb_log_stderr.h new file mode 100644 index 0000000..1da3cc8 --- /dev/null +++ b/src/hb_log_stderr/hb_log_stderr.h @@ -0,0 +1,9 @@ +#ifndef HB_LOG_STDERR_H_ +#define HB_LOG_STDERR_H_ + +#include "hb_log/hb_log.h" + +hb_result_t hb_log_stderr_initialize(); +void hb_log_stderr_finalize(); + +#endif