0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 08:23:56 +01:00

ircd::log: Drop in ircd::fmt.

This commit is contained in:
Jason Volk 2017-03-17 20:24:25 -07:00
parent fa1c393d7a
commit a0e7002dde
2 changed files with 130 additions and 219 deletions

View file

@ -38,7 +38,7 @@ namespace ircd {
const char *smalldate(const time_t &);
} // namespace ircd
} // namespace ircd
// windows.h #define conflicts with our facility
#ifdef HAVE_WINDOWS_H
@ -56,15 +56,13 @@ enum facility
NOTICE = 3,
INFO = 4,
DEBUG = 5,
_NUM_
};
const char *reflect(const facility &);
void slog(const facility &, const std::function<void (std::ostream &)> &);
void vlog(const facility &, const std::string &name, const char *const &fmt, va_list ap);
void vlog(const facility &, const char *const &fmt, va_list ap);
void logf(const facility &, const char *fmt, ...) AFP(2, 3);
void vlog(const facility &, const std::string &name, const char *const &fmt, const va_rtti &ap);
void vlog(const facility &, const char *const &fmt, const va_rtti &ap);
void mark(const facility &, const char *const &msg = nullptr);
void mark(const char *const &msg = nullptr);
@ -73,24 +71,25 @@ class log
std::string name;
public:
void operator()(const facility &, const char *fmt, ...) AFP(3, 4);
void critical(const char *fmt, ...) AFP(2, 3);
void error(const char *fmt, ...) AFP(2, 3);
void warning(const char *fmt, ...) AFP(2, 3);
void notice(const char *fmt, ...) AFP(2, 3);
void info(const char *fmt, ...) AFP(2, 3);
void debug(const char *fmt, ...) AFP(2, 3);
template<class... args> void operator()(const facility &, const char *const &fmt, args&&...);
template<class... args> void critical(const char *const &fmt, args&&...);
template<class... args> void error(const char *const &fmt, args&&...);
template<class... args> void warning(const char *const &fmt, args&&...);
template<class... args> void notice(const char *const &fmt, args&&...);
template<class... args> void info(const char *const &fmt, args&&...);
template<class... args> void debug(const char *const &fmt, args&&...);
log(const std::string &name, const char &snote);
log(const std::string &name);
};
void critical(const char *fmt, ...) AFP(1, 2);
void error(const char *fmt, ...) AFP(1, 2);
void warning(const char *fmt, ...) AFP(1, 2);
void notice(const char *fmt, ...) AFP(1, 2);
void info(const char *fmt, ...) AFP(1, 2);
void debug(const char *fmt, ...) AFP(1, 2);
template<class... args> void critical(const char *const &fmt, args&&...);
template<class... args> void error(const char *const &fmt, args&&...);
template<class... args> void warning(const char *const &fmt, args&&...);
template<class... args> void notice(const char *const &fmt, args&&...);
template<class... args> void info(const char *const &fmt, args&&...);
template<class... args> void debug(const char *const &fmt, args&&...);
struct console_quiet
{
@ -105,55 +104,110 @@ void open();
void init();
void fini();
} // namespace log
enum ilogfile
{
L_MAIN,
L_USER,
L_FUSER,
L_OPERED,
L_FOPER,
L_SERVER,
L_KILL,
L_KLINE,
L_OPERSPY,
L_IOERROR,
LAST_LOGFILE
};
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
template<class... A> void ilog(ilogfile dest, A&&... a)
{
log::logf(log::INFO, std::forward<A>(a)...);
}
template<class... A> void idebug(A&&... a)
{
log::debug(std::forward<A>(a)...);
}
template<class... A> void inotice(A&&... a)
{
log::notice(std::forward<A>(a)...);
}
template<class... A> void iwarn(A&&... a)
{
log::warning(std::forward<A>(a)...);
}
template<class... A> void ierror(A&&... a)
{
log::error(std::forward<A>(a)...);
}
template<class... A> void ilog_error(A&&... a)
{
log::error(std::forward<A>(a)...);
}
template<class... A> void slog(const ilogfile, const uint sno, const char *fmt, A&&... a)
{
log::info(fmt, std::forward<A>(a)...);
}
#pragma GCC diagnostic pop
} // namespace log
} // namespace ircd
template<class... args>
void
ircd::log::debug(const char *const &fmt,
args&&... a)
{
vlog(facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::info(const char *const &fmt,
args&&... a)
{
vlog(facility::INFO, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::notice(const char *const &fmt,
args&&... a)
{
vlog(facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::warning(const char *const &fmt,
args&&... a)
{
vlog(facility::WARNING, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::error(const char *const &fmt,
args&&... a)
{
vlog(facility::ERROR, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::critical(const char *const &fmt,
args&&... a)
{
vlog(facility::CRITICAL, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::debug(const char *const &fmt,
args&&... a)
{
operator()(facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::info(const char *const &fmt,
args&&... a)
{
operator()(facility::INFO, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::notice(const char *const &fmt,
args&&... a)
{
operator()(facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::warning(const char *const &fmt,
args&&... a)
{
operator()(facility::WARNING, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::error(const char *const &fmt,
args&&... a)
{
operator()(facility::ERROR, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::critical(const char *const &fmt,
args&&... a)
{
operator()(facility::CRITICAL, fmt, va_rtti{std::forward<args>(a)...});
}
template<class... args>
void
ircd::log::log::operator()(const facility &f,
const char *const &fmt,
args&&... a)
{
vlog(f, name, fmt, va_rtti{std::forward<args>(a)...});
}

View file

@ -199,68 +199,6 @@ log::console_quiet::~console_quiet()
std::copy(begin(quieted_err), end(quieted_err), begin(console_err));
}
void
log::debug(const char *const fmt,
...)
{
#ifndef NDEBUG
va_list ap;
va_start(ap, fmt);
vlog(facility::DEBUG, fmt, ap);
va_end(ap);
#endif
}
void
log::info(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(facility::INFO, fmt, ap);
va_end(ap);
}
void
log::notice(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(facility::NOTICE, fmt, ap);
va_end(ap);
}
void
log::warning(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(facility::WARNING, fmt, ap);
va_end(ap);
}
void
log::error(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(facility::ERROR, fmt, ap);
va_end(ap);
}
void
log::critical(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(facility::CRITICAL, fmt, ap);
va_end(ap);
}
log::log::log(const std::string &name)
:name{name}
{
@ -272,77 +210,6 @@ log::log::log(const std::string &name,
{
}
void
log::log::debug(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(DEBUG, name, fmt, ap);
va_end(ap);
}
void
log::log::info(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(INFO, name, fmt, ap);
va_end(ap);
}
void
log::log::notice(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(NOTICE, name, fmt, ap);
va_end(ap);
}
void
log::log::warning(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(WARNING, name, fmt, ap);
va_end(ap);
}
void
log::log::error(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(ERROR, name, fmt, ap);
va_end(ap);
}
void
log::log::critical(const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(CRITICAL, name, fmt, ap);
va_end(ap);
}
void
log::log::operator()(const facility &facility,
const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(facility, name, fmt, ap);
va_end(ap);
}
void
log::mark(const char *const &msg)
{
@ -364,28 +231,18 @@ log::mark(const facility &fac,
});
}
void
log::logf(const facility &fac,
const char *const fmt,
...)
{
va_list ap;
va_start(ap, fmt);
vlog(fac, fmt, ap);
va_end(ap);
}
void
log::vlog(const facility &fac,
const char *const &fmt,
va_list ap)
const va_rtti &ap)
{
char buf[1024];
vsnprintf(buf, sizeof(buf), fmt, ap);
fmt::vsnprintf(buf, sizeof(buf), fmt, ap);
slog(fac, [&buf]
(std::ostream &s)
{
s << "ircd :" << buf;
static const auto name{"ircd"};
s << std::left << std::setw(9) << name << std::right << " :" << buf;
});
}
@ -393,14 +250,14 @@ void
log::vlog(const facility &fac,
const std::string &name,
const char *const &fmt,
va_list ap)
const va_rtti &ap)
{
char buf[1024];
vsnprintf(buf, sizeof(buf), fmt, ap);
fmt::vsnprintf(buf, sizeof(buf), fmt, ap);
slog(fac, [&buf, &name]
(std::ostream &s)
{
s << name << " :" << buf;
s << std::left << std::setw(9) << name << std::right << " :" << buf;
});
}