datactl/loginternal.h
datactl/loginternal.h
Namespaces
| Name |
|---|
| Syntalos |
| Syntalos::datactl |
Classes
| Name | |
|---|---|
| struct | Syntalos::datactl::LogCategory A named log category with a per-instance severity threshold. |
Defines
| Name | |
|---|---|
| SY_DEFINE_LOG_CATEGORY(varname, catname) | |
| SY_DECLARE_LOG_CATEGORY(varname) | |
| SY_LOG(cat, sev, …) | |
| SY_LOG_DEBUG(cat, …) | |
| SY_LOG_INFO(cat, …) | |
| SY_LOG_WARNING(cat, …) | |
| SY_LOG_CRITICAL(cat, …) |
Macros Documentation
define SY_DEFINE_LOG_CATEGORY
#define SY_DEFINE_LOG_CATEGORY(
varname,
catname
)
static ::Syntalos::datactl::LogCategory varname(catname)Define a file-local log category.
The category self-registers in the global list at static-init time.
define SY_DECLARE_LOG_CATEGORY
#define SY_DECLARE_LOG_CATEGORY(
varname
)
extern ::Syntalos::datactl::LogCategory varnameForward-declare a log category for use from a header.
define SY_LOG
#define SY_LOG(
cat,
sev,
...
)
do { \
if (::Syntalos::datactl::shouldLog((cat), (sev))) \
::Syntalos::datactl::dispatchLog((cat), (sev), __FILE__, __LINE__, __func__, std::format(__VA_ARGS__)); \
} while (0)define SY_LOG_DEBUG
#define SY_LOG_DEBUG(
cat,
...
)
SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Debug, __VA_ARGS__)define SY_LOG_INFO
#define SY_LOG_INFO(
cat,
...
)
SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Info, __VA_ARGS__)define SY_LOG_WARNING
#define SY_LOG_WARNING(
cat,
...
)
SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Warning, __VA_ARGS__)define SY_LOG_CRITICAL
#define SY_LOG_CRITICAL(
cat,
...
)
SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Critical, __VA_ARGS__)Source code
/*
* Copyright (C) 2025-2026 Matthias Klumpp <matthias@tenstral.net>
*
* Licensed under the GNU Lesser General Public License Version 3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the license, or
* (at your option) any later version.
*
* This software 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
// Internal logging helpers for use only within the syntalos-datactl library.
// Not part of the public API.
#pragma once
#include <atomic>
#include <format>
#include <string>
#include "logging.h"
namespace Syntalos::datactl
{
struct LogCategory {
const char *name;
std::atomic<int> threshold;
LogCategory *next = nullptr;
explicit LogCategory(const char *name, LogSeverity defaultSeverity = LogSeverity::Info) noexcept;
};
extern std::atomic<LogCategory *> g_categoryListHead;
extern std::atomic<bool> g_handlerActive;
inline bool shouldLog(const LogCategory &c, LogSeverity s) noexcept
{
return g_handlerActive.load(std::memory_order_acquire) && int(s) >= c.threshold.load(std::memory_order_relaxed);
}
void dispatchLog(
const LogCategory &cat,
LogSeverity sev,
const char *file,
int line,
const char *function,
const std::string &message);
} // namespace Syntalos::datactl
#define SY_DEFINE_LOG_CATEGORY(varname, catname) static ::Syntalos::datactl::LogCategory varname(catname)
#define SY_DECLARE_LOG_CATEGORY(varname) extern ::Syntalos::datactl::LogCategory varname
#define SY_LOG(cat, sev, ...) \
do { \
if (::Syntalos::datactl::shouldLog((cat), (sev))) \
::Syntalos::datactl::dispatchLog((cat), (sev), __FILE__, __LINE__, __func__, std::format(__VA_ARGS__)); \
} while (0)
#define SY_LOG_DEBUG(cat, ...) SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Debug, __VA_ARGS__)
#define SY_LOG_INFO(cat, ...) SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Info, __VA_ARGS__)
#define SY_LOG_WARNING(cat, ...) SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Warning, __VA_ARGS__)
#define SY_LOG_CRITICAL(cat, ...) SY_LOG((cat), ::Syntalos::datactl::LogSeverity::Critical, __VA_ARGS__)Updated on 2026-04-24 at 06:25:18 +0000