mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd::http: Add log level severity(category) convenience tool; tweak category table.
This commit is contained in:
parent
16898ba19e
commit
a1420b25a3
3 changed files with 30 additions and 17 deletions
|
@ -30,6 +30,7 @@ namespace ircd::http
|
|||
string_view category(const enum category &) noexcept;
|
||||
enum category category(const enum code &) noexcept;
|
||||
enum category category(const string_view &) noexcept;
|
||||
enum log::level severity(const enum category &) noexcept;
|
||||
|
||||
void writeline(window_buffer &);
|
||||
void writeline(window_buffer &, const window_buffer::closure &);
|
||||
|
@ -48,12 +49,13 @@ enum class ircd::http::category
|
|||
:uint8_t
|
||||
{
|
||||
NONE = 0, ///< Sentinel
|
||||
INFO = 1, ///< Informational
|
||||
SUCCESS = 2, ///< Successful
|
||||
REDIRECT = 3, ///< Redirectional
|
||||
ERROR = 4, ///< Erroneous
|
||||
SERVER = 6, ///< Server Error
|
||||
UNKNOWN = 7, /// Pair with default case in switch/tables
|
||||
INFO = 1, ///< Informational (100-199)
|
||||
SUCCESS = 2, ///< Successful (200-299)
|
||||
REDIRECT = 3, ///< Redirectional (300-399)
|
||||
ERROR = 4, ///< Client Error (400-499)
|
||||
SERVER = 5, ///< Server Error (501-599)
|
||||
INTERNAL = 6, ///< Internal Error (500 only)
|
||||
UNKNOWN = 7, ///< Pair with default case in switch/tables
|
||||
};
|
||||
|
||||
/// HTTP Status codes.
|
||||
|
|
21
ircd/http.cc
21
ircd/http.cc
|
@ -1331,6 +1331,23 @@ catch(const std::out_of_range &e)
|
|||
return ""_sv;
|
||||
}
|
||||
|
||||
enum ircd::log::level
|
||||
ircd::http::severity(const enum category &category)
|
||||
noexcept
|
||||
{
|
||||
switch(category)
|
||||
{
|
||||
case http::category::NONE: return log::level::DERROR;
|
||||
case http::category::SUCCESS: return log::level::DEBUG;
|
||||
case http::category::REDIRECT: return log::level::DWARNING;
|
||||
case http::category::ERROR: return log::level::DERROR;
|
||||
case http::category::SERVER: return log::level::DERROR;
|
||||
case http::category::INTERNAL: return log::level::ERROR;
|
||||
default:
|
||||
case http::category::UNKNOWN: return log::level::DWARNING;
|
||||
}
|
||||
}
|
||||
|
||||
enum ircd::http::category
|
||||
ircd::http::category(const string_view &str)
|
||||
noexcept
|
||||
|
@ -1368,6 +1385,9 @@ noexcept
|
|||
if(ushort(code) < 500)
|
||||
return category::ERROR;
|
||||
|
||||
if(ushort(code) == 500)
|
||||
return category::INTERNAL;
|
||||
|
||||
if(ushort(code) < 600)
|
||||
return category::SERVER;
|
||||
|
||||
|
@ -1386,6 +1406,7 @@ noexcept
|
|||
case category::REDIRECT: return "REDIRECT";
|
||||
case category::ERROR: return "ERROR";
|
||||
case category::SERVER: return "SERVER";
|
||||
case category::INTERNAL: return "INTERNAL";
|
||||
default:
|
||||
case category::UNKNOWN: return "UNKNOWN";
|
||||
}
|
||||
|
|
|
@ -1278,17 +1278,7 @@ ircd::resource::response::response(client &client,
|
|||
#ifdef RB_DEBUG
|
||||
const log::level level
|
||||
{
|
||||
ushort(code) >= 200 && ushort(code) < 300?
|
||||
log::level::DEBUG:
|
||||
ushort(code) >= 300 && ushort(code) < 400?
|
||||
log::level::DWARNING:
|
||||
ushort(code) >= 400 && ushort(code) < 500?
|
||||
log::level::DERROR:
|
||||
ushort(code) == 500?
|
||||
log::level::ERROR:
|
||||
ushort(code) > 500?
|
||||
log::level::DERROR:
|
||||
log::level::ERROR
|
||||
http::severity(http::category(code))
|
||||
};
|
||||
|
||||
log::logf
|
||||
|
|
Loading…
Reference in a new issue