More refactoring and bug fixes

- Added `libhttp` and `librest_api` targets to CMakeLists.txt
- Added examples for `libhttp` and `librest_api` in examples directory
- Added `cache` and `add` commands
- Added documentation for `libhttp` and `librest_api`
- Added all available HTTP response codes to REST API
- Changed how `bin/compile.sh` works (must supply args to build)
This commit is contained in:
David Allen 2023-05-27 11:28:58 -06:00
parent 5a73651ad1
commit 8b1f1374d8
23 changed files with 575 additions and 164 deletions

View file

@ -3,6 +3,8 @@
#include "utils.hpp"
#include "colors.hpp"
#include "types.hpp"
#include <format>
// #include <fmt/core.h>
#if __cplusplus > 201703L
@ -18,22 +20,21 @@ TODO: Write log information to file
*/
namespace gdpm::log
{
template <typename...Args> concept RequireMinArgs = requires (std::size_t min){ sizeof...(Args) > min; };
enum level{
NONE,
NONE = 0,
INFO,
WARNING,
DEBUG,
ERROR
};
struct config {
static int level;
static std::string prefix;
static std::string path;
static bool print_to_stdout;
static bool print_to_stderr;
struct context {
int level;
string prefix;
string path;
bool print_to_stdout;
bool print_to_stderr;
};
static void vlog(fmt::string_view format, fmt::format_args args){
@ -46,7 +47,7 @@ namespace gdpm::log
template <typename S, typename...Args>
static constexpr void info(const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > 0
#if GDPM_LOG_LEVEL > NONE
vlog(
fmt::format(GDPM_COLOR_LOG_INFO "[INFO {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
// fmt::make_format_args<Args...>(args...)
@ -55,18 +56,40 @@ namespace gdpm::log
#endif
}
template <typename S, typename...Args>
static constexpr void info(const S& prefix, const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > INFO
vlog(
fmt::format(GDPM_COLOR_LOG_INFO + prefix + GDPM_COLOR_LOG_RESET, format),
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void info(const context& context, const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > INFO
vlog(
fmt::format(GDPM_COLOR_LOG_INFO + context.prefix + GDPM_COLOR_LOG_RESET, format),
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void info_n(const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > INFO
vlog(
fmt::format(GDPM_COLOR_LOG_INFO "[INFO {}] {}" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
// fmt::make_format_args<Args...>(args...)
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void error(const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > 1
#if GDPM_LOG_LEVEL > ERROR
vlog(
fmt::format(GDPM_COLOR_LOG_ERROR "[ERROR {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
// fmt::make_format_args<Args...>(args...)
@ -75,9 +98,29 @@ namespace gdpm::log
#endif
}
template <typename S, typename...Args>
static constexpr void error(const S& prefix, const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > ERROR
vlog(
fmt::format(GDPM_COLOR_LOG_ERROR + prefix + GDPM_COLOR_LOG_RESET, format),
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void error(const context& context, const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > ERROR
vlog(
fmt::format(GDPM_COLOR_LOG_ERROR + context.prefix + GDPM_COLOR_LOG_RESET, format),
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void debug(const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > 1
#if GDPM_LOG_LEVEL > DEBUG
vlog(
fmt::format(GDPM_COLOR_LOG_DEBUG "[DEBUG {}] {}\n" GDPM_COLOR_LOG_RESET, utils::timestamp(), format),
// fmt::make_format_args<Args...>(args...)
@ -86,6 +129,26 @@ namespace gdpm::log
#endif
}
template <typename S, typename...Args>
static constexpr void debug(const S& prefix, const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > DEBUG
vlog(
fmt::format(GDPM_COLOR_LOG_DEBUG + prefix + GDPM_COLOR_LOG_RESET, format),
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void debug(const context& context, const S& format, Args&&...args){
#if GDPM_LOG_LEVEL > DEBUG
vlog(
fmt::format(GDPM_COLOR_LOG_DEBUG + context.prefix + GDPM_COLOR_LOG_RESET, format),
fmt::make_format_args(args...)
);
#endif
}
template <typename S, typename...Args>
static constexpr void print(const S& format, Args&&...args){
vlog(
@ -95,7 +158,7 @@ namespace gdpm::log
);
}
template <typename S = std::string, typename...Args>
template <typename S = string, typename...Args>
static constexpr void println(const S& format, Args&&...args){
vlog(
fmt::format("{}\n", format),
@ -105,7 +168,7 @@ namespace gdpm::log
}
template <typename>
static constexpr void println(const std::string& format = ""){
static constexpr void println(const string& format = ""){
println(format);
}