0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-19 19:33:45 +02:00

ircd::log: Rename facility to level.

This commit is contained in:
Jason Volk 2018-12-19 12:52:08 -08:00
parent 7137280b05
commit 5a0a9989e4
7 changed files with 218 additions and 218 deletions

View file

@ -30,7 +30,7 @@ namespace ircd::db
size_t file_count(const database &); size_t file_count(const database &);
size_t bytes(const database &); size_t bytes(const database &);
options getopt(const database &); options getopt(const database &);
log::facility loglevel(const database &); log::level loglevel(const database &);
// Property information interface // Property information interface
using prop_int = uint64_t; using prop_int = uint64_t;
@ -44,7 +44,7 @@ namespace ircd::db
rocksdb::Cache *cache(database &); rocksdb::Cache *cache(database &);
// Control panel // Control panel
void loglevel(database &, const log::facility &); void loglevel(database &, const log::level &);
void setopt(database &, const string_view &key, const string_view &val); void setopt(database &, const string_view &key, const string_view &val);
void fdeletions(database &, const bool &enable, const bool &force = false); void fdeletions(database &, const bool &enable, const bool &force = false);
uint64_t checkpoint(database &); uint64_t checkpoint(database &);

View file

@ -11,7 +11,7 @@
#pragma once #pragma once
#define HAVE_IRCD_LOGGER_H #define HAVE_IRCD_LOGGER_H
// windows.h #define conflicts with our facility // windows.h #define conflicts with our level
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
#undef ERROR #undef ERROR
#endif #endif
@ -24,7 +24,7 @@ namespace ircd
/// Logging system /// Logging system
namespace ircd::log namespace ircd::log
{ {
enum facility :int; enum level :int;
struct log; struct log;
struct vlog; struct vlog;
struct logf; struct logf;
@ -43,8 +43,8 @@ namespace ircd::log
extern log star; // "*", '*' extern log star; // "*", '*'
extern log general; // "ircd", 'G' extern log general; // "ircd", 'G'
string_view reflect(const facility &); string_view reflect(const level &);
facility reflect(const string_view &); level reflect(const string_view &);
// The mask is the list of named loggers to allow; an empty mask disallows // The mask is the list of named loggers to allow; an empty mask disallows
// all loggers. An empty unmask allows all loggers. An unmask of a logger // all loggers. An empty unmask allows all loggers. An unmask of a logger
@ -54,9 +54,9 @@ namespace ircd::log
void console_mask(const vector_view<string_view> & = {}); void console_mask(const vector_view<string_view> & = {});
// This suite adjusts the output for an entire level. // This suite adjusts the output for an entire level.
bool console_enabled(const facility &); bool console_enabled(const level &);
void console_disable(const facility &); void console_disable(const level &);
void console_enable(const facility &); void console_enable(const level &);
void console_disable(); void console_disable();
void console_enable(); void console_enable();
@ -68,7 +68,7 @@ namespace ircd::log
void fini(); void fini();
} }
enum ircd::log::facility enum ircd::log::level
:int :int
{ {
CRITICAL = 0, ///< Catastrophic/unrecoverable; program is in a compromised state. CRITICAL = 0, ///< Catastrophic/unrecoverable; program is in a compromised state.
@ -96,7 +96,7 @@ struct ircd::log::log
bool fmasked {true}; // currently in the file mask (enabled) bool fmasked {true}; // currently in the file mask (enabled)
public: public:
template<class... args> void operator()(const facility &, const string_view &fmt, args&&...); template<class... args> void operator()(const level &, const string_view &fmt, args&&...);
#if RB_LOG_LEVEL >= 0 #if RB_LOG_LEVEL >= 0
template<class... args> void critical(const string_view &fmt, args&&...); template<class... args> void critical(const string_view &fmt, args&&...);
@ -155,21 +155,21 @@ struct ircd::log::log
struct ircd::log::vlog struct ircd::log::vlog
{ {
vlog(const log &log, const facility &, const string_view &fmt, const va_rtti &ap); vlog(const log &log, const level &, const string_view &fmt, const va_rtti &ap);
}; };
struct ircd::log::logf struct ircd::log::logf
{ {
template<class... args> template<class... args>
logf(const log &log, const facility &facility, const string_view &fmt, args&&... a) logf(const log &log, const level &level, const string_view &fmt, args&&... a)
{ {
vlog(log, facility, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
struct ircd::log::mark struct ircd::log::mark
{ {
mark(const facility &, const string_view &msg = {}); mark(const level &, const string_view &msg = {});
mark(const string_view &msg = {}); mark(const string_view &msg = {});
}; };
@ -185,13 +185,13 @@ struct ircd::log::debug
template<class... args> template<class... args>
debug(const log &log, const string_view &fmt, args&&... a) debug(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
debug(const string_view &fmt, args&&... a) debug(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -215,13 +215,13 @@ struct ircd::log::dwarning
template<class... args> template<class... args>
dwarning(const log &log, const string_view &fmt, args&&... a) dwarning(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::DWARNING, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::DWARNING, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
dwarning(const string_view &fmt, args&&... a) dwarning(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::DWARNING, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::DWARNING, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -245,13 +245,13 @@ struct ircd::log::derror
template<class... args> template<class... args>
derror(const log &log, const string_view &fmt, args&&... a) derror(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::DERROR, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::DERROR, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
derror(const string_view &fmt, args&&... a) derror(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::DERROR, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::DERROR, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -275,13 +275,13 @@ struct ircd::log::info
template<class... args> template<class... args>
info(const log &log, const string_view &fmt, args&&... a) info(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::INFO, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::INFO, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
info(const string_view &fmt, args&&... a) info(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::INFO, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::INFO, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -305,13 +305,13 @@ struct ircd::log::notice
template<class... args> template<class... args>
notice(const log &log, const string_view &fmt, args&&... a) notice(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
notice(const string_view &fmt, args&&... a) notice(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -335,13 +335,13 @@ struct ircd::log::warning
template<class... args> template<class... args>
warning(const log &log, const string_view &fmt, args&&... a) warning(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::WARNING, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::WARNING, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
warning(const string_view &fmt, args&&... a) warning(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::WARNING, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::WARNING, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -365,13 +365,13 @@ struct ircd::log::error
template<class... args> template<class... args>
error(const log &log, const string_view &fmt, args&&... a) error(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::ERROR, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::ERROR, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
error(const string_view &fmt, args&&... a) error(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::ERROR, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::ERROR, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -395,13 +395,13 @@ struct ircd::log::critical
template<class... args> template<class... args>
critical(const log &log, const string_view &fmt, args&&... a) critical(const log &log, const string_view &fmt, args&&... a)
{ {
vlog(log, facility::CRITICAL, fmt, va_rtti{std::forward<args>(a)...}); vlog(log, level::CRITICAL, fmt, va_rtti{std::forward<args>(a)...});
} }
template<class... args> template<class... args>
critical(const string_view &fmt, args&&... a) critical(const string_view &fmt, args&&... a)
{ {
vlog(general, facility::CRITICAL, fmt, va_rtti{std::forward<args>(a)...}); vlog(general, level::CRITICAL, fmt, va_rtti{std::forward<args>(a)...});
} }
}; };
#else #else
@ -425,7 +425,7 @@ void
ircd::log::log::debug(const string_view &fmt, ircd::log::log::debug(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -442,7 +442,7 @@ void
ircd::log::log::dwarning(const string_view &fmt, ircd::log::log::dwarning(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::DWARNING, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::DWARNING, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -459,7 +459,7 @@ void
ircd::log::log::derror(const string_view &fmt, ircd::log::log::derror(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::DERROR, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::DERROR, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -476,7 +476,7 @@ void
ircd::log::log::info(const string_view &fmt, ircd::log::log::info(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::INFO, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::INFO, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -493,7 +493,7 @@ void
ircd::log::log::notice(const string_view &fmt, ircd::log::log::notice(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -510,7 +510,7 @@ void
ircd::log::log::warning(const string_view &fmt, ircd::log::log::warning(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::WARNING, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::WARNING, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -527,7 +527,7 @@ void
ircd::log::log::error(const string_view &fmt, ircd::log::log::error(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::ERROR, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::ERROR, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -544,7 +544,7 @@ void
ircd::log::log::critical(const string_view &fmt, ircd::log::log::critical(const string_view &fmt,
args&&... a) args&&... a)
{ {
operator()(facility::CRITICAL, fmt, va_rtti{std::forward<args>(a)...}); operator()(level::CRITICAL, fmt, va_rtti{std::forward<args>(a)...});
} }
#else #else
inline void inline void
@ -557,7 +557,7 @@ ircd::log::log::critical(const string_view &fmt,
template<class... args> template<class... args>
void void
ircd::log::log::operator()(const facility &f, ircd::log::log::operator()(const level &f,
const string_view &fmt, const string_view &fmt,
args&&... a) args&&... a)
{ {

View file

@ -552,14 +552,14 @@ ircd::db::bgcancel(database &d,
property<uint64_t>(d, rocksdb::DB::Properties::kBackgroundErrors) property<uint64_t>(d, rocksdb::DB::Properties::kBackgroundErrors)
}; };
const auto facility const auto level
{ {
errors? log::facility::ERROR : log::facility::DEBUG errors? log::level::ERROR : log::level::DEBUG
}; };
log::logf log::logf
{ {
log, facility, log, level,
"'%s': Canceled all background work; errors:%lu", "'%s': Canceled all background work; errors:%lu",
name(d), name(d),
errors errors
@ -647,14 +647,14 @@ ircd::db::setopt(database &d,
}; };
} }
/// Set the rdb logging level by translating our ircd::log::facility to the /// Set the rdb logging level by translating our ircd::log::level to the
/// RocksDB enum. This translation is a reasonable convenience, as both /// RocksDB enum. This translation is a reasonable convenience, as both
/// enums are similar enough. /// enums are similar enough.
void void
ircd::db::loglevel(database &d, ircd::db::loglevel(database &d,
const ircd::log::facility &fac) const ircd::log::level &fac)
{ {
using ircd::log::facility; using ircd::log::level;
rocksdb::InfoLogLevel lev rocksdb::InfoLogLevel lev
{ {
@ -663,24 +663,24 @@ ircd::db::loglevel(database &d,
switch(fac) switch(fac)
{ {
case facility::CRITICAL: lev = rocksdb::FATAL_LEVEL; break; case level::CRITICAL: lev = rocksdb::FATAL_LEVEL; break;
case facility::ERROR: lev = rocksdb::ERROR_LEVEL; break; case level::ERROR: lev = rocksdb::ERROR_LEVEL; break;
case facility::WARNING: case level::WARNING:
case facility::NOTICE: lev = rocksdb::WARN_LEVEL; break; case level::NOTICE: lev = rocksdb::WARN_LEVEL; break;
case facility::INFO: lev = rocksdb::INFO_LEVEL; break; case level::INFO: lev = rocksdb::INFO_LEVEL; break;
case facility::DERROR: case level::DERROR:
case facility::DWARNING: case level::DWARNING:
case facility::DEBUG: lev = rocksdb::DEBUG_LEVEL; break; case level::DEBUG: lev = rocksdb::DEBUG_LEVEL; break;
case facility::_NUM_: assert(0); break; case level::_NUM_: assert(0); break;
} }
d.logger->SetInfoLogLevel(lev); d.logger->SetInfoLogLevel(lev);
} }
/// Set the rdb logging level by translating our ircd::log::facility to the /// Set the rdb logging level by translating our ircd::log::level to the
/// RocksDB enum. This translation is a reasonable convenience, as both /// RocksDB enum. This translation is a reasonable convenience, as both
/// enums are similar enough. /// enums are similar enough.
ircd::log::facility ircd::log::level
ircd::db::loglevel(const database &d) ircd::db::loglevel(const database &d)
{ {
const auto &level const auto &level
@ -695,11 +695,11 @@ ircd::db::loglevel(const database &d)
assert(0); assert(0);
case rocksdb::HEADER_LEVEL: case rocksdb::HEADER_LEVEL:
case rocksdb::FATAL_LEVEL: return log::facility::CRITICAL; case rocksdb::FATAL_LEVEL: return log::level::CRITICAL;
case rocksdb::ERROR_LEVEL: return log::facility::ERROR; case rocksdb::ERROR_LEVEL: return log::level::ERROR;
case rocksdb::WARN_LEVEL: return log::facility::WARNING; case rocksdb::WARN_LEVEL: return log::level::WARNING;
case rocksdb::INFO_LEVEL: return log::facility::INFO; case rocksdb::INFO_LEVEL: return log::level::INFO;
case rocksdb::DEBUG_LEVEL: return log::facility::DEBUG; case rocksdb::DEBUG_LEVEL: return log::level::DEBUG;
} }
} }
@ -2049,7 +2049,7 @@ noexcept
} }
static static
ircd::log::facility ircd::log::level
translate(const rocksdb::InfoLogLevel &level) translate(const rocksdb::InfoLogLevel &level)
{ {
switch(level) switch(level)
@ -2057,13 +2057,13 @@ translate(const rocksdb::InfoLogLevel &level)
// Treat all infomational messages from rocksdb as debug here for now. // Treat all infomational messages from rocksdb as debug here for now.
// We can clean them up and make better reports for our users eventually. // We can clean them up and make better reports for our users eventually.
default: default:
case rocksdb::InfoLogLevel::DEBUG_LEVEL: return ircd::log::facility::DEBUG; case rocksdb::InfoLogLevel::DEBUG_LEVEL: return ircd::log::level::DEBUG;
case rocksdb::InfoLogLevel::INFO_LEVEL: return ircd::log::facility::DEBUG; case rocksdb::InfoLogLevel::INFO_LEVEL: return ircd::log::level::DEBUG;
case rocksdb::InfoLogLevel::WARN_LEVEL: return ircd::log::facility::WARNING; case rocksdb::InfoLogLevel::WARN_LEVEL: return ircd::log::level::WARNING;
case rocksdb::InfoLogLevel::ERROR_LEVEL: return ircd::log::facility::ERROR; case rocksdb::InfoLogLevel::ERROR_LEVEL: return ircd::log::level::ERROR;
case rocksdb::InfoLogLevel::FATAL_LEVEL: return ircd::log::facility::CRITICAL; case rocksdb::InfoLogLevel::FATAL_LEVEL: return ircd::log::level::CRITICAL;
case rocksdb::InfoLogLevel::HEADER_LEVEL: return ircd::log::facility::NOTICE; case rocksdb::InfoLogLevel::HEADER_LEVEL: return ircd::log::level::NOTICE;
} }
} }
@ -2599,16 +2599,16 @@ ircd::db::database::events::OnCompactionCompleted(rocksdb::DB *const db,
const rocksdb::CompactionJobInfo &info) const rocksdb::CompactionJobInfo &info)
noexcept noexcept
{ {
const log::facility facility const log::level level
{ {
info.status == rocksdb::Status::OK()? info.status == rocksdb::Status::OK()?
log::facility::INFO: log::level::INFO:
log::facility::ERROR log::level::ERROR
}; };
log::logf log::logf
{ {
log, facility, log, level,
"'%s': %d compacted '%s' ctx:%lu level[in:%d out:%d] files[in:%zu out:%zu] reason:%d #%d: %s", "'%s': %d compacted '%s' ctx:%lu level[in:%d out:%d] files[in:%zu out:%zu] reason:%d #%d: %s",
d->name, d->name,
info.job_id, info.job_id,
@ -2630,16 +2630,16 @@ void
ircd::db::database::events::OnTableFileDeleted(const rocksdb::TableFileDeletionInfo &info) ircd::db::database::events::OnTableFileDeleted(const rocksdb::TableFileDeletionInfo &info)
noexcept noexcept
{ {
const log::facility facility const log::level level
{ {
info.status == rocksdb::Status::OK()? info.status == rocksdb::Status::OK()?
log::facility::DEBUG: log::level::DEBUG:
log::facility::ERROR log::level::ERROR
}; };
log::logf log::logf
{ {
log, facility, log, level,
"'%s': %d table file delete [%s][%s] #%d: %s", "'%s': %d table file delete [%s][%s] #%d: %s",
d->name, d->name,
info.job_id, info.job_id,
@ -2654,16 +2654,16 @@ void
ircd::db::database::events::OnTableFileCreated(const rocksdb::TableFileCreationInfo &info) ircd::db::database::events::OnTableFileCreated(const rocksdb::TableFileCreationInfo &info)
noexcept noexcept
{ {
const log::facility facility const log::level level
{ {
info.status == rocksdb::Status::OK()? info.status == rocksdb::Status::OK()?
log::facility::DEBUG: log::level::DEBUG:
log::facility::ERROR log::level::ERROR
}; };
log::logf log::logf
{ {
log, facility, log, level,
"'%s': %d table file closed [%s][%s] '%s' #%d: %s", "'%s': %d table file closed [%s][%s] '%s' #%d: %s",
d->name, d->name,
info.job_id, info.job_id,
@ -2758,11 +2758,11 @@ noexcept
false false
}; };
const log::facility fac const log::level fac
{ {
ignore? ignore?
log::facility::DERROR: log::level::DERROR:
log::facility::ERROR log::level::ERROR
}; };
log::logf log::logf
@ -6313,18 +6313,18 @@ try
} }
catch(const std::system_error &e) catch(const std::system_error &e)
{ {
// Set the facility to downplay some errors which the user shouldn't // Set the level to downplay some errors which the user shouldn't
// be alerted to with a log message under normal operations. // be alerted to with a log message under normal operations.
const log::facility facility const log::level level
{ {
is(e.code(), std::errc::no_such_file_or_directory)? is(e.code(), std::errc::no_such_file_or_directory)?
log::facility::DERROR: log::level::DERROR:
log::facility::ERROR log::level::ERROR
}; };
log::logf log::logf
{ {
log, facility, "'%s': opening seqfile:%p `%s' (%d) :%s", log, level, "'%s': opening seqfile:%p `%s' (%d) :%s",
d->name, d->name,
this, this,
name, name,

View file

@ -17,7 +17,7 @@
#define IRCD_JS_FIX #define IRCD_JS_FIX
// This was only ever defined for the SpiderMonkey headers and some of our hacks, // This was only ever defined for the SpiderMonkey headers and some of our hacks,
// but we need to undef it to not step on the log facility log::DEBUG. // but we need to undef it to not step on the log level log::DEBUG.
// Use JS_DEBUG as an analog instead. // Use JS_DEBUG as an analog instead.
#undef DEBUG #undef DEBUG
@ -3426,13 +3426,13 @@ ircd::js::context::handle_error(JSContext *const cx,
noexcept try noexcept try
{ {
assert(report); assert(report);
const log::facility facility const log::level level
{ {
JSREPORT_IS_WARNING(report->flags)? log::WARNING: JSREPORT_IS_WARNING(report->flags)? log::WARNING:
log::DEBUG log::DEBUG
}; };
log(facility, "context(%p): %s", log(level, "context(%p): %s",
(const void *)cx, (const void *)cx,
debug(*report).c_str()); debug(*report).c_str());

View file

@ -16,21 +16,21 @@ namespace ircd::log
{ {
struct confs; struct confs;
extern const std::array<string_view, num_of<facility>()> default_ansi; extern const std::array<string_view, num_of<level>()> default_ansi;
extern std::array<confs, num_of<facility>()> confs; extern std::array<confs, num_of<level>()> confs;
std::array<std::ofstream, num_of<facility>()> file; std::array<std::ofstream, num_of<level>()> file;
std::array<ulong, num_of<facility>()> console_quiet_stdout; std::array<ulong, num_of<level>()> console_quiet_stdout;
std::array<ulong, num_of<facility>()> console_quiet_stderr; std::array<ulong, num_of<level>()> console_quiet_stderr;
std::ostream &out_console{std::cout}; std::ostream &out_console{std::cout};
std::ostream &err_console{std::cerr}; std::ostream &err_console{std::cerr};
static std::string dir_path(); static std::string dir_path();
static std::string file_path(const facility &); static std::string file_path(const level &);
static void mkdir(); static void mkdir();
static void open(const facility &); static void open(const level &);
} }
struct ircd::log::confs struct ircd::log::confs
@ -47,7 +47,7 @@ void
ircd::log::init() ircd::log::init()
{ {
if(!ircd::debugmode) if(!ircd::debugmode)
console_disable(facility::DEBUG); console_disable(level::DEBUG);
mkdir(); mkdir();
} }
@ -76,37 +76,37 @@ ircd::log::mkdir()
void void
ircd::log::open() ircd::log::open()
{ {
for_each<facility>([](const facility &fac) for_each<level>([](const level &lev)
{ {
const auto &conf(confs.at(fac)); const auto &conf(confs.at(lev));
if(!bool(conf.file_enable)) if(!bool(conf.file_enable))
return; return;
if(file[fac].is_open()) if(file[lev].is_open())
file[fac].close(); file[lev].close();
file[fac].clear(); file[lev].clear();
file[fac].exceptions(std::ios::badbit | std::ios::failbit); file[lev].exceptions(std::ios::badbit | std::ios::failbit);
open(fac); open(lev);
}); });
} }
void void
ircd::log::close() ircd::log::close()
{ {
for_each<facility>([](const facility &fac) for_each<level>([](const level &lev)
{ {
if(file[fac].is_open()) if(file[lev].is_open())
file[fac].close(); file[lev].close();
}); });
} }
void void
ircd::log::flush() ircd::log::flush()
{ {
for_each<facility>([](const facility &fac) for_each<level>([](const level &lev)
{ {
file[fac].flush(); file[lev].flush();
}); });
std::flush(out_console); std::flush(out_console);
@ -114,23 +114,23 @@ ircd::log::flush()
} }
void void
ircd::log::open(const facility &fac) ircd::log::open(const level &lev)
try try
{ {
const auto &mode(std::ios::app); const auto &mode(std::ios::app);
const auto &path(file_path(fac)); const auto &path(file_path(lev));
file[fac].open(path.c_str(), mode); file[lev].open(path.c_str(), mode);
} }
catch(const std::exception &e) catch(const std::exception &e)
{ {
fprintf(stderr, "!!! Opening log file [%s] failed: %s", fprintf(stderr, "!!! Opening log file [%s] failed: %s",
file_path(fac).c_str(), file_path(lev).c_str(),
e.what()); e.what());
throw; throw;
} }
std::string std::string
ircd::log::file_path(const facility &fac) ircd::log::file_path(const level &lev)
{ {
const std::string base const std::string base
{ {
@ -139,7 +139,7 @@ ircd::log::file_path(const facility &fac)
const string_view parts[] const string_view parts[]
{ {
base, reflect(fac) base, reflect(lev)
}; };
return fs::make_path(parts); return fs::make_path(parts);
@ -159,43 +159,43 @@ ircd::log::dir_path()
void void
ircd::log::console_enable() ircd::log::console_enable()
{ {
for_each<facility>([](const facility &fac) for_each<level>([](const level &lev)
{ {
console_enable(fac); console_enable(lev);
}); });
} }
void void
ircd::log::console_disable() ircd::log::console_disable()
{ {
for_each<facility>([](const facility &fac) for_each<level>([](const level &lev)
{ {
console_disable(fac); console_disable(lev);
}); });
} }
void void
ircd::log::console_enable(const facility &fac) ircd::log::console_enable(const level &lev)
{ {
if(console_quiet_stdout[fac]) if(console_quiet_stdout[lev])
console_quiet_stdout[fac]--; console_quiet_stdout[lev]--;
if(console_quiet_stderr[fac]) if(console_quiet_stderr[lev])
console_quiet_stderr[fac]--; console_quiet_stderr[lev]--;
} }
void void
ircd::log::console_disable(const facility &fac) ircd::log::console_disable(const level &lev)
{ {
console_quiet_stdout[fac]++; console_quiet_stdout[lev]++;
console_quiet_stderr[fac]++; console_quiet_stderr[lev]++;
} }
bool bool
ircd::log::console_enabled(const facility &fac) ircd::log::console_enabled(const level &lev)
{ {
return !console_quiet_stdout[fac] || return !console_quiet_stdout[lev] ||
!console_quiet_stderr[fac]; !console_quiet_stderr[lev];
} }
void void
@ -235,17 +235,17 @@ ircd::log::console_quiet::~console_quiet()
ircd::log::mark::mark(const string_view &msg) ircd::log::mark::mark(const string_view &msg)
{ {
for_each<facility>([&msg] for_each<level>([&msg]
(const auto &fac) (const auto &lev)
{ {
mark(fac, msg); mark(lev, msg);
}); });
} }
ircd::log::mark::mark(const facility &fac, ircd::log::mark::mark(const level &lev,
const string_view &msg) const string_view &msg)
{ {
vlog(star, fac, "%s", msg); vlog(star, lev, "%s", msg);
} }
// //
@ -346,8 +346,8 @@ ircd::log::log::log(const string_view &name,
namespace ircd::log namespace ircd::log
{ {
static void check(std::ostream &) noexcept; static void check(std::ostream &) noexcept;
static void slog(const log &, const facility &, const window_buffer::closure &) noexcept; static void slog(const log &, const level &, const window_buffer::closure &) noexcept;
static void vlog_threadsafe(const log &, const facility &, const string_view &fmt, const va_rtti &ap); static void vlog_threadsafe(const log &, const level &, const string_view &fmt, const va_rtti &ap);
} }
decltype(ircd::log::star) decltype(ircd::log::star)
@ -368,7 +368,7 @@ ircd::log::general
/// main IRCd event loop which is running on the main thread. /// main IRCd event loop which is running on the main thread.
void void
ircd::log::vlog_threadsafe(const log &log, ircd::log::vlog_threadsafe(const log &log,
const facility &fac, const level &lev,
const string_view &fmt, const string_view &fmt,
const va_rtti &ap) const va_rtti &ap)
{ {
@ -380,14 +380,14 @@ ircd::log::vlog_threadsafe(const log &log,
// The pointer to the logger is copied to the main thread. // The pointer to the logger is copied to the main thread.
auto *const logp{&log}; auto *const logp{&log};
ircd::post([fac, str(std::move(str)), logp] ircd::post([lev, str(std::move(str)), logp]
{ {
// If that named logger was destroyed while this closure was // If that named logger was destroyed while this closure was
// travelling to the main thread then we just discard this message. // travelling to the main thread then we just discard this message.
if(!log::exists(logp)) if(!log::exists(logp))
return; return;
slog(*logp, fac, [&str](const mutable_buffer &out) -> size_t slog(*logp, lev, [&str](const mutable_buffer &out) -> size_t
{ {
return copy(out, string_view{str}); return copy(out, string_view{str});
}); });
@ -395,17 +395,17 @@ ircd::log::vlog_threadsafe(const log &log,
} }
ircd::log::vlog::vlog(const log &log, ircd::log::vlog::vlog(const log &log,
const facility &fac, const level &lev,
const string_view &fmt, const string_view &fmt,
const va_rtti &ap) const va_rtti &ap)
{ {
if(!is_main_thread()) if(!is_main_thread())
{ {
vlog_threadsafe(log, fac, fmt, ap); vlog_threadsafe(log, lev, fmt, ap);
return; return;
} }
slog(log, fac, [&fmt, &ap](const mutable_buffer &out) -> size_t slog(log, lev, [&fmt, &ap](const mutable_buffer &out) -> size_t
{ {
return fmt::vsprintf(out, fmt, ap); return fmt::vsprintf(out, fmt, ap);
}); });
@ -416,17 +416,17 @@ namespace ircd::log
// linkage for slog() reentrance assertion // linkage for slog() reentrance assertion
bool entered; bool entered;
static bool can_skip(const log &, const facility &); static bool can_skip(const log &, const level &);
} }
void void
ircd::log::slog(const log &log, ircd::log::slog(const log &log,
const facility &fac, const level &lev,
const window_buffer::closure &closure) const window_buffer::closure &closure)
noexcept noexcept
{ {
const auto &conf(confs.at(fac)); const auto &conf(confs.at(lev));
if(can_skip(log, fac)) if(can_skip(log, lev))
return; return;
// Have to be on the main thread to call slog(). // Have to be on the main thread to call slog().
@ -455,7 +455,7 @@ noexcept
<< string_view{conf.console_ansi} << string_view{conf.console_ansi}
<< std::setw(8) << std::setw(8)
<< std::right << std::right
<< reflect(fac) << reflect(lev)
<< (string_view{conf.console_ansi}? "\033[0m " : " ") << (string_view{conf.console_ansi}? "\033[0m " : " ")
// << (log.snote? log.snote : '-') // << (log.snote? log.snote : '-')
<< std::setw(9) << std::setw(9)
@ -492,14 +492,14 @@ noexcept
}}; }};
// copy to std::cerr // copy to std::cerr
if(log.cmasked && bool(conf.console_stderr) && !console_quiet_stderr[fac]) if(log.cmasked && bool(conf.console_stderr) && !console_quiet_stderr[lev])
{ {
err_console.clear(); err_console.clear();
write(err_console); write(err_console);
} }
// copy to std::cout // copy to std::cout
if(log.cmasked && bool(conf.console_stdout) && !console_quiet_stdout[fac]) if(log.cmasked && bool(conf.console_stdout) && !console_quiet_stdout[lev])
{ {
out_console.clear(); out_console.clear();
write(out_console); write(out_console);
@ -508,28 +508,28 @@ noexcept
} }
// copy to file // copy to file
if(log.fmasked && file[fac].is_open()) if(log.fmasked && file[lev].is_open())
{ {
file[fac].clear(); file[lev].clear();
write(file[fac]); write(file[lev]);
if(conf.file_flush) if(conf.file_flush)
std::flush(file[fac]); std::flush(file[lev]);
} }
} }
bool bool
ircd::log::can_skip(const log &log, ircd::log::can_skip(const log &log,
const facility &fac) const level &lev)
{ {
const auto &conf(confs.at(fac)); const auto &conf(confs.at(lev));
// When all of these conditions are true there is no possible log output // When all of these conditions are true there is no possible log output
// so we can bail real quick. // so we can bail real quick.
if(!file[fac].is_open() && !bool(conf.console_stdout) && !bool(conf.console_stderr)) if(!file[lev].is_open() && !bool(conf.console_stdout) && !bool(conf.console_stderr))
return true; return true;
// Same for this set of conditions... // Same for this set of conditions...
if((!file[fac].is_open() || !log.fmasked) && (!log.cmasked || !console_enabled(fac))) if((!file[lev].is_open() || !log.fmasked) && (!log.cmasked || !console_enabled(lev)))
return true; return true;
return false; return false;
@ -565,43 +565,43 @@ catch(const std::exception &e)
ircd::terminate(); ircd::terminate();
} }
ircd::log::facility ircd::log::level
ircd::log::reflect(const string_view &f) ircd::log::reflect(const string_view &f)
{ {
if(f == "CRITICAL") return facility::CRITICAL; if(f == "CRITICAL") return level::CRITICAL;
if(f == "ERROR") return facility::ERROR; if(f == "ERROR") return level::ERROR;
if(f == "DERROR") return facility::DERROR; if(f == "DERROR") return level::DERROR;
if(f == "DWARNING") return facility::DWARNING; if(f == "DWARNING") return level::DWARNING;
if(f == "WARNING") return facility::WARNING; if(f == "WARNING") return level::WARNING;
if(f == "NOTICE") return facility::NOTICE; if(f == "NOTICE") return level::NOTICE;
if(f == "INFO") return facility::INFO; if(f == "INFO") return level::INFO;
if(f == "DEBUG") return facility::DEBUG; if(f == "DEBUG") return level::DEBUG;
throw ircd::error throw ircd::error
{ {
"'%s' is not a recognized log facility", f "'%s' is not a recognized log level", f
}; };
} }
ircd::string_view ircd::string_view
ircd::log::reflect(const facility &f) ircd::log::reflect(const level &f)
{ {
switch(f) switch(f)
{ {
case facility::CRITICAL: return "CRITICAL"; case level::CRITICAL: return "CRITICAL";
case facility::ERROR: return "ERROR"; case level::ERROR: return "ERROR";
case facility::DERROR: return "ERROR"; case level::DERROR: return "ERROR";
case facility::WARNING: return "WARNING"; case level::WARNING: return "WARNING";
case facility::DWARNING: return "WARNING"; case level::DWARNING: return "WARNING";
case facility::INFO: return "INFO"; case level::INFO: return "INFO";
case facility::NOTICE: return "NOTICE"; case level::NOTICE: return "NOTICE";
case facility::DEBUG: return "DEBUG"; case level::DEBUG: return "DEBUG";
case facility::_NUM_: break; // Allows -Wswitch to remind developer to add reflection here case level::_NUM_: break; // Allows -Wswitch to remind developer to add reflection here
}; };
throw assertive throw assertive
{ {
"'%d' is not a recognized log facility", int(f) "'%d' is not a recognized log level", int(f)
}; };
} }
@ -676,8 +676,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.critical.console.ansi" }, { "name", "ircd.log.critical.console.ansi" },
{ "default", default_ansi.at(facility::CRITICAL) }, { "default", default_ansi.at(level::CRITICAL) },
} }
}, },
@ -715,8 +715,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.error.console.ansi" }, { "name", "ircd.log.error.console.ansi" },
{ "default", default_ansi.at(facility::ERROR) }, { "default", default_ansi.at(level::ERROR) },
} }
}, },
@ -754,8 +754,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.warning.console.ansi" }, { "name", "ircd.log.warning.console.ansi" },
{ "default", default_ansi.at(facility::WARNING) }, { "default", default_ansi.at(level::WARNING) },
} }
}, },
@ -793,8 +793,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.notice.console.ansi" }, { "name", "ircd.log.notice.console.ansi" },
{ "default", default_ansi.at(facility::NOTICE) }, { "default", default_ansi.at(level::NOTICE) },
} }
}, },
@ -832,8 +832,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.info.console.ansi" }, { "name", "ircd.log.info.console.ansi" },
{ "default", default_ansi.at(facility::INFO) }, { "default", default_ansi.at(level::INFO) },
} }
}, },
@ -871,8 +871,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.derror.console.ansi" }, { "name", "ircd.log.derror.console.ansi" },
{ "default", default_ansi.at(facility::DERROR) }, { "default", default_ansi.at(level::DERROR) },
} }
}, },
@ -910,8 +910,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.dwarning.console.ansi" }, { "name", "ircd.log.dwarning.console.ansi" },
{ "default", default_ansi.at(facility::DWARNING) }, { "default", default_ansi.at(level::DWARNING) },
} }
}, },
@ -949,8 +949,8 @@ ircd::log::confs
// console ansi // console ansi
{ {
{ "name", "ircd.log.debug.console.ansi" }, { "name", "ircd.log.debug.console.ansi" },
{ "default", default_ansi.at(facility::DEBUG) }, { "default", default_ansi.at(level::DEBUG) },
} }
} }
}}; }};

View file

@ -1100,20 +1100,20 @@ ircd::resource::response::response(client &client,
}; };
#ifdef RB_DEBUG #ifdef RB_DEBUG
const log::facility facility const log::level level
{ {
ushort(code) >= 200 && ushort(code) < 300? ushort(code) >= 200 && ushort(code) < 300?
log::facility::DEBUG: log::level::DEBUG:
ushort(code) >= 300 && ushort(code) < 400? ushort(code) >= 300 && ushort(code) < 400?
log::facility::DWARNING: log::level::DWARNING:
ushort(code) >= 400 && ushort(code) < 500? ushort(code) >= 400 && ushort(code) < 500?
log::facility::DERROR: log::level::DERROR:
log::facility::ERROR log::level::ERROR
}; };
log::logf log::logf
{ {
log, facility, log, level,
"%s HTTP %d `%s' %s in %ld$us; %s content-length:%s", "%s HTTP %d `%s' %s in %ld$us; %s content-length:%s",
client.loghead(), client.loghead(),
uint(code), uint(code),

View file

@ -491,13 +491,13 @@ console_cmd__log__level(opt &out, const string_view &line)
if(!param.count()) if(!param.count())
{ {
for(int i(0); i < num_of<log::facility>(); ++i) for(int i(0); i < num_of<log::level>(); ++i)
if(i > RB_LOG_LEVEL) if(i > RB_LOG_LEVEL)
out << "[\033[1;40m-\033[0m]: " << reflect(log::facility(i)) << std::endl; out << "[\033[1;40m-\033[0m]: " << reflect(log::level(i)) << std::endl;
else if(console_enabled(log::facility(i))) else if(console_enabled(log::level(i)))
out << "[\033[1;42m+\033[0m]: " << reflect(log::facility(i)) << std::endl; out << "[\033[1;42m+\033[0m]: " << reflect(log::level(i)) << std::endl;
else else
out << "[\033[1;41m-\033[0m]: " << reflect(log::facility(i)) << std::endl; out << "[\033[1;41m-\033[0m]: " << reflect(log::level(i)) << std::endl;
return true; return true;
} }
@ -507,18 +507,18 @@ console_cmd__log__level(opt &out, const string_view &line)
param.at<int>(0) param.at<int>(0)
}; };
for(int i(0); i < num_of<log::facility>(); ++i) for(int i(0); i < num_of<log::level>(); ++i)
if(i > RB_LOG_LEVEL) if(i > RB_LOG_LEVEL)
{ {
out << "[\033[1;40m-\033[0m]: " << reflect(log::facility(i)) << std::endl; out << "[\033[1;40m-\033[0m]: " << reflect(log::level(i)) << std::endl;
} }
else if(i <= level) else if(i <= level)
{ {
console_enable(log::facility(i)); console_enable(log::level(i));
out << "[\033[1;42m+\033[0m]: " << reflect(log::facility(i)) << std::endl; out << "[\033[1;42m+\033[0m]: " << reflect(log::level(i)) << std::endl;
} else { } else {
console_disable(log::facility(i)); console_disable(log::level(i));
out << "[\033[1;41m-\033[0m]: " << reflect(log::facility(i)) << std::endl; out << "[\033[1;41m-\033[0m]: " << reflect(log::level(i)) << std::endl;
} }
return true; return true;
@ -1541,15 +1541,15 @@ try
return true; return true;
} }
const log::facility &fac const log::level &lev
{ {
log::reflect(param.at("level")) log::reflect(param.at("level"))
}; };
loglevel(database, fac); loglevel(database, lev);
out << "set logging level of '" << name(database) << "'" out << "set logging level of '" << name(database) << "'"
<< " database to '" << reflect(fac) << "'" << " database to '" << reflect(lev) << "'"
<< std::endl; << std::endl;
return true; return true;