2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_LOGGER_H
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-26 06:38:15 +02:00
|
|
|
// windows.h #define conflicts with our facility
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
#undef ERROR
|
|
|
|
#endif
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd
|
|
|
|
{
|
|
|
|
const char *smalldate(const time_t &);
|
|
|
|
}
|
|
|
|
|
2017-09-12 18:37:44 +02:00
|
|
|
/// Logging system
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd::log
|
|
|
|
{
|
|
|
|
enum facility :int;
|
|
|
|
const char *reflect(const facility &);
|
|
|
|
|
|
|
|
struct log;
|
|
|
|
struct console_quiet;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct critical;
|
|
|
|
struct error;
|
|
|
|
struct warning;
|
|
|
|
struct notice;
|
|
|
|
struct info;
|
|
|
|
struct debug;
|
2017-08-28 23:51:22 +02:00
|
|
|
|
|
|
|
void flush();
|
|
|
|
void close();
|
|
|
|
void open();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
void fini();
|
|
|
|
}
|
2016-08-26 06:38:15 +02:00
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
enum ircd::log::facility
|
|
|
|
:int
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
|
|
|
CRITICAL = 0,
|
|
|
|
ERROR = 1,
|
|
|
|
WARNING = 2,
|
|
|
|
NOTICE = 3,
|
|
|
|
INFO = 4,
|
|
|
|
DEBUG = 5,
|
|
|
|
_NUM_
|
|
|
|
};
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
class ircd::log::log
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
public:
|
2017-03-18 04:24:25 +01:00
|
|
|
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&&...);
|
2016-08-26 06:38:15 +02:00
|
|
|
|
|
|
|
log(const std::string &name, const char &snote);
|
|
|
|
log(const std::string &name);
|
|
|
|
};
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
struct ircd::log::console_quiet
|
2016-09-07 01:31:29 +02:00
|
|
|
{
|
|
|
|
console_quiet(const bool &showmsg = true);
|
|
|
|
~console_quiet();
|
|
|
|
};
|
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct ircd::log::debug
|
2017-03-18 04:24:25 +01:00
|
|
|
{
|
2018-01-21 10:17:33 +01:00
|
|
|
template<class... args>
|
|
|
|
debug(const char *const &fmt, args&&... a)
|
|
|
|
{
|
|
|
|
// got DCE?
|
|
|
|
#ifdef RB_DEBUG
|
|
|
|
vlog(facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
2016-08-26 06:38:15 +02:00
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct ircd::log::info
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-01-21 10:17:33 +01:00
|
|
|
template<class... args>
|
|
|
|
info(const char *const &fmt, args&&... a)
|
|
|
|
{
|
|
|
|
vlog(facility::INFO, fmt, va_rtti{std::forward<args>(a)...});
|
|
|
|
}
|
|
|
|
};
|
2017-03-18 04:24:25 +01:00
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct ircd::log::notice
|
2017-03-18 04:24:25 +01:00
|
|
|
{
|
2018-01-21 10:17:33 +01:00
|
|
|
template<class... args>
|
|
|
|
notice(const char *const &fmt, args&&... a)
|
|
|
|
{
|
|
|
|
vlog(facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
|
|
|
|
}
|
|
|
|
};
|
2017-03-18 04:24:25 +01:00
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct ircd::log::warning
|
2017-03-18 04:24:25 +01:00
|
|
|
{
|
2018-01-21 10:17:33 +01:00
|
|
|
template<class... args>
|
|
|
|
warning(const char *const &fmt, args&&... a)
|
|
|
|
{
|
|
|
|
vlog(facility::WARNING, fmt, va_rtti{std::forward<args>(a)...});
|
|
|
|
}
|
|
|
|
};
|
2016-08-26 06:38:15 +02:00
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct ircd::log::error
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-01-21 10:17:33 +01:00
|
|
|
template<class... args>
|
|
|
|
error(const char *const &fmt, args&&... a)
|
|
|
|
{
|
|
|
|
vlog(facility::ERROR, fmt, va_rtti{std::forward<args>(a)...});
|
|
|
|
}
|
|
|
|
};
|
2017-03-18 04:24:25 +01:00
|
|
|
|
2018-01-21 10:17:33 +01:00
|
|
|
struct ircd::log::critical
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-01-21 10:17:33 +01:00
|
|
|
template<class... args>
|
|
|
|
critical(const char *const &fmt, args&&... a)
|
|
|
|
{
|
|
|
|
vlog(facility::CRITICAL, fmt, va_rtti{std::forward<args>(a)...});
|
|
|
|
}
|
|
|
|
};
|
2017-03-18 04:24:25 +01:00
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
void
|
|
|
|
ircd::log::log::debug(const char *const &fmt,
|
|
|
|
args&&... a)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2017-10-05 01:27:36 +02:00
|
|
|
#ifdef RB_DEBUG
|
2017-03-18 04:24:25 +01:00
|
|
|
operator()(facility::DEBUG, fmt, va_rtti{std::forward<args>(a)...});
|
2017-10-05 01:27:36 +02:00
|
|
|
#endif
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
2017-03-18 04:24:25 +01:00
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
void
|
|
|
|
ircd::log::log::info(const char *const &fmt,
|
|
|
|
args&&... a)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2017-03-18 04:24:25 +01:00
|
|
|
operator()(facility::INFO, fmt, va_rtti{std::forward<args>(a)...});
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
2017-03-18 04:24:25 +01:00
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
void
|
|
|
|
ircd::log::log::notice(const char *const &fmt,
|
|
|
|
args&&... a)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2017-03-18 04:24:25 +01:00
|
|
|
operator()(facility::NOTICE, fmt, va_rtti{std::forward<args>(a)...});
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
2017-03-18 04:24:25 +01:00
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
void
|
|
|
|
ircd::log::log::warning(const char *const &fmt,
|
|
|
|
args&&... a)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2017-03-18 04:24:25 +01:00
|
|
|
operator()(facility::WARNING, fmt, va_rtti{std::forward<args>(a)...});
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
2017-03-18 04:24:25 +01:00
|
|
|
|
|
|
|
template<class... args>
|
|
|
|
void
|
|
|
|
ircd::log::log::error(const char *const &fmt,
|
|
|
|
args&&... a)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2017-03-18 04:24:25 +01:00
|
|
|
operator()(facility::ERROR, fmt, va_rtti{std::forward<args>(a)...});
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
2016-06-23 03:23:24 +02:00
|
|
|
|
2017-03-18 04:24:25 +01:00
|
|
|
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)...});
|
|
|
|
}
|