A C++ library for logging very fast and without allocating.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

209 lignes
16 KiB

#pragma once
#ifdef __cplusplus
#include <cstdint>
#include <cstddef>
#include <string_view>
#include <string>
#include <functional>
#include <any>
#else
#include <stdint.h>
#include <stddef.h>
#endif
#include "sl/strategies.h"
/**
* @brief represents a buffer strategy, generally as an obscure pointer
*/
struct sl_buffer_strategy;
/**
* @brief represents a sink strategy, generally as an obscure pointer
*/
struct sl_sink_strategy;
/**
* @brief represents an overflow strategy, generally as an obscure pointer
*/
struct sl_overflow_strategy;
/**
* @brief represents an output strategy, generally as an obscure pointer
*/
struct sl_output_strategy;
#ifdef __cplusplus
namespace sl {
/**
* @brief represents a c-style buffer strategy
*/
using buffer_strategy = sl_buffer_strategy;
/**
* @brief represents a c-style sink strategy
*/
using sink_strategy = sl_sink_strategy;
/**
* @brief represents a c-style overflow strategy
*/
using overflow_strategy = sl_overflow_strategy;
/**
* @brief represents a c-style output strategy
*/
using output_strategy = sl_output_strategy;
}
template<BufferStrategy b_strategy_t, SinkStrategy s_strategy_t, OverflowStrategy over_strategy_t, OutputStrategy out_strategy_t >
void register_log(std::string_view buffer_filename, uint64_t buffer_size, uint64_t out_strategy_parameter, std::string_view output_directory);
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyInternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyShared, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyDirect, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyFastest, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyMmaped, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyWait, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategyTimed>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySized>(std::string_view, uint64_t, uint64_t, std::string_view);
template<> void register_log<BufferStrategyExternal, SinkStrategyExternal, OverflowStrategyContinue, OutputStrategySimple>(std::string_view, uint64_t, uint64_t, std::string_view);
#else
typedef struct sl_buffer_strategy sl_buffer_strategy;
typedef struct sl_sink_strategy sl_sink_strategy;
typedef struct sl_overflow_strategy sl_overflow_strategy;
typedef struct sl_output_strategy sl_output_strategy;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Constructs a buffer strategy from C
* @param strategy The type of strategy
* @param filename A file describing the strategy, ignored if SL_BUFFER_TYPE is SL_INTERNAL, optional if SL_BUFFER_TYPE is SL_SHARED
* @return a strategy token for building a logger
*/
sl_buffer_strategy* sl_create_buffer_strategy(SL_BUFFER_TYPE strategy, char *filename);
/**
* @brief Constructs a sink strategy for how to handle IO in the logger
* @param strategy The type of strategy
* @return a strategy token to build a logger
*/
sl_sink_strategy* sl_create_sink_strategy(SL_SINK_IO_TYPE strategy);
/**
* @brief Constructs an overflow strategy for how to handle the edge case of a full buffer
* @param strategy The type of strategy
* @return a strategy token to build a logger
*/
sl_overflow_strategy* sl_create_overflow_strategy(SL_ON_SINK_FULL strategy);
/**
* @brief Constructs a strategy that will direct where data is logged and how it will be split
* @param strategy The strategy to use
* @param strategy_parameter Either the amount of hours to keep in the same file, or the file size in kilobytes
* @param output_directory The directory where the logs will be written
* @return a strategy token to build a logger
*/
sl_output_strategy* sl_create_output_strategy(SL_ROLL_LOGS strategy, uint64_t strategy_parameter, char* output_directory);
/**
* @brief Constructs and registers a logger, readily available immediately
* @param internal_id The ID with which you want to refer to the logger to access it as fast as possible
* @param external_id The ID which will be part of the logs filename
* @param strategies Collect the 4 tokens and reunite them into the hero's sword that will slay every other logger
*/
void sl_register_logger(int internal_id, char* external_id, sl_buffer_strategy*, sl_sink_strategy*, sl_overflow_strategy*, sl_output_strategy*);
#ifdef __cplusplus
}
#endif