From 9734c83bd4664d16cb7d806ef139eb33a7fbbddc Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Fri, 12 Jun 2026 17:31:09 +0300 Subject: [PATCH] extracted base logging function into a logging_base.h --- janus/src/acap.c | 4 +- janus/src/client.c | 2 +- janus/src/config.c | 2 +- janus/src/memsinkfd.c | 3 +- janus/src/plugin.c | 6 ++- janus/src/uslibs/logging.c | 1 + janus/src/uslibs/logging.h | 1 + .../src/{logging.h => uslibs/logging_base.h} | 0 src/libs/logging.h | 16 +------ src/libs/logging_base.h | 48 +++++++++++++++++++ 10 files changed, 62 insertions(+), 21 deletions(-) create mode 120000 janus/src/uslibs/logging.c create mode 120000 janus/src/uslibs/logging.h rename janus/src/{logging.h => uslibs/logging_base.h} (100%) create mode 100644 src/libs/logging_base.h diff --git a/janus/src/acap.c b/janus/src/acap.c index 59f4e50..5a9a8e7 100644 --- a/janus/src/acap.c +++ b/janus/src/acap.c @@ -34,13 +34,13 @@ #include "uslibs/types.h" #include "uslibs/errors.h" #include "uslibs/tools.h" +#include "uslibs/threading.h" +#include "uslibs/logging.h" #include "uslibs/array.h" #include "uslibs/ring.h" -#include "uslibs/threading.h" #include "rtp.h" #include "au.h" -#include "logging.h" static void *_pcm_thread(void *v_acap); diff --git a/janus/src/client.c b/janus/src/client.c index 24aaa02..c0706a0 100644 --- a/janus/src/client.c +++ b/janus/src/client.c @@ -35,11 +35,11 @@ #include "uslibs/types.h" #include "uslibs/tools.h" #include "uslibs/threading.h" +#include "uslibs/logging.h" #include "uslibs/array.h" #include "uslibs/list.h" #include "uslibs/ring.h" -#include "logging.h" #include "au.h" #include "rtp.h" diff --git a/janus/src/config.c b/janus/src/config.c index d4358e2..c1813a0 100644 --- a/janus/src/config.c +++ b/janus/src/config.c @@ -30,9 +30,9 @@ #include "uslibs/types.h" #include "uslibs/tools.h" +#include "uslibs/logging.h" #include "const.h" -#include "logging.h" static char *_get_value(janus_config *jcfg, const char *section, const char *option); diff --git a/janus/src/memsinkfd.c b/janus/src/memsinkfd.c index 9730863..eff4ba8 100644 --- a/janus/src/memsinkfd.c +++ b/janus/src/memsinkfd.c @@ -29,11 +29,10 @@ #include "uslibs/types.h" #include "uslibs/errors.h" #include "uslibs/tools.h" +#include "uslibs/logging.h" #include "uslibs/frame.h" #include "uslibs/memsinksh.h" -#include "logging.h" - int us_memsink_fd_wait_frame(int fd, us_memsink_shared_s *mem, u64 last_id) { const ldf deadline_ts = us_get_now_monotonic() + 1; // wait_timeout diff --git a/janus/src/plugin.c b/janus/src/plugin.c index 75e4a86..21b526a 100644 --- a/janus/src/plugin.c +++ b/janus/src/plugin.c @@ -42,13 +42,13 @@ #include "uslibs/errors.h" #include "uslibs/tools.h" #include "uslibs/threading.h" +#include "uslibs/logging.h" #include "uslibs/list.h" #include "uslibs/ring.h" #include "uslibs/memsinksh.h" #include "uslibs/tc358743.h" #include "const.h" -#include "logging.h" #include "client.h" #include "au.h" #include "acap.h" @@ -430,6 +430,8 @@ static int _plugin_init(janus_callbacks *gw, const char *config_dir_path) { // sysctl -w net.core.rmem_max=1000000 // sysctl -w net.core.wmem_max=1000000 + US_LOGGING_INIT; + US_JLOG_INFO("main", "Initializing PiKVM uStreamer plugin %s ...", US_VERSION); if (gw == NULL || config_dir_path == NULL || ((_g_config = us_config_init(config_dir_path)) == NULL)) { return -1; @@ -475,6 +477,8 @@ static void _plugin_destroy(void) { US_DELETE(_g_rtpa, us_rtpa_destroy); US_DELETE(_g_rtpv, us_rtpv_destroy); US_DELETE(_g_config, us_config_destroy); + + US_LOGGING_DESTROY; } static void _plugin_create_session(janus_plugin_session *session, int *err) { diff --git a/janus/src/uslibs/logging.c b/janus/src/uslibs/logging.c new file mode 120000 index 0000000..a334984 --- /dev/null +++ b/janus/src/uslibs/logging.c @@ -0,0 +1 @@ +../../../src/libs/logging.c \ No newline at end of file diff --git a/janus/src/uslibs/logging.h b/janus/src/uslibs/logging.h new file mode 120000 index 0000000..99f7bdc --- /dev/null +++ b/janus/src/uslibs/logging.h @@ -0,0 +1 @@ +../../../src/libs/logging.h \ No newline at end of file diff --git a/janus/src/logging.h b/janus/src/uslibs/logging_base.h similarity index 100% rename from janus/src/logging.h rename to janus/src/uslibs/logging_base.h diff --git a/src/libs/logging.h b/src/libs/logging.h index d4d4bbd..aa2363e 100644 --- a/src/libs/logging.h +++ b/src/libs/logging.h @@ -34,6 +34,7 @@ #include "types.h" #include "tools.h" #include "threading.h" +#include "logging_base.h" enum us_log_level_t { @@ -72,20 +73,7 @@ extern pthread_mutex_t us_g_log_mutex; #define US_COLOR_RESET "\x1b[0m" -#define US_LOG_PRINTF_NOLOCK(x_label_color, x_label, x_msg_color, x_msg, ...) { \ - char m_tname_buf[US_THREAD_NAME_SIZE] = {0}; \ - us_thread_get_name(m_tname_buf); \ - if (us_g_log_colored) { \ - fprintf(stderr, US_COLOR_GRAY "-- " x_label_color x_label US_COLOR_GRAY \ - " [%.03Lf %9s]" " -- " US_COLOR_RESET x_msg_color x_msg US_COLOR_RESET, \ - us_get_now_monotonic(), m_tname_buf, ##__VA_ARGS__); \ - } else { \ - fprintf(stderr, "-- " x_label " [%.03Lf %9s] -- " x_msg, \ - us_get_now_monotonic(), m_tname_buf, ##__VA_ARGS__); \ - } \ - fputc('\n', stderr); \ - fflush(stderr); \ - } +// XXX: See the definition of US_LOG_PRINTF_NOLOCK() in logging_base.h #define US_LOG_PRINTF(x_label_color, x_label, x_msg_color, x_msg, ...) { \ US_LOGGING_LOCK; \ diff --git a/src/libs/logging_base.h b/src/libs/logging_base.h new file mode 100644 index 0000000..1956a08 --- /dev/null +++ b/src/libs/logging_base.h @@ -0,0 +1,48 @@ +/***************************************************************************** +# # +# uStreamer - Lightweight and fast MJPEG-HTTP streamer. # +# # +# Copyright (C) 2018-2024 Maxim Devaev # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +*****************************************************************************/ + + +#pragma once + +#include +#include + +#include + +#include "types.h" +#include "tools.h" +#include "threading.h" + + +#define US_LOG_PRINTF_NOLOCK(x_label_color, x_label, x_msg_color, x_msg, ...) { \ + char m_tname_buf[US_THREAD_NAME_SIZE] = {0}; \ + us_thread_get_name(m_tname_buf); \ + if (us_g_log_colored) { \ + fprintf(stderr, US_COLOR_GRAY "-- " x_label_color x_label US_COLOR_GRAY \ + " [%.03Lf %9s]" " -- " US_COLOR_RESET x_msg_color x_msg US_COLOR_RESET, \ + us_get_now_monotonic(), m_tname_buf, ##__VA_ARGS__); \ + } else { \ + fprintf(stderr, "-- " x_label " [%.03Lf %9s] -- " x_msg, \ + us_get_now_monotonic(), m_tname_buf, ##__VA_ARGS__); \ + } \ + fputc('\n', stderr); \ + fflush(stderr); \ + }