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
|
|
|
|
2018-07-01 23:10:20 +02:00
|
|
|
#include <RB_INC_IOSTREAM
|
|
|
|
// <iostream> inclusion here runs std::ios_base::Init() statically as this unit
|
|
|
|
// is initialized (GNU initialization order given in Makefile).
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd::log
|
2008-11-16 08:15:28 +01:00
|
|
|
{
|
2018-12-19 02:44:36 +01:00
|
|
|
struct confs;
|
2017-08-28 23:51:22 +02:00
|
|
|
|
2019-04-05 23:32:36 +02:00
|
|
|
static bool is_conf_mask_file(const string_view &name);
|
|
|
|
static bool is_conf_mask_console(const string_view &name);
|
|
|
|
static void slog(const log &, const level &, const window_buffer::closure &) noexcept;
|
|
|
|
static void vlog_threadsafe(const log &, const level &, const string_view &fmt, const va_rtti &ap);
|
|
|
|
static std::string file_path(const level &);
|
|
|
|
static void open(const level &);
|
|
|
|
static void mkdir();
|
|
|
|
|
|
|
|
extern const size_t CTX_NAME_TRUNC;
|
|
|
|
extern const size_t LOG_NAME_TRUNC;
|
|
|
|
extern const size_t LOG_BUFSIZE;
|
2019-08-02 07:20:04 +02:00
|
|
|
extern const std::array<string_view, num_of<level>()> console_ansi;
|
2018-12-19 21:52:08 +01:00
|
|
|
extern std::array<confs, num_of<level>()> confs;
|
2019-03-10 02:10:02 +01:00
|
|
|
extern conf::item<std::string> unmask_file;
|
|
|
|
extern conf::item<std::string> unmask_console;
|
|
|
|
extern conf::item<std::string> mask_file;
|
|
|
|
extern conf::item<std::string> mask_console;
|
2019-04-05 23:32:36 +02:00
|
|
|
extern std::array<std::ofstream, num_of<level>()> file;
|
|
|
|
extern std::array<ulong, num_of<level>()> console_quiet_stdout;
|
|
|
|
extern std::array<ulong, num_of<level>()> console_quiet_stderr;
|
2018-12-19 02:44:36 +01:00
|
|
|
std::ostream &out_console{std::cout};
|
|
|
|
std::ostream &err_console{std::cerr};
|
2017-08-28 23:51:22 +02:00
|
|
|
}
|
2014-03-03 05:25:47 +01:00
|
|
|
|
2018-12-19 02:44:36 +01:00
|
|
|
struct ircd::log::confs
|
|
|
|
{
|
|
|
|
conf::item<bool> file_enable;
|
|
|
|
conf::item<bool> file_flush;
|
|
|
|
conf::item<bool> console_stdout;
|
|
|
|
conf::item<bool> console_stderr;
|
|
|
|
conf::item<bool> console_flush;
|
|
|
|
};
|
|
|
|
|
2019-04-05 23:32:36 +02:00
|
|
|
/// Linkage for list of named loggers.
|
2019-04-17 05:48:00 +02:00
|
|
|
template<>
|
|
|
|
decltype(ircd::instance_list<ircd::log::log>::allocator)
|
|
|
|
ircd::instance_list<ircd::log::log>::allocator
|
|
|
|
{};
|
|
|
|
|
2019-04-05 23:32:36 +02:00
|
|
|
template<>
|
|
|
|
decltype(ircd::instance_list<ircd::log::log>::list)
|
|
|
|
ircd::instance_list<ircd::log::log>::list
|
2019-04-17 05:48:00 +02:00
|
|
|
{
|
|
|
|
allocator
|
|
|
|
};
|
2019-04-05 23:32:36 +02:00
|
|
|
|
|
|
|
decltype(ircd::log::file)
|
|
|
|
ircd::log::file;
|
|
|
|
|
|
|
|
decltype(ircd::log::console_quiet_stdout)
|
|
|
|
ircd::log::console_quiet_stdout;
|
|
|
|
|
|
|
|
decltype(ircd::log::console_quiet_stderr)
|
|
|
|
ircd::log::console_quiet_stderr;
|
|
|
|
|
|
|
|
decltype(ircd::log::LOG_BUFSIZE)
|
|
|
|
ircd::log::LOG_BUFSIZE
|
|
|
|
{
|
|
|
|
1024
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::log::LOG_NAME_TRUNC)
|
|
|
|
ircd::log::LOG_NAME_TRUNC
|
|
|
|
{
|
2019-04-05 23:37:10 +02:00
|
|
|
12
|
2019-04-05 23:32:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::log::CTX_NAME_TRUNC)
|
|
|
|
ircd::log::CTX_NAME_TRUNC
|
|
|
|
{
|
2019-07-20 23:56:10 +02:00
|
|
|
10
|
2019-04-05 23:32:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// The '*' logger is for log::mark()'s which do not target any specific named
|
|
|
|
/// logger because such mark()'s are not repeated to all named loggers. The '*'
|
|
|
|
/// logger should not otherwise be the target of log messages.
|
|
|
|
decltype(ircd::log::star)
|
|
|
|
ircd::log::star
|
|
|
|
{
|
|
|
|
"*", '*'
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The general logger is for all core and miscellaneous log messages. This
|
|
|
|
/// is the default logger target for log:: calls which do not pass a specific
|
|
|
|
/// logger.
|
|
|
|
decltype(ircd::log::general)
|
|
|
|
ircd::log::general
|
|
|
|
{
|
|
|
|
"ircd", 'G'
|
|
|
|
};
|
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
decltype(ircd::log::hook)
|
|
|
|
ircd::log::hook;
|
|
|
|
|
2019-08-04 01:11:14 +02:00
|
|
|
//
|
|
|
|
// init
|
|
|
|
//
|
|
|
|
|
2016-08-26 06:38:15 +02:00
|
|
|
void
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::init()
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2019-12-04 01:45:59 +01:00
|
|
|
// DEBUG is very noisy so it always starts off by default unless -debug
|
2018-12-19 02:44:36 +01:00
|
|
|
if(!ircd::debugmode)
|
2018-12-19 21:52:08 +01:00
|
|
|
console_disable(level::DEBUG);
|
2018-12-16 03:00:18 +01:00
|
|
|
|
2019-12-04 01:45:59 +01:00
|
|
|
// In non-debug-mode compilation we don't want DWARNING and DERROR
|
|
|
|
// messages which weren't DCE'ed to be displayed by default.
|
|
|
|
if(!RB_DEBUG_LEVEL && !ircd::debugmode)
|
|
|
|
{
|
|
|
|
console_disable(level::DERROR);
|
|
|
|
console_disable(level::DWARNING);
|
|
|
|
}
|
|
|
|
|
2019-04-15 20:08:40 +02:00
|
|
|
if(ircd::write_avoid)
|
|
|
|
return;
|
|
|
|
|
2018-12-16 03:00:18 +01:00
|
|
|
mkdir();
|
2008-11-16 08:15:28 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
void
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::fini()
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2018-02-07 21:03:56 +01:00
|
|
|
flush();
|
|
|
|
close();
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2018-12-16 03:00:18 +01:00
|
|
|
void
|
|
|
|
ircd::log::mkdir()
|
|
|
|
{
|
2018-12-30 00:27:58 +01:00
|
|
|
const auto &dir
|
2018-12-16 03:00:18 +01:00
|
|
|
{
|
2019-06-23 10:58:25 +02:00
|
|
|
fs::path(fs::base::LOG)
|
2018-12-16 03:00:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if(fs::exists(dir))
|
|
|
|
return;
|
|
|
|
|
|
|
|
fs::mkdir(dir);
|
|
|
|
}
|
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
//
|
|
|
|
// interface
|
|
|
|
//
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
void
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::open()
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
for_each<level>([](const level &lev)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-12-23 02:16:17 +01:00
|
|
|
if(lev > RB_LOG_LEVEL)
|
|
|
|
return;
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
const auto &conf(confs.at(lev));
|
2018-12-19 02:44:36 +01:00
|
|
|
if(!bool(conf.file_enable))
|
2016-09-06 19:09:11 +02:00
|
|
|
return;
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
if(file[lev].is_open())
|
|
|
|
file[lev].close();
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
file[lev].clear();
|
|
|
|
file[lev].exceptions(std::ios::badbit | std::ios::failbit);
|
|
|
|
open(lev);
|
2016-08-26 06:38:15 +02:00
|
|
|
});
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-26 06:38:15 +02:00
|
|
|
void
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::close()
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
for_each<level>([](const level &lev)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2018-12-23 02:16:17 +01:00
|
|
|
if(lev > RB_LOG_LEVEL)
|
|
|
|
return;
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
if(file[lev].is_open())
|
|
|
|
file[lev].close();
|
2016-08-26 06:38:15 +02:00
|
|
|
});
|
2014-03-03 05:25:47 +01:00
|
|
|
}
|
2008-04-20 05:42:30 +02:00
|
|
|
|
|
|
|
void
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::flush()
|
2008-04-20 05:42:30 +02:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
for_each<level>([](const level &lev)
|
2008-04-20 05:42:30 +02:00
|
|
|
{
|
2018-12-23 02:16:17 +01:00
|
|
|
if(lev > RB_LOG_LEVEL)
|
|
|
|
return;
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
file[lev].flush();
|
2016-08-26 06:38:15 +02:00
|
|
|
});
|
2018-02-07 21:03:56 +01:00
|
|
|
|
|
|
|
std::flush(out_console);
|
|
|
|
std::flush(err_console);
|
2008-04-20 05:42:30 +02:00
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-26 06:38:15 +02:00
|
|
|
void
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::open(const level &lev)
|
2016-08-26 06:38:15 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto &mode(std::ios::app);
|
2018-12-19 21:52:08 +01:00
|
|
|
const auto &path(file_path(lev));
|
|
|
|
file[lev].open(path.c_str(), mode);
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
2016-06-23 03:23:24 +02:00
|
|
|
{
|
2018-08-16 09:19:37 +02:00
|
|
|
fprintf(stderr, "!!! Opening log file [%s] failed: %s",
|
2018-12-19 21:52:08 +01:00
|
|
|
file_path(lev).c_str(),
|
2018-08-16 09:19:37 +02:00
|
|
|
e.what());
|
2016-08-26 06:38:15 +02:00
|
|
|
throw;
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2018-12-16 03:00:18 +01:00
|
|
|
std::string
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::file_path(const level &lev)
|
2018-12-16 03:00:18 +01:00
|
|
|
{
|
2019-06-23 10:58:25 +02:00
|
|
|
return fs::path_string(fs::base::LOG, reflect(lev));
|
2018-12-16 03:00:18 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:00:10 +01:00
|
|
|
void
|
|
|
|
ircd::log::console_enable()
|
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
for_each<level>([](const level &lev)
|
2018-12-06 04:00:10 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
console_enable(lev);
|
2018-12-06 04:00:10 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::log::console_disable()
|
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
for_each<level>([](const level &lev)
|
2018-12-06 04:00:10 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
console_disable(lev);
|
2018-12-06 04:00:10 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-22 01:11:24 +01:00
|
|
|
void
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::console_enable(const level &lev)
|
2018-02-22 01:11:24 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
if(console_quiet_stdout[lev])
|
|
|
|
console_quiet_stdout[lev]--;
|
2018-12-19 02:44:36 +01:00
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
if(console_quiet_stderr[lev])
|
|
|
|
console_quiet_stderr[lev]--;
|
2018-02-22 01:11:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::console_disable(const level &lev)
|
2018-02-22 01:11:24 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
console_quiet_stdout[lev]++;
|
|
|
|
console_quiet_stderr[lev]++;
|
2018-02-22 01:11:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::console_enabled(const level &lev)
|
2018-02-22 01:11:24 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
return !console_quiet_stdout[lev] ||
|
|
|
|
!console_quiet_stderr[lev];
|
2018-02-22 01:11:24 +01:00
|
|
|
}
|
|
|
|
|
2018-04-24 00:46:09 +02:00
|
|
|
void
|
2019-03-10 01:17:56 +01:00
|
|
|
ircd::log::file_mask(const vector_view<const string_view> &list)
|
|
|
|
{
|
|
|
|
for(auto *const &log : log::list)
|
|
|
|
log->fmasked = std::find(begin(list), end(list), log->name) != end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::log::file_unmask(const vector_view<const string_view> &list)
|
|
|
|
{
|
|
|
|
for(auto *const &log : log::list)
|
|
|
|
log->fmasked = std::find(begin(list), end(list), log->name) == end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::log::console_mask(const vector_view<const string_view> &list)
|
2018-04-24 00:46:09 +02:00
|
|
|
{
|
|
|
|
for(auto *const &log : log::list)
|
|
|
|
log->cmasked = std::find(begin(list), end(list), log->name) != end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-10 01:17:56 +01:00
|
|
|
ircd::log::console_unmask(const vector_view<const string_view> &list)
|
2018-04-24 00:46:09 +02:00
|
|
|
{
|
|
|
|
for(auto *const &log : log::list)
|
|
|
|
log->cmasked = std::find(begin(list), end(list), log->name) == end(list);
|
|
|
|
}
|
|
|
|
|
2018-04-23 23:14:26 +02:00
|
|
|
//
|
|
|
|
// console quiet
|
|
|
|
//
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::console_quiet::console_quiet(const bool &showmsg)
|
2016-09-07 01:31:29 +02:00
|
|
|
{
|
|
|
|
if(showmsg)
|
|
|
|
notice("Log messages are now quieted at the console");
|
|
|
|
|
2018-12-19 02:44:36 +01:00
|
|
|
console_disable();
|
2016-09-07 01:31:29 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
ircd::log::console_quiet::~console_quiet()
|
2016-09-07 01:31:29 +02:00
|
|
|
{
|
2018-12-19 02:44:36 +01:00
|
|
|
console_enable();
|
2016-09-07 01:31:29 +02:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:14:26 +02:00
|
|
|
//
|
|
|
|
// mark
|
|
|
|
//
|
2016-03-29 02:06:31 +02:00
|
|
|
|
2018-04-23 23:14:26 +02:00
|
|
|
ircd::log::mark::mark(const string_view &msg)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
for_each<level>([&msg]
|
|
|
|
(const auto &lev)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-12-23 02:16:17 +01:00
|
|
|
if(lev > RB_LOG_LEVEL)
|
|
|
|
return;
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
mark(lev, msg);
|
2016-08-26 06:38:15 +02:00
|
|
|
});
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::mark::mark(const level &lev,
|
2018-04-23 23:14:26 +02:00
|
|
|
const string_view &msg)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
vlog(star, lev, "%s", msg);
|
2017-10-12 02:40:49 +02:00
|
|
|
}
|
|
|
|
|
2018-04-23 23:14:26 +02:00
|
|
|
//
|
|
|
|
// log
|
|
|
|
//
|
|
|
|
|
2018-04-24 00:46:09 +02:00
|
|
|
ircd::log::log *
|
|
|
|
ircd::log::log::find(const string_view &name)
|
|
|
|
{
|
|
|
|
const auto it
|
|
|
|
{
|
|
|
|
std::find_if(begin(list), end(list), [&name]
|
|
|
|
(const auto *const &log)
|
|
|
|
{
|
|
|
|
return log->name == name;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::log::log *
|
|
|
|
ircd::log::log::find(const char &snote)
|
|
|
|
{
|
|
|
|
const auto it
|
|
|
|
{
|
|
|
|
std::find_if(begin(list), end(list), [&snote]
|
|
|
|
(const auto *const &log)
|
|
|
|
{
|
|
|
|
return log->snote == snote;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// This function is related to cross-thread logging; its purpose
|
|
|
|
/// is to check if a given named logger still exists after the pointer
|
|
|
|
/// is conveyed to the main thread from some other thread.
|
|
|
|
bool
|
|
|
|
ircd::log::log::exists(const log *const &ptr)
|
|
|
|
{
|
|
|
|
const auto it
|
|
|
|
{
|
|
|
|
std::find_if(begin(list), end(list), [&ptr]
|
|
|
|
(const auto *const &log)
|
|
|
|
{
|
|
|
|
return log == ptr;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
return it != end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// log::log
|
|
|
|
//
|
|
|
|
|
2018-04-23 23:14:26 +02:00
|
|
|
ircd::log::log::log(const string_view &name,
|
|
|
|
const char &snote)
|
|
|
|
:name{name}
|
|
|
|
,snote{snote}
|
2019-03-10 02:10:02 +01:00
|
|
|
,cmasked
|
|
|
|
{
|
|
|
|
is_conf_mask_console(name)
|
|
|
|
}
|
|
|
|
,fmasked
|
|
|
|
{
|
|
|
|
is_conf_mask_file(name)
|
|
|
|
}
|
2018-04-23 23:14:26 +02:00
|
|
|
{
|
2018-04-23 23:48:48 +02:00
|
|
|
for(const auto *const &other : list)
|
|
|
|
{
|
|
|
|
if(other == this)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(other->name == name)
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"Logger with name '%s' already exists at %p",
|
|
|
|
name,
|
|
|
|
other
|
|
|
|
};
|
|
|
|
|
|
|
|
if(snote != '\0' && other->snote == snote)
|
|
|
|
throw ircd::error
|
|
|
|
{
|
|
|
|
"Logger with snote '%c' is '%s' and already exists at %p",
|
|
|
|
snote,
|
2018-04-25 02:56:43 +02:00
|
|
|
other->name,
|
2018-04-23 23:48:48 +02:00
|
|
|
other
|
|
|
|
};
|
|
|
|
}
|
2018-04-23 23:14:26 +02:00
|
|
|
}
|
|
|
|
|
2019-06-24 06:28:50 +02:00
|
|
|
// required for instance_list template instantiation.
|
|
|
|
ircd::log::log::~log()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-23 23:14:26 +02:00
|
|
|
//
|
|
|
|
// vlog
|
|
|
|
//
|
|
|
|
|
2017-10-12 02:40:49 +02:00
|
|
|
/// ircd::log is not thread-safe. This internal function is called when the
|
|
|
|
/// normal vlog() detects it's not on the main IRCd thread. It then generates
|
|
|
|
/// the formatted log message on this thread, and posts the message to the
|
|
|
|
/// main IRCd event loop which is running on the main thread.
|
|
|
|
void
|
2018-04-24 00:46:09 +02:00
|
|
|
ircd::log::vlog_threadsafe(const log &log,
|
2018-12-19 21:52:08 +01:00
|
|
|
const level &lev,
|
2018-12-10 22:00:33 +01:00
|
|
|
const string_view &fmt,
|
2017-10-12 02:40:49 +02:00
|
|
|
const va_rtti &ap)
|
|
|
|
{
|
2019-03-27 01:29:50 +01:00
|
|
|
static ios::descriptor descriptor
|
|
|
|
{
|
|
|
|
"ircd::log::vlog_threadsafe"
|
|
|
|
};
|
|
|
|
|
2017-10-12 02:40:49 +02:00
|
|
|
// Generate the formatted message on this thread first
|
2017-10-17 09:41:10 +02:00
|
|
|
std::string str
|
2017-10-12 02:40:49 +02:00
|
|
|
{
|
|
|
|
fmt::vsnstringf(1024, fmt, ap)
|
|
|
|
};
|
|
|
|
|
2018-04-24 00:46:09 +02:00
|
|
|
// The pointer to the logger is copied to the main thread.
|
|
|
|
auto *const logp{&log};
|
2019-03-27 01:29:50 +01:00
|
|
|
ircd::post(descriptor, [lev, str(std::move(str)), logp]
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-04-24 00:46:09 +02:00
|
|
|
// If that named logger was destroyed while this closure was
|
|
|
|
// travelling to the main thread then we just discard this message.
|
|
|
|
if(!log::exists(logp))
|
|
|
|
return;
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
slog(*logp, lev, [&str](const mutable_buffer &out) -> size_t
|
2017-10-12 02:40:49 +02:00
|
|
|
{
|
2017-12-23 22:06:12 +01:00
|
|
|
return copy(out, string_view{str});
|
2017-10-12 02:40:49 +02:00
|
|
|
});
|
2016-08-26 06:38:15 +02:00
|
|
|
});
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2018-04-24 00:46:09 +02:00
|
|
|
ircd::log::vlog::vlog(const log &log,
|
2018-12-19 21:52:08 +01:00
|
|
|
const level &lev,
|
2018-12-10 22:00:33 +01:00
|
|
|
const string_view &fmt,
|
2018-04-23 23:14:26 +02:00
|
|
|
const va_rtti &ap)
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2018-12-28 22:18:34 +01:00
|
|
|
if(!is_main_thread() && likely(ios::available()))
|
2017-10-12 02:40:49 +02:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
vlog_threadsafe(log, lev, fmt, ap);
|
2017-10-12 02:40:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
slog(log, lev, [&fmt, &ap](const mutable_buffer &out) -> size_t
|
2016-08-26 06:38:15 +02:00
|
|
|
{
|
2017-12-23 22:06:12 +01:00
|
|
|
return fmt::vsprintf(out, fmt, ap);
|
2017-10-17 09:41:10 +02:00
|
|
|
});
|
2017-10-16 06:27:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-23 07:54:32 +01:00
|
|
|
namespace ircd::log
|
|
|
|
{
|
|
|
|
bool entered;
|
2019-08-04 03:12:24 +02:00
|
|
|
|
|
|
|
static bool can_skip(const log &, const level &);
|
2017-12-23 07:54:32 +01:00
|
|
|
}
|
|
|
|
|
2016-08-26 06:38:15 +02:00
|
|
|
void
|
2019-08-04 03:12:24 +02:00
|
|
|
__attribute__((optimize("3")))
|
2018-04-24 00:46:09 +02:00
|
|
|
ircd::log::slog(const log &log,
|
2018-12-19 21:52:08 +01:00
|
|
|
const level &lev,
|
2018-02-08 06:30:20 +01:00
|
|
|
const window_buffer::closure &closure)
|
2017-10-17 09:41:10 +02:00
|
|
|
noexcept
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
if(can_skip(log, lev))
|
2018-04-24 00:46:09 +02:00
|
|
|
return;
|
|
|
|
|
2017-12-23 07:54:32 +01:00
|
|
|
// Have to be on the main thread to call slog().
|
2017-10-12 02:40:49 +02:00
|
|
|
assert_main_thread();
|
2017-12-23 07:54:32 +01:00
|
|
|
|
|
|
|
// During the composition of this log message, if another log message
|
|
|
|
// is created from calls for normal reasons or from errors, it's a
|
|
|
|
// problem too. We can only have one log slog() at a time for now...
|
|
|
|
const reentrance_assertion<entered> ra;
|
|
|
|
|
|
|
|
// If slog() yields for some reason that's not good either...
|
2017-10-17 09:41:10 +02:00
|
|
|
const ctx::critical_assertion ca;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2017-12-23 07:54:32 +01:00
|
|
|
// The principal buffer doesn't have to be static but courtesy of all the
|
|
|
|
// above effort we might as well take advantage...
|
2019-04-05 23:32:36 +02:00
|
|
|
static char buf[LOG_BUFSIZE], date[64];
|
2017-11-25 22:19:32 +01:00
|
|
|
|
2017-12-23 22:06:12 +01:00
|
|
|
// Maximum size of log line leaving 2 characters for \r\n
|
|
|
|
const size_t max(sizeof(buf) - 2);
|
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
// Get the ANSI color for the level.
|
2019-08-02 07:20:04 +02:00
|
|
|
const string_view &console_ansi
|
|
|
|
{
|
|
|
|
ircd::log::console_ansi.at(lev)
|
|
|
|
};
|
|
|
|
|
2019-08-14 04:38:08 +02:00
|
|
|
// Get one of the two primary slice epoch counters. If this is being
|
|
|
|
// invoked on an ircd::ctx, we grab the ctx slice counter; otherwise we
|
|
|
|
// grab the ios slice counter.
|
|
|
|
const auto &epoch
|
|
|
|
{
|
|
|
|
ctx::current? ctx::epoch() : ios::epoch()
|
|
|
|
};
|
|
|
|
|
|
|
|
// With two possible slice epoch counters, the number of characters
|
|
|
|
// required for the epoch column might be different between two adjacent
|
|
|
|
// log messages. To maintain alignment we use this monotonic counter which
|
|
|
|
// gets bumped the first time either epoch value requires more columns. To
|
|
|
|
// minimize overhead here we simply settle for 3 different widths.
|
|
|
|
static size_t epoch_width{6}; epoch_width =
|
|
|
|
epoch < 1'000'000UL?
|
|
|
|
std::max(epoch_width, 6UL):
|
|
|
|
epoch < 100'000'000UL?
|
|
|
|
std::max(epoch_width, 8UL):
|
|
|
|
std::max(epoch_width, 12UL);
|
|
|
|
|
2017-12-23 22:06:12 +01:00
|
|
|
// Compose the prefix sequence into the buffer through stringstream
|
2017-10-25 22:42:41 +02:00
|
|
|
std::stringstream s;
|
2018-05-04 05:08:24 +02:00
|
|
|
pubsetbuf(s, buf);
|
2019-07-16 21:16:43 +02:00
|
|
|
s
|
2019-08-04 05:04:08 +02:00
|
|
|
<< microdate(date)
|
2019-07-16 21:16:43 +02:00
|
|
|
<< ' '
|
2019-08-14 04:38:08 +02:00
|
|
|
<< std::setw(epoch_width)
|
2019-07-16 21:16:43 +02:00
|
|
|
<< std::right
|
2019-08-14 04:38:08 +02:00
|
|
|
<< epoch
|
2019-07-16 21:16:43 +02:00
|
|
|
<< ' '
|
2019-08-02 07:20:04 +02:00
|
|
|
<< console_ansi
|
2019-07-16 21:16:43 +02:00
|
|
|
<< std::setw(8)
|
|
|
|
<< std::right
|
|
|
|
<< reflect(lev)
|
2019-08-02 07:20:04 +02:00
|
|
|
<< (console_ansi? "\033[0m " : " ")
|
2019-07-16 21:16:43 +02:00
|
|
|
// << (log.snote? log.snote : '-')
|
|
|
|
<< std::setw(LOG_NAME_TRUNC)
|
|
|
|
<< std::left
|
|
|
|
<< trunc(log.name, LOG_NAME_TRUNC)
|
|
|
|
<< ' '
|
|
|
|
<< std::setw(5)
|
|
|
|
<< std::right
|
|
|
|
<< ctx::id()
|
|
|
|
<< ' '
|
|
|
|
<< std::setw(CTX_NAME_TRUNC)
|
|
|
|
<< std::left
|
|
|
|
<< trunc(ctx::name(), CTX_NAME_TRUNC)
|
|
|
|
<< " :";
|
2017-12-23 22:06:12 +01:00
|
|
|
|
|
|
|
// Compose the user message after prefix
|
|
|
|
const size_t pos(s.tellp());
|
|
|
|
const mutable_buffer userspace{buf + pos, max - pos};
|
2018-02-08 06:30:20 +01:00
|
|
|
window_buffer sb{userspace};
|
2017-12-23 22:06:12 +01:00
|
|
|
sb(closure);
|
|
|
|
|
|
|
|
// Compose the newline after user message.
|
|
|
|
size_t len{pos + sb.consumed()};
|
|
|
|
assert(len + 2 <= sizeof(buf));
|
|
|
|
buf[len++] = '\r';
|
|
|
|
buf[len++] = '\n';
|
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
// The final message
|
2017-12-23 22:06:12 +01:00
|
|
|
assert(len <= sizeof(buf));
|
|
|
|
const string_view msg{buf, len};
|
2019-08-04 03:12:24 +02:00
|
|
|
|
|
|
|
// Call the hooks listening for log messages. The return value in
|
|
|
|
// `used` indicates at least one function was called, which we expect
|
|
|
|
// after calling can_skip() above.
|
|
|
|
bool used {false};
|
|
|
|
hook(used, log, lev, msg);
|
|
|
|
assert(used);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
__attribute__((optimize("3")))
|
|
|
|
ircd::log::can_skip(const log &log,
|
|
|
|
const level &lev)
|
|
|
|
{
|
|
|
|
// Nobody is listening.
|
|
|
|
if(hook.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If used remains false, we can skip generating this log message; none
|
|
|
|
// of the listeners will be making use of it.
|
|
|
|
bool used {false};
|
|
|
|
hook(used, log, lev, string_view{});
|
|
|
|
return !used;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Primary internal log hooks. This will likely be moved out to
|
|
|
|
// `$(topdir)/construct` at some point.
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace ircd::log
|
|
|
|
{
|
|
|
|
static void check(std::ostream &) noexcept;
|
|
|
|
static void handle_to_stdout(bool &, const log &, const level &, const string_view &) noexcept;
|
|
|
|
static void handle_to_file(bool &, const log &, const level &, const string_view &) noexcept;
|
|
|
|
|
|
|
|
extern hook::callback log_to_stdout;
|
|
|
|
extern hook::callback log_to_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::log::log_to_file)
|
|
|
|
ircd::log::log_to_file
|
|
|
|
{
|
|
|
|
hook, handle_to_file
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::log::handle_to_file(bool &ret,
|
|
|
|
const log &log,
|
|
|
|
const level &lev,
|
|
|
|
const string_view &msg)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const auto &conf
|
|
|
|
{
|
|
|
|
confs.at(lev)
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool copy_to_file
|
|
|
|
{
|
|
|
|
file[lev].is_open()
|
|
|
|
&& (log.fmasked || lev == level::CRITICAL)
|
|
|
|
};
|
|
|
|
|
|
|
|
ret |= copy_to_file;
|
|
|
|
if(!copy_to_file || !msg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file[lev].clear();
|
|
|
|
check(file[lev]);
|
|
|
|
file[lev].write(data(msg), size(msg));
|
|
|
|
if(conf.file_flush)
|
|
|
|
std::flush(file[lev]);
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::log::log_to_stdout)
|
|
|
|
ircd::log::log_to_stdout
|
|
|
|
{
|
|
|
|
hook, handle_to_stdout
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::log::handle_to_stdout(bool &ret,
|
|
|
|
const log &log,
|
|
|
|
const level &lev,
|
|
|
|
const string_view &msg)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
const auto &conf
|
2017-10-25 22:42:41 +02:00
|
|
|
{
|
2019-08-04 03:12:24 +02:00
|
|
|
confs.at(lev)
|
|
|
|
};
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2019-01-04 00:56:21 +01:00
|
|
|
const bool copy_to_stderr
|
|
|
|
{
|
|
|
|
bool(conf.console_stderr)
|
|
|
|
&& ((!console_quiet_stderr[lev] && log.cmasked) || lev == level::CRITICAL)
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool copy_to_stdout
|
|
|
|
{
|
|
|
|
bool(conf.console_stdout)
|
2019-08-13 12:26:37 +02:00
|
|
|
&& ((!console_quiet_stdout[lev] && log.cmasked) || log.snote == '*')
|
2019-01-04 00:56:21 +01:00
|
|
|
};
|
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
ret |= copy_to_stdout | copy_to_stderr;
|
|
|
|
if((!copy_to_stdout && !copy_to_stderr) || !msg)
|
|
|
|
return;
|
2019-01-04 00:56:21 +01:00
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
if(unlikely(copy_to_stderr))
|
2017-10-25 22:42:41 +02:00
|
|
|
{
|
2017-10-27 00:31:50 +02:00
|
|
|
err_console.clear();
|
2019-08-04 03:12:24 +02:00
|
|
|
check(err_console);
|
|
|
|
err_console.write(data(msg), size(msg));
|
2017-10-25 22:42:41 +02:00
|
|
|
}
|
2016-08-26 06:38:15 +02:00
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
if(likely(copy_to_stdout))
|
2017-10-25 22:42:41 +02:00
|
|
|
{
|
2017-10-27 00:31:50 +02:00
|
|
|
out_console.clear();
|
2019-08-04 03:12:24 +02:00
|
|
|
check(out_console);
|
|
|
|
out_console.write(data(msg), size(msg));
|
2018-12-19 02:44:36 +01:00
|
|
|
if(conf.console_flush)
|
2017-10-25 22:42:41 +02:00
|
|
|
std::flush(out_console);
|
|
|
|
}
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2019-08-04 03:12:24 +02:00
|
|
|
//
|
|
|
|
// ircd::log util
|
|
|
|
//
|
2018-12-19 02:44:36 +01:00
|
|
|
|
2017-10-17 09:41:10 +02:00
|
|
|
void
|
|
|
|
ircd::log::check(std::ostream &s)
|
|
|
|
noexcept try
|
|
|
|
{
|
|
|
|
if(likely(s.good()))
|
2016-08-26 06:38:15 +02:00
|
|
|
return;
|
2016-06-23 03:23:24 +02:00
|
|
|
|
2018-08-16 09:19:37 +02:00
|
|
|
thread_local char buf[128];
|
2017-10-17 09:41:10 +02:00
|
|
|
snprintf(buf, sizeof(buf), "fatal: log stream good[%d] bad[%d] fail[%d] eof[%d]",
|
|
|
|
s.good(),
|
|
|
|
s.bad(),
|
|
|
|
s.fail(),
|
|
|
|
s.eof());
|
|
|
|
|
|
|
|
fprintf(stderr, "log stream(%p) fatal: %s\n", (const void *)&s, buf);
|
|
|
|
fprintf(stdout, "log stream(%p) fatal: %s\n", (const void *)&s, buf);
|
2017-10-27 00:31:50 +02:00
|
|
|
fflush(stderr);
|
|
|
|
fflush(stdout);
|
2017-10-17 09:41:10 +02:00
|
|
|
s.exceptions(s.eofbit | s.failbit | s.badbit);
|
|
|
|
throw std::runtime_error(buf);
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", e.what());
|
|
|
|
fprintf(stdout, "%s\n", e.what());
|
2017-10-27 00:31:50 +02:00
|
|
|
fflush(stderr);
|
|
|
|
fflush(stdout);
|
2017-11-26 01:20:42 +01:00
|
|
|
ircd::terminate();
|
2016-08-26 06:38:15 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::level
|
2018-12-12 17:47:13 +01:00
|
|
|
ircd::log::reflect(const string_view &f)
|
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
if(f == "CRITICAL") return level::CRITICAL;
|
|
|
|
if(f == "ERROR") return level::ERROR;
|
|
|
|
if(f == "DERROR") return level::DERROR;
|
|
|
|
if(f == "DWARNING") return level::DWARNING;
|
|
|
|
if(f == "WARNING") return level::WARNING;
|
|
|
|
if(f == "NOTICE") return level::NOTICE;
|
|
|
|
if(f == "INFO") return level::INFO;
|
|
|
|
if(f == "DEBUG") return level::DEBUG;
|
2018-12-12 17:47:13 +01:00
|
|
|
|
|
|
|
throw ircd::error
|
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
"'%s' is not a recognized log level", f
|
2018-12-12 17:47:13 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::string_view
|
2018-12-19 21:52:08 +01:00
|
|
|
ircd::log::reflect(const level &f)
|
2016-06-23 03:23:24 +02:00
|
|
|
{
|
2016-08-26 06:38:15 +02:00
|
|
|
switch(f)
|
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
case level::CRITICAL: return "CRITICAL";
|
|
|
|
case level::ERROR: return "ERROR";
|
|
|
|
case level::DERROR: return "ERROR";
|
|
|
|
case level::WARNING: return "WARNING";
|
|
|
|
case level::DWARNING: return "WARNING";
|
|
|
|
case level::INFO: return "INFO";
|
|
|
|
case level::NOTICE: return "NOTICE";
|
|
|
|
case level::DEBUG: return "DEBUG";
|
|
|
|
case level::_NUM_: break; // Allows -Wswitch to remind developer to add reflection here
|
2016-08-26 06:38:15 +02:00
|
|
|
};
|
|
|
|
|
2019-01-14 00:50:04 +01:00
|
|
|
throw panic
|
2018-12-12 17:47:13 +01:00
|
|
|
{
|
2018-12-19 21:52:08 +01:00
|
|
|
"'%d' is not a recognized log level", int(f)
|
2018-12-12 17:47:13 +01:00
|
|
|
};
|
2016-06-23 03:23:24 +02:00
|
|
|
}
|
2016-08-13 05:05:54 +02:00
|
|
|
|
2019-08-02 07:20:04 +02:00
|
|
|
decltype(ircd::log::console_ansi)
|
|
|
|
ircd::log::console_ansi
|
2018-12-19 02:44:36 +01:00
|
|
|
{{
|
|
|
|
"\033[1;5;37;45m"_sv, // CRITICAL
|
|
|
|
"\033[1;37;41m"_sv, // ERROR
|
|
|
|
"\033[0;30;43m"_sv, // WARNING
|
|
|
|
"\033[1;37;46m"_sv, // NOTICE
|
|
|
|
"\033[1;37;42m"_sv, // INFO
|
|
|
|
"\033[0;31;47m"_sv, // DERROR
|
|
|
|
"\033[0;30;47m"_sv, // DWARNING
|
|
|
|
"\033[1;30;47m"_sv, // DEBUG
|
|
|
|
}};
|
|
|
|
|
2019-03-10 02:10:02 +01:00
|
|
|
bool
|
|
|
|
ircd::log::is_conf_mask_console(const string_view &name)
|
|
|
|
{
|
|
|
|
if(token_exists(string_view(mask_console), ' ', name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(token_exists(string_view(unmask_console), ' ', name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// When nothing is in the list then we consider this item masked.
|
|
|
|
return empty(string_view(mask_console));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::log::is_conf_mask_file(const string_view &name)
|
|
|
|
{
|
|
|
|
if(token_exists(string_view(mask_file), ' ', name))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if(token_exists(string_view(unmask_file), ' ', name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// When nothing is in the list then we consider this item masked.
|
|
|
|
return empty(string_view(mask_file));
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::log::unmask_file)
|
|
|
|
ircd::log::unmask_file
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.unmask.file" },
|
|
|
|
{ "default", string_view{} },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!empty(string_view(unmask_file)))
|
|
|
|
file_unmask(tokens<std::vector>(unmask_file, ' '));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::log::unmask_console)
|
|
|
|
ircd::log::unmask_console
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.unmask.console" },
|
|
|
|
{ "default", string_view{} },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!empty(string_view(unmask_console)))
|
|
|
|
console_unmask(tokens<std::vector>(unmask_console, ' '));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::log::mask_file)
|
|
|
|
ircd::log::mask_file
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.mask.file" },
|
|
|
|
{ "default", string_view{} },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!empty(string_view(mask_file)))
|
|
|
|
file_mask(tokens<std::vector>(mask_file, ' '));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
decltype(ircd::log::mask_console)
|
|
|
|
ircd::log::mask_console
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.mask.console" },
|
|
|
|
{ "default", string_view{} },
|
|
|
|
}, []
|
|
|
|
{
|
|
|
|
if(!empty(string_view(mask_console)))
|
|
|
|
console_mask(tokens<std::vector>(mask_console, ' '));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-19 02:44:36 +01:00
|
|
|
decltype(ircd::log::confs)
|
|
|
|
ircd::log::confs
|
|
|
|
{{
|
|
|
|
// CRITICAL
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.critical.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.critical.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.critical.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.critical.console.stderr" },
|
2018-12-19 23:14:28 +01:00
|
|
|
{ "default", false },
|
2018-12-19 02:44:36 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.critical.console.flush" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ERROR
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.error.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.error.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.error.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.error.console.stderr" },
|
2018-12-19 23:14:28 +01:00
|
|
|
{ "default", false },
|
2018-12-19 02:44:36 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.error.console.flush" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// WARNING
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.warning.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.warning.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.warning.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.warning.console.stderr" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.warning.console.flush" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// NOTICE
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.notice.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.notice.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.notice.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.notice.console.stderr" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.notice.console.flush" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// INFO
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.info.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.info.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.info.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.info.console.stderr" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.info.console.flush" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// DERROR
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.derror.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.derror.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.derror.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.derror.console.stderr" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.derror.console.flush" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// DWARNING
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.dwarning.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.dwarning.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.dwarning.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.dwarning.console.stderr" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.dwarning.console.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// DEBUG
|
|
|
|
{
|
|
|
|
// file enable
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.debug.file.enable" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// file flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.debug.file.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stdout
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.debug.console.stdout" },
|
|
|
|
{ "default", true },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console enable on stderr
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.debug.console.stderr" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
|
|
|
|
// console flush
|
|
|
|
{
|
|
|
|
{ "name", "ircd.log.debug.console.flush" },
|
|
|
|
{ "default", false },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}};
|