Skip to content

Commit

Permalink
rework hb_log_stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
irov committed Feb 5, 2024
1 parent cdd962e commit 230ece9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/hb_json/hb_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string.h>
#include <memory.h>
Expand Down
9 changes: 0 additions & 9 deletions src/hb_log_console/hb_log_console.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "hb_log_console.h"
#include "hb_log_stderr.h"

#include <stdio.h>

Expand All @@ -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 )
{
Expand All @@ -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 );
}
Expand Down
9 changes: 9 additions & 0 deletions src/hb_log_stderr/hb_log_stderr.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 230ece9

Please sign in to comment.