diff options
Diffstat (limited to 'src/Log.cpp')
-rw-r--r-- | src/Log.cpp | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/Log.cpp b/src/Log.cpp index e05caa21..fbcaeca1 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2016 David Robillard <http://drobilla.net/> + Copyright 2007-2024 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -14,19 +14,20 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Log.hpp" +#include <ingen/Log.hpp> -#include "ingen/ColorContext.hpp" -#include "ingen/Node.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "lv2/core/lv2.h" -#include "lv2/log/log.h" -#include "lv2/urid/urid.h" -#include "raul/Path.hpp" +#include <ingen/ColorContext.hpp> +#include <ingen/Node.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <lv2/core/lv2.h> +#include <lv2/log/log.h> +#include <lv2/urid/urid.h> +#include <raul/Path.hpp> #include <cstdio> #include <cstdlib> +#include <memory> namespace ingen { @@ -39,46 +40,44 @@ void Log::rt_error(const char* msg) { #ifndef NDEBUG - va_list args; - vtprintf(_uris.log_Error, msg, args); + tprintf(_uris.log_Error, msg); #endif } void Log::error(const std::string& msg) { - va_list args; - vtprintf(_uris.log_Error, msg.c_str(), args); + tprintf(_uris.log_Error, msg.c_str()); } void Log::warn(const std::string& msg) { - va_list args; - vtprintf(_uris.log_Warning, msg.c_str(), args); + tprintf(_uris.log_Warning, msg.c_str()); } void Log::info(const std::string& msg) { - va_list args; - vtprintf(_uris.log_Note, msg.c_str(), args); + tprintf(_uris.log_Note, msg.c_str()); } void Log::trace(const std::string& msg) { - va_list args; - vtprintf(_uris.log_Trace, msg.c_str(), args); + tprintf(_uris.log_Trace, msg.c_str()); } -void -Log::print(FILE* stream, const std::string& msg) const +int +Log::tprintf(LV2_URID type, const char* fmt, ...) { - fprintf(stream, "%s", msg.c_str()); - if (_flush) { - fflush(stdout); - } + va_list args; + va_start(args, fmt); + + const int ret = vtprintf(type, fmt, args); + + va_end(args); + return ret; } int @@ -96,16 +95,16 @@ Log::vtprintf(LV2_URID type, const char* fmt, va_list args) if (_log) { ret = _log->vprintf(_log->handle, type, fmt, args); } else if (type == _uris.log_Error) { - ColorContext ctx(stderr, ColorContext::Color::RED); + const ColorContext ctx{stderr, ColorContext::Color::RED}; ret = vfprintf(stderr, fmt, args); } else if (type == _uris.log_Warning) { - ColorContext ctx(stderr, ColorContext::Color::YELLOW); + const ColorContext ctx{stderr, ColorContext::Color::YELLOW}; ret = vfprintf(stderr, fmt, args); } else if (type == _uris.log_Note) { - ColorContext ctx(stderr, ColorContext::Color::GREEN); + const ColorContext ctx{stderr, ColorContext::Color::GREEN}; ret = vfprintf(stdout, fmt, args); } else if (_trace && type == _uris.log_Trace) { - ColorContext ctx(stderr, ColorContext::Color::GREEN); + const ColorContext ctx{stderr, ColorContext::Color::GREEN}; ret = vfprintf(stderr, fmt, args); } else { fprintf(stderr, "Unknown log type %u\n", type); @@ -120,11 +119,10 @@ Log::vtprintf(LV2_URID type, const char* fmt, va_list args) static int log_vprintf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, va_list args) { - auto* f = static_cast<Log::Feature::Handle*>(handle); - va_list noargs = {}; + auto* const f = static_cast<Log::Feature::Handle*>(handle); - int ret = f->log->vtprintf(type, f->node->path().c_str(), noargs); - ret += f->log->vtprintf(type, ": ", noargs); + int ret = f->log->tprintf(type, f->node->path().c_str()); + ret += f->log->tprintf(type, ": "); ret += f->log->vtprintf(type, fmt, args); return ret; |