diff --git a/lib/raop.h b/lib/raop.h index 9682754..e6aaf51 100644 --- a/lib/raop.h +++ b/lib/raop.h @@ -32,18 +32,6 @@ extern "C" { #endif - -/* Define syslog style log levels */ -#define RAOP_LOG_EMERG 0 /* system is unusable */ -#define RAOP_LOG_ALERT 1 /* action must be taken immediately */ -#define RAOP_LOG_CRIT 2 /* critical conditions */ -#define RAOP_LOG_ERR 3 /* error conditions */ -#define RAOP_LOG_WARNING 4 /* warning conditions */ -#define RAOP_LOG_NOTICE 5 /* normal but significant condition */ -#define RAOP_LOG_INFO 6 /* informational */ -#define RAOP_LOG_DEBUG 7 /* debug-level messages */ - - typedef struct raop_s raop_t; typedef void (*raop_log_callback_t)(void *cls, int level, const char *msg); diff --git a/log.h b/log.h deleted file mode 100644 index b2a7de4..0000000 --- a/log.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * RPiPlay - An open-source AirPlay mirroring server for Raspberry Pi - * Copyright (C) 2019 Florian Draschbacher - * - * 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, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AIRPLAYSERVER_LOG_H -#define AIRPLAYSERVER_LOG_H - -#include -#include - -#define LEVEL_ERROR 0 -#define LEVEL_WARN 1 -#define LEVEL_INFO 2 -#define LEVEL_DEBUG 3 -#define LEVEL_VERBOSE 4 - -void log(int level, const char* format, ...) { - va_list vargs; - va_start(vargs, format); - vprintf(format, vargs); - printf("\n"); - va_end(vargs); -} - -#define LOGV(...) log(LEVEL_VERBOSE, __VA_ARGS__) -#define LOGD(...) log(LEVEL_DEBUG, __VA_ARGS__) -#define LOGI(...) log(LEVEL_INFO, __VA_ARGS__) -#define LOGW(...) log(LEVEL_WARN, __VA_ARGS__) -#define LOGE(...) log(LEVEL_ERROR, __VA_ARGS__) - - -#endif //AIRPLAYSERVER_LOG_H diff --git a/uxplay.cpp b/uxplay.cpp index a8439c4..dd47899 100644 --- a/uxplay.cpp +++ b/uxplay.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #ifdef _WIN32 /*modifications for Windows compilation */ #include @@ -51,7 +53,6 @@ # endif #endif -#include "log.h" #include "lib/raop.h" #include "lib/stream.h" #include "lib/logger.h" @@ -116,6 +117,7 @@ static bool do_append_hostname = true; static bool use_random_hw_addr = false; static unsigned short display[5] = {0}, tcp[3] = {0}, udp[3] = {0}; static bool debug_log = DEFAULT_DEBUG_LOG; +static int log_level = LOGGER_INFO; static bool bt709_fix = false; static int max_connections = 2; static unsigned short raop_port; @@ -125,6 +127,35 @@ static std::vector allowed_clients; static std::vector blocked_clients; static bool restrict_clients; +/* logging */ + +void log(int level, const char* format, ...) { + va_list vargs; + if (level > log_level) return; + switch (level) { + case 0: + case 1: + case 2: + case 3: + printf("*** ERROR: "); + break; + case 4: + printf("*** WARNING: "); + break; + default: + break; + } + va_start(vargs, format); + vprintf(format, vargs); + printf("\n"); + va_end(vargs); +} + +#define LOGD(...) log(LOGGER_DEBUG, __VA_ARGS__) +#define LOGI(...) log(LOGGER_INFO, __VA_ARGS__) +#define LOGW(...) log(LOGGER_WARNING, __VA_ARGS__) +#define LOGE(...) log(LOGGER_ERR, __VA_ARGS__) + /* 95 byte png file with a 1x1 white square (single pixel): placeholder for coverart*/ static const unsigned char empty_image[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, @@ -1092,14 +1123,14 @@ static bool check_blocked_client(char *deviceid) { // Server callbacks extern "C" void conn_init (void *cls) { open_connections++; - //LOGD("Open connections: %i", open_connections); + LOGD("Open connections: %i", open_connections); //video_renderer_update_background(1); } extern "C" void conn_destroy (void *cls) { //video_renderer_update_background(-1); open_connections--; - //LOGD("Open connections: %i", open_connections); + LOGD("Open connections: %i", open_connections); if (open_connections == 0) { remote_clock_offset = 0; if (use_audio) { @@ -1366,7 +1397,7 @@ int start_raop_server (unsigned short display[5], unsigned short tcp[3], unsigne raop_set_udp_ports(raop, udp); raop_set_log_callback(raop, log_callback, NULL); - raop_set_log_level(raop, debug_log ? RAOP_LOG_DEBUG : LOGGER_INFO); + raop_set_log_level(raop, log_level); raop_port = raop_get_port(raop); raop_start(raop, &raop_port); @@ -1493,6 +1524,8 @@ int main (int argc, char *argv[]) { } parse_arguments (argc, argv); + log_level = (debug_log ? LOGGER_DEBUG : LOGGER_INFO); + #ifdef _WIN32 /* use utf-8 terminal output; don't buffer stdout in WIN32 when debug_log = false */ SetConsoleOutputCP(CP_UTF8); if (!debug_log) { @@ -1563,7 +1596,7 @@ int main (int argc, char *argv[]) { render_logger = logger_init(); logger_set_callback(render_logger, log_callback, NULL); - logger_set_level(render_logger, debug_log ? LOGGER_DEBUG : LOGGER_INFO); + logger_set_level(render_logger, log_level); if (use_audio) { audio_renderer_init(render_logger, audiosink.c_str(), &audio_sync, &video_sync);