Configuration and logging move out of the context source

context.cpp had grown to hold three unrelated concerns: the context
lifecycle, everything about the .conf file format, and everything about
writing a log message.

conf.cpp now owns the format end to end - parsing a file into the store,
reading values back out, and interpreting a configured string as the
boolean or log level a setting holds. logging.cpp owns the write path:
the level filter, the stream choice, and the name a level carries in
output.

context.cpp keeps what a context is: resolving each setting from the
override, the configured value, or the built-in default, and reporting
what it resolved.
This commit is contained in:
2026-08-18 02:57:47 -04:00
parent 50b95fb729
commit c71913ded9
7 changed files with 429 additions and 283 deletions

61
include/internal/conf.hpp Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file conf.hpp
* @brief Reading the .conf files, and interpreting the values they carry
*
* @copyright Copyright (c) 2026 SILO GROUP LLC
* @author Chris Punches <chris.punches@silogroup.org>
*
* Part of the Dark Horse Linux Package Manager (DPM)
*
* This program 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 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
struct dpm_ctx;
namespace dpm_core {
/**
* @brief Reads every .conf file in a context's configuration directory
*
* Each file becomes one namespace in the store, named after the file
* without its extension, so core.conf fills "core" and mymodule.conf
* fills "mymodule". Files with any other extension are ignored.
*
* A missing or unreadable directory leaves the store empty, which
* leaves every setting at its default.
*
* @param ctx The libdpm-core.so context
*/
void load_config_dir(dpm_ctx* ctx);
/**
* @brief Interprets a configured boolean value
*
* @param v The configured value
* @param fallback Returned when the value matches no known spelling
* @return The interpreted boolean, or the fallback
*/
bool parse_bool(const std::string& v, bool fallback);
/**
* @brief Maps a configured log level name to its numeric level
*
* @param v The level name read from configuration
* @param fallback Returned when the name is unrecognized
* @return A DPM_LOG_* value, or the fallback
*/
int log_level_str2enum(const std::string& v, int fallback);
} // namespace dpm_core