silly cable
parent
dbff8fd8b3
commit
66efccf095
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.20)
|
||||
include(cmake/color.cmake)
|
||||
set(BLT_VERSION 5.2.0)
|
||||
set(BLT_VERSION 5.2.1)
|
||||
|
||||
set(BLT_TARGET BLT)
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ namespace blt::fs
|
|||
{
|
||||
public:
|
||||
explicit buffered_writer(const std::string& name, size_t buffer_size = 1024 * 128);
|
||||
explicit buffered_writer(size_t buffer_size = 1024 * 128);
|
||||
|
||||
i64 write(const char* buffer, size_t bytes) override;
|
||||
|
||||
|
|
|
@ -359,15 +359,17 @@ namespace blt::nbt {
|
|||
void writePayload(blt::fs::writer_t& out) final {
|
||||
for (const auto& v : t){
|
||||
auto tag = v.second;
|
||||
out.put((char) tag->getType());
|
||||
auto c = (char) tag->getType();
|
||||
out.write(&c, 1);
|
||||
tag->writeName(out);
|
||||
tag->writePayload(out);
|
||||
}
|
||||
out.put('\0');
|
||||
const char c = '\0';
|
||||
out.write(&c, 1);
|
||||
}
|
||||
void readPayload(blt::fs::reader_t& in) final {
|
||||
char type;
|
||||
while ((type = in.get()) != (char)nbt_tag::END){
|
||||
while ((in.read(&type, 1), type) != (char)nbt_tag::END){
|
||||
auto* v = _internal_::toType(type);
|
||||
v->readName(in);
|
||||
v->readPayload(in);
|
||||
|
@ -431,7 +433,8 @@ namespace blt::nbt {
|
|||
delete root;
|
||||
}
|
||||
void write(tag_compound& root){
|
||||
writer.put((char)nbt_tag::COMPOUND);
|
||||
auto c = (char)nbt_tag::COMPOUND;
|
||||
writer.write(&c, 1);
|
||||
root.writeName(writer);
|
||||
root.writePayload(writer);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace blt
|
|||
}
|
||||
|
||||
using iterator_category = typename std::iterator_traits<Iter>::iterator_category;
|
||||
using value_type = enumerate_item<Iter>;
|
||||
using value_type = enumerate_item<meta::deref_return_t<Iter>>;
|
||||
using difference_type = blt::ptrdiff_t;
|
||||
using pointer = value_type;
|
||||
using reference = value_type;
|
||||
|
|
|
@ -71,7 +71,8 @@ namespace blt::logging::ansi
|
|||
BLUE = 4,
|
||||
MAGENTA = 5,
|
||||
CYAN = 6,
|
||||
WHITE = 7, };
|
||||
WHITE = 7
|
||||
};
|
||||
|
||||
struct rgb_t
|
||||
{
|
||||
|
|
|
@ -28,6 +28,82 @@
|
|||
|
||||
namespace blt::logging
|
||||
{
|
||||
namespace tags
|
||||
{
|
||||
// Current Year
|
||||
inline constexpr auto YEAR = "{YEAR}";
|
||||
// Current Month
|
||||
inline constexpr auto MONTH = "{MONTH}";
|
||||
// Current Day
|
||||
inline constexpr auto DAY = "{DAY}";
|
||||
// Current Hour
|
||||
inline constexpr auto HOUR = "{HOUR}";
|
||||
// Current Minute
|
||||
inline constexpr auto MINUTE = "{MINUTE}";
|
||||
// Current Second
|
||||
inline constexpr auto SECOND = "{SECOND}";
|
||||
// Current Millisecond
|
||||
inline constexpr auto MILLISECOND = "{MS}";
|
||||
// Current Nanosecond time, This is direct output of nanotime
|
||||
inline constexpr auto NANOSECOND = "{NS}";
|
||||
// Current Unix time in milliseconds
|
||||
inline constexpr auto UNIX_TIME = "{UNIX}";
|
||||
// Formatted ISO year-month-day in a single variable
|
||||
inline constexpr auto ISO_YEAR = "{ISO_YEAR}";
|
||||
// Formatted hour:minute:second in a single variable
|
||||
inline constexpr auto TIME = "{TIME}";
|
||||
// Formatted year-month-day hour:minute:second in a single variable
|
||||
inline constexpr auto FULL_TIME = "{FULL_TIME}";
|
||||
// Color of the current log level, empty string if use_color = false
|
||||
inline constexpr auto LOG_COLOR = "{LC}";
|
||||
// Color of the error color, empty string if use_color = false
|
||||
inline constexpr auto ERROR_COLOR = "{EC}";
|
||||
// Empty is use_color = false or if log level is not an error. Otherwise, {EC}
|
||||
inline constexpr auto CONDITIONAL_ERROR_COLOR = "{CEC}";
|
||||
// Resets all ANSI sequences
|
||||
inline constexpr auto RESET = "{RESET}";
|
||||
// Current log level
|
||||
inline constexpr auto LOG_LEVEL = "{LL}";
|
||||
// Current thread name. Requires you to manually set the thread name using blt::logging::set_thread_name() from that thread.
|
||||
inline constexpr auto THREAD_NAME = "{TN}";
|
||||
// Current file from where the log call was invoked.
|
||||
inline constexpr auto FILE = "{FILE}";
|
||||
// Current line from where the log call was invoked
|
||||
inline constexpr auto LINE = "{LINE}";
|
||||
// User string input, formatted with provided args
|
||||
inline constexpr auto STR = "{STR}";
|
||||
|
||||
namespace detail
|
||||
{
|
||||
enum class log_tag_token_t : u8
|
||||
{
|
||||
YEAR,
|
||||
MONTH,
|
||||
DAY,
|
||||
HOUR,
|
||||
MINUTE,
|
||||
SECOND,
|
||||
MS,
|
||||
NS,
|
||||
UNIX,
|
||||
ISO_YEAR,
|
||||
TIME,
|
||||
FULL_TIME,
|
||||
LC,
|
||||
EC,
|
||||
CEC,
|
||||
RESET,
|
||||
LL,
|
||||
TN,
|
||||
FILE,
|
||||
LINE,
|
||||
STR,
|
||||
// token used to describe that a non-format token should be consumed. aka a normal string from the file.
|
||||
CONTENT
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
enum class log_level_t : u8
|
||||
{
|
||||
TRACE,
|
||||
|
@ -43,10 +119,12 @@ namespace blt::logging
|
|||
class logging_config_t
|
||||
{
|
||||
friend logger_t;
|
||||
|
||||
public:
|
||||
// wrappers for streams exist in blt/fs/stream_wrappers.h
|
||||
std::vector<fs::writer_t*> log_outputs = get_default_log_outputs();
|
||||
std::string log_format = get_default_log_format();
|
||||
std::string error_color = get_default_error_color();
|
||||
std::array<std::string, LOG_LEVEL_COUNT> log_level_colors = get_default_log_level_colors();
|
||||
std::array<std::string, LOG_LEVEL_COUNT> log_level_names = get_default_log_level_names();
|
||||
log_level_t level = log_level_t::TRACE;
|
||||
|
@ -56,11 +134,13 @@ namespace blt::logging
|
|||
// this will attempt to use the maximum possible size for each printed element, then align to that.
|
||||
// This creates output where the user message always starts at the same column.
|
||||
bool ensure_alignment = true;
|
||||
|
||||
private:
|
||||
static std::string get_default_log_format();
|
||||
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_names();
|
||||
static std::string get_default_error_color();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,12 @@ namespace blt::fs
|
|||
throw std::runtime_error("Failed to open file for writing");
|
||||
}
|
||||
|
||||
buffered_writer::buffered_writer(const std::string& name, const size_t buffer_size): fwriter_t{name}
|
||||
buffered_writer::buffered_writer(const std::string& name, const size_t buffer_size): fwriter_t{name, "ab"}
|
||||
{
|
||||
m_buffer.resize(buffer_size);
|
||||
}
|
||||
|
||||
buffered_writer::buffered_writer(const size_t buffer_size)
|
||||
{
|
||||
m_buffer.resize(buffer_size);
|
||||
}
|
||||
|
@ -148,6 +153,6 @@ namespace blt::fs
|
|||
{
|
||||
const std::time_t time = std::time(nullptr);
|
||||
const auto current_time = std::localtime(&time);
|
||||
return {current_time->tm_year, current_time->tm_mon, current_time->tm_mday, current_time->tm_hour};
|
||||
return {current_time->tm_year + 1900, current_time->tm_mon + 1, current_time->tm_mday, current_time->tm_hour};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@ namespace blt::nbt {
|
|||
}
|
||||
|
||||
void NBTReader::read() {
|
||||
char t = reader.get();
|
||||
char t;
|
||||
reader.read(&t, 1);
|
||||
if (t != (char)nbt_tag::COMPOUND) {
|
||||
BLT_WARN("Found %d", t);
|
||||
throw std::runtime_error("Incorrectly formatted NBT data! Root tag must be a compound tag!");
|
||||
|
|
|
@ -15,20 +15,93 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <blt/logging/logging_config.h>
|
||||
#include <iostream>
|
||||
#include <blt/fs/stream_wrappers.h>
|
||||
#include <blt/logging/ansi.h>
|
||||
#include <blt/logging/logging_config.h>
|
||||
#include <blt/std/hashmap.h>
|
||||
|
||||
namespace blt::logging
|
||||
{
|
||||
namespace tags::detail
|
||||
{
|
||||
hashmap_t<std::string_view, log_tag_token_t> make_map()
|
||||
{
|
||||
hashmap_t<std::string_view, log_tag_token_t> map{};
|
||||
map[YEAR] = log_tag_token_t::YEAR;
|
||||
map[MONTH] = log_tag_token_t::MONTH;
|
||||
map[DAY] = log_tag_token_t::DAY;
|
||||
map[HOUR] = log_tag_token_t::HOUR;
|
||||
map[MINUTE] = log_tag_token_t::MINUTE;
|
||||
map[SECOND] = log_tag_token_t::SECOND;
|
||||
map[MILLISECOND] = log_tag_token_t::MS;
|
||||
map[NANOSECOND] = log_tag_token_t::NS;
|
||||
map[UNIX_TIME] = log_tag_token_t::UNIX;
|
||||
map[ISO_YEAR] = log_tag_token_t::ISO_YEAR;
|
||||
map[TIME] = log_tag_token_t::TIME;
|
||||
map[FULL_TIME] = log_tag_token_t::FULL_TIME;
|
||||
map[LOG_COLOR] = log_tag_token_t::LC;
|
||||
map[ERROR_COLOR] = log_tag_token_t::EC;
|
||||
map[CONDITIONAL_ERROR_COLOR] = log_tag_token_t::CEC;
|
||||
map[RESET] = log_tag_token_t::RESET;
|
||||
map[LOG_LEVEL] = log_tag_token_t::LL;
|
||||
map[THREAD_NAME] = log_tag_token_t::TN;
|
||||
map[FILE] = log_tag_token_t::FILE;
|
||||
map[LINE] = log_tag_token_t::LINE;
|
||||
map[STR] = log_tag_token_t::STR;
|
||||
return map;
|
||||
}
|
||||
|
||||
hashmap_t<std::string_view, log_tag_token_t> tag_map = make_map();
|
||||
}
|
||||
|
||||
std::string logging_config_t::get_default_log_format()
|
||||
{}
|
||||
{
|
||||
return build(fg(ansi::color::color8_bright::CYAN)) + "[" + tags::FULL_TIME + "]" + tags::RESET + " " + tags::LOG_COLOR + "[" + tags::LOG_LEVEL
|
||||
+ "]" + tags::RESET + " " + build(fg(ansi::color::color8::MAGENTA)) + "(" + tags::FILE + ":" + tags::LINE + ")" + tags::RESET + " " +
|
||||
tags::CONDITIONAL_ERROR_COLOR + tags::STR + tags::RESET + "\n";
|
||||
}
|
||||
|
||||
std::vector<fs::writer_t*> logging_config_t::get_default_log_outputs()
|
||||
{}
|
||||
{
|
||||
static fs::fstream_writer_t cout_writer{std::cout};
|
||||
std::vector<fs::writer_t*> outputs{};
|
||||
outputs.push_back(&cout_writer);
|
||||
return outputs;
|
||||
}
|
||||
|
||||
std::array<std::string, LOG_LEVEL_COUNT> logging_config_t::get_default_log_level_colors()
|
||||
{}
|
||||
{
|
||||
return {
|
||||
// TRACE
|
||||
build(fg(ansi::color::color8_bright::WHITE)),
|
||||
// DEBUG
|
||||
build(fg(ansi::color::color8::CYAN)),
|
||||
// INFO
|
||||
build(fg(ansi::color::color8_bright::GREEN)),
|
||||
// WARN
|
||||
build(fg(ansi::color::color8_bright::YELLOW)),
|
||||
// ERROR
|
||||
build(fg(ansi::color::color8_bright::RED)),
|
||||
// FATAL
|
||||
build(fg(ansi::color::color8_bright::WHITE), bg(ansi::color::color8_bright::RED)),
|
||||
};
|
||||
}
|
||||
|
||||
std::array<std::string, LOG_LEVEL_COUNT> logging_config_t::get_default_log_level_names()
|
||||
{}
|
||||
{
|
||||
return {
|
||||
"TRACE",
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARN",
|
||||
"ERROR",
|
||||
"FATAL",
|
||||
};
|
||||
}
|
||||
|
||||
std::string logging_config_t::get_default_error_color()
|
||||
{
|
||||
return build(fg(ansi::color::color8_bright::RED));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ void test_iterate()
|
|||
}
|
||||
BLT_TRACE("================================");
|
||||
for (auto a : blt::iterate(array_1).map([](const blt::vec2& in) { return in.normalize(); })
|
||||
.enumerate().filter([](const auto& f) { return f.value.x() > 0.5; }))
|
||||
.enumerate().filter([](const auto& f) { return f.second.x() > 0.5; }))
|
||||
{
|
||||
if (!a)
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue