mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-13 20:09:59 +02:00
Split src/common/* into headers and definitions
This commit is contained in:
+5
-47
@@ -16,27 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __WINE__
|
||||
#include "../wine-host/boost-fix.h"
|
||||
#endif
|
||||
#include <boost/process/environment.hpp>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* The environment variable indicating whether to log to a file. Will log to
|
||||
* STDERR if not specified.
|
||||
*/
|
||||
constexpr char logging_file_environment_variable[] = "YABRIDGE_DEBUG_FILE";
|
||||
/**
|
||||
* The verbosity of the logging, defaults to `Logger::Verbosity::events` if
|
||||
* `logging_file_environment_variable` has been set and
|
||||
* `Logger::Verbosity::basic` otherwise.
|
||||
*
|
||||
* @see Logger::Verbosity
|
||||
*/
|
||||
constexpr char logging_verbosity_environment_variable[] =
|
||||
"YABRIDGE_DEBUG_VERBOSITY";
|
||||
#include <ostream>
|
||||
|
||||
/**
|
||||
* Super basic logging facility meant for debugging malfunctioning VST
|
||||
@@ -85,38 +65,16 @@ class Logger {
|
||||
*/
|
||||
Logger(std::ostream&& stream,
|
||||
Verbosity verbosity_level,
|
||||
std::string prefix = "")
|
||||
: stream(stream), verbosity(verbosity_level), prefix(prefix){};
|
||||
std::string prefix = "");
|
||||
|
||||
/**
|
||||
* Create a logger instance based on the set environment variables.
|
||||
* Create a logger instance based on the set environment variables. See the
|
||||
* constants in `logging.cpp` for more information.
|
||||
*
|
||||
* @param prefix A message to prepend for every log message, useful to
|
||||
* differentiate between the Wine process and the Linus VST plugin.
|
||||
*/
|
||||
static Logger create_from_environment(std::string prefix = "") {
|
||||
auto env = boost::this_process::environment();
|
||||
std::string file_path = env.get(logging_file_environment_variable);
|
||||
std::string verbosity = env.get(logging_verbosity_environment_variable);
|
||||
|
||||
// Default to `Verbosity::basic` if the environment variable has not
|
||||
// been set or if it is not an integer.
|
||||
Verbosity verbosity_level;
|
||||
try {
|
||||
verbosity_level = static_cast<Verbosity>(std::stoi(verbosity));
|
||||
} catch (const std::invalid_argument&) {
|
||||
verbosity_level = Verbosity::basic;
|
||||
}
|
||||
|
||||
// If `file` points to a valid location then use create/truncate the
|
||||
// file and write all of the logs there, otherwise use STDERR
|
||||
std::ofstream log_file(file_path, std::fstream::out);
|
||||
if (log_file.is_open()) {
|
||||
return Logger(std::move(log_file), verbosity_level, prefix);
|
||||
} else {
|
||||
return Logger(std::move(std::cerr), verbosity_level, prefix);
|
||||
}
|
||||
}
|
||||
static Logger create_from_environment(std::string prefix = "");
|
||||
|
||||
// TODO: Add dedicated logging functions for events and the Wine process's
|
||||
// STDOUT and STDERR
|
||||
|
||||
Reference in New Issue
Block a user