injectors
parent
fa0e70bda4
commit
2b1086ee15
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
include(cmake/color.cmake)
|
include(cmake/color.cmake)
|
||||||
set(BLT_VERSION 5.2.8)
|
set(BLT_VERSION 5.2.9)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ namespace blt::logging
|
||||||
struct fmt_token_t;
|
struct fmt_token_t;
|
||||||
class fmt_tokenizer_t;
|
class fmt_tokenizer_t;
|
||||||
class fmt_parser_t;
|
class fmt_parser_t;
|
||||||
|
|
||||||
|
class injector_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //BLT_LOGGING_FWDDECL_H
|
#endif //BLT_LOGGING_FWDDECL_H
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLT_LOGGING_INJECTOR_H
|
||||||
|
#define BLT_LOGGING_INJECTOR_H
|
||||||
|
|
||||||
|
namespace blt::logging
|
||||||
|
{
|
||||||
|
struct injector_output_t
|
||||||
|
{
|
||||||
|
std::string new_logging_output;
|
||||||
|
// should we continue processing the injector call chain?
|
||||||
|
bool should_continue;
|
||||||
|
// should we log the resulting string at the end of the injector call chain? If false for any injector, it becomes false for all injectors.
|
||||||
|
bool should_log;
|
||||||
|
};
|
||||||
|
|
||||||
|
class injector_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~injector_t() = default;
|
||||||
|
virtual injector_output_t inject(const std::string& input) = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //BLT_LOGGING_INJECTOR_H
|
|
@ -20,6 +20,7 @@
|
||||||
#define BLT_LOGGING_LOGGING_CONFIG_H
|
#define BLT_LOGGING_LOGGING_CONFIG_H
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -133,9 +134,15 @@ namespace blt::logging
|
||||||
|
|
||||||
void compile();
|
void compile();
|
||||||
|
|
||||||
logging_config_t& add_log_output(fs::writer_t* writer)
|
logging_config_t& add_log_output(fs::writer_t& writer)
|
||||||
{
|
{
|
||||||
m_log_outputs.push_back(writer);
|
m_log_outputs.push_back(&writer);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
logging_config_t& add_injector(injector_t* injector)
|
||||||
|
{
|
||||||
|
m_injectors.push_back(std::unique_ptr<injector_t>(injector));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,8 +207,7 @@ namespace blt::logging
|
||||||
i32 line) const;
|
i32 line) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> m_log_tag_content;
|
std::vector<std::unique_ptr<injector_t>> m_injectors;
|
||||||
std::vector<tags::detail::log_tag_token_t> m_log_tag_tokens;
|
|
||||||
// wrappers for streams exist in blt/fs/stream_wrappers.h
|
// wrappers for streams exist in blt/fs/stream_wrappers.h
|
||||||
std::vector<fs::writer_t*> m_log_outputs = get_default_log_outputs();
|
std::vector<fs::writer_t*> m_log_outputs = get_default_log_outputs();
|
||||||
std::string m_log_format = get_default_log_format();
|
std::string m_log_format = get_default_log_format();
|
||||||
|
@ -219,6 +225,9 @@ namespace blt::logging
|
||||||
|
|
||||||
size_t m_longest_name_length = 0;
|
size_t m_longest_name_length = 0;
|
||||||
|
|
||||||
|
std::vector<std::string> m_log_tag_content;
|
||||||
|
std::vector<tags::detail::log_tag_token_t> m_log_tag_tokens;
|
||||||
|
|
||||||
static std::string get_default_log_format();
|
static std::string get_default_log_format();
|
||||||
static std::vector<fs::writer_t*> get_default_log_outputs();
|
static std::vector<fs::writer_t*> get_default_log_outputs();
|
||||||
static std::array<std::string, LOG_LEVEL_COUNT> get_default_log_level_colors();
|
static std::array<std::string, LOG_LEVEL_COUNT> get_default_log_level_colors();
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <blt/iterator/enumerate.h>
|
#include <blt/logging/injector.h>
|
||||||
#include <blt/logging/logging.h>
|
#include <blt/logging/logging.h>
|
||||||
#include <blt/std/hashmap.h>
|
#include <blt/std/hashmap.h>
|
||||||
#include <blt/std/types.h>
|
#include <blt/std/types.h>
|
||||||
|
|
Loading…
Reference in New Issue