Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion spectator/registry.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#include <registry.h>

// Not exposed by registry.h on purpose: keeping <logger.h> out of the public
// header keeps spdlog and the spectator::Logger name out of consumers.
#include <logger.h>

namespace spectator {

void SetLogLevel(spdlog::level::level_enum level)
{
// GetLogger() yields nullptr when spdlog initialization failed.
if (auto* logger = Logger::GetLogger(); logger != nullptr)
{
logger->set_level(level);
}
}

std::pair<std::string, int> ParseUdpAddress(const std::string& address)
std::pair<std::string, int> ParseUdpAddress(const std::string& address)
{
std::regex pattern("udp://([0-9.]+):(\\d+)");
std::smatch matches;
Expand Down
10 changes: 9 additions & 1 deletion spectator/registry.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

#include <config.h>
#include <logger.h>
#include <meter_id.h>
#include <meter_types.h>
#include <writer.h>

// Only for spdlog::level::level_enum. Deliberately not <logger.h>, which would
// also drag in spdlog/async.h, fmt, and the spectator::Logger name.
#include <spdlog/common.h>

#include <memory>
#include <string>
#include <map>
Expand All @@ -15,6 +18,11 @@

namespace spectator {

// Sets the severity threshold of the spectator logger. Lets callers adjust
// logging without including <logger.h>, so spectator::Logger stays out of
// consumers' namespaces. No-op if the logger failed to initialize.
void SetLogLevel(spdlog::level::level_enum level);

class Registry
{
public:
Expand Down
Loading