@@ -35,6 +35,6 @@ inline Int
|
||||
bit_range(Int num, size_t start, size_t end) {
|
||||
// NOTE: we do not require -1 if it is a signed integral
|
||||
Int left =
|
||||
std::numeric_limits<Int>::digits - (std::is_unsigned<Int>::value) - end;
|
||||
std::numeric_limits<Int>::digits - (!std::is_signed<Int>::value) - end;
|
||||
return static_cast<Int>(num << left) >> (left + start);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <fmt/core.h>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
// Why I wrote this myself? I do not know
|
||||
@@ -110,7 +110,7 @@ sha256(std::array<uint8_t, N>& data) {
|
||||
|
||||
for (j = 0; j < 8; j++)
|
||||
for (i = 0; i < 4; i++)
|
||||
fmt::format_to(std::back_inserter(string),
|
||||
std::format_to(std::back_inserter(string),
|
||||
"{:02x}",
|
||||
((h[j] >> (24 - i * 8)) & 0xFF));
|
||||
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/loglevel.hh"
|
||||
#include <fmt/ostream.h>
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
|
||||
namespace logging {
|
||||
namespace ansi {
|
||||
@@ -14,7 +13,7 @@ static constexpr auto BOLD = "\033[1m";
|
||||
static constexpr auto RESET = "\033[0m";
|
||||
}
|
||||
|
||||
using fmt::print;
|
||||
using std::print;
|
||||
|
||||
class Logger {
|
||||
using LogLevel = matar::LogLevel;
|
||||
@@ -27,12 +26,12 @@ class Logger {
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void log(const fmt::format_string<Args...>& fmt, Args&&... args) {
|
||||
fmt::println(stream, fmt, std::forward<Args>(args)...);
|
||||
void log(const std::format_string<Args...>& fmt, Args&&... args) {
|
||||
std::println(stream, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(const fmt::format_string<Args...>& fmt, Args&&... args) {
|
||||
void debug(const std::format_string<Args...>& fmt, Args&&... args) {
|
||||
if (level & static_cast<uint8_t>(LogLevel::Debug)) {
|
||||
print(stream, "{}{}[DEBUG] ", ansi::MAGENTA, ansi::BOLD);
|
||||
log(fmt, std::forward<Args>(args)...);
|
||||
@@ -41,7 +40,7 @@ class Logger {
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(const fmt::format_string<Args...>& fmt, Args&&... args) {
|
||||
void info(const std::format_string<Args...>& fmt, Args&&... args) {
|
||||
if (level & static_cast<uint8_t>(LogLevel::Info)) {
|
||||
print(stream, "{}[INFO] ", ansi::WHITE);
|
||||
log(fmt, std::forward<Args>(args)...);
|
||||
@@ -50,7 +49,7 @@ class Logger {
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(const fmt::format_string<Args...>& fmt, Args&&... args) {
|
||||
void warn(const std::format_string<Args...>& fmt, Args&&... args) {
|
||||
if (level & static_cast<uint8_t>(LogLevel::Warn)) {
|
||||
print(stream, "{}[WARN] ", ansi::YELLOW);
|
||||
log(fmt, std::forward<Args>(args)...);
|
||||
@@ -59,7 +58,7 @@ class Logger {
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(const fmt::format_string<Args...>& fmt, Args&&... args) {
|
||||
void error(const std::format_string<Args...>& fmt, Args&&... args) {
|
||||
if (level & static_cast<uint8_t>(LogLevel::Error)) {
|
||||
print(stream, "{}{}[ERROR] ", ansi::RED, ansi::BOLD);
|
||||
log(fmt, std::forward<Args>(args)...);
|
||||
|
Reference in New Issue
Block a user