mirror of
https://github.com/ceph/ceph
synced 2024-12-27 14:03:25 +00:00
mon: allow syslog level and facility for cluster log to be controlled
Allow user to control the minimum level to go to syslog for the client- and server-side submission paths for the cluster log, along with the syslog 'facility'. See syslog(3) man page. Also move the level checks into a LogEntry method. Closes: #3704 Signed-off-by: Sage Weil <sage@inktank.com> Reviewed-by: Joao Luis <joao.luis@inktank.com>
This commit is contained in:
parent
04f3fe4e2c
commit
ceb390f672
@ -86,10 +86,8 @@ void LogClient::do_log(clog_type type, const std::string& s)
|
||||
|
||||
// log to syslog?
|
||||
if (cct->_conf->clog_to_syslog) {
|
||||
ostringstream oss;
|
||||
oss << e;
|
||||
string str(oss.str());
|
||||
syslog(clog_type_to_syslog_prio(e.type) | LOG_USER, "%s", str.c_str());
|
||||
e.log_to_syslog(cct->_conf->clog_to_syslog_level,
|
||||
cct->_conf->clog_to_syslog_facility);
|
||||
}
|
||||
|
||||
// log to monitor?
|
||||
|
@ -1,28 +1,14 @@
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "LogEntry.h"
|
||||
#include "Formatter.h"
|
||||
|
||||
#include "include/stringify.h"
|
||||
|
||||
|
||||
int clog_type_to_syslog_prio(clog_type t)
|
||||
{
|
||||
switch (t) {
|
||||
case CLOG_DEBUG:
|
||||
return LOG_DEBUG;
|
||||
case CLOG_INFO:
|
||||
return LOG_INFO;
|
||||
case CLOG_WARN:
|
||||
return LOG_WARNING;
|
||||
case CLOG_ERROR:
|
||||
return LOG_ERR;
|
||||
case CLOG_SEC:
|
||||
return LOG_CRIT;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// LogEntryKey
|
||||
@ -56,6 +42,104 @@ void LogEntryKey::generate_test_instances(list<LogEntryKey*>& o)
|
||||
|
||||
// ----
|
||||
|
||||
int clog_type_to_syslog_level(clog_type t)
|
||||
{
|
||||
switch (t) {
|
||||
case CLOG_DEBUG:
|
||||
return LOG_DEBUG;
|
||||
case CLOG_INFO:
|
||||
return LOG_INFO;
|
||||
case CLOG_WARN:
|
||||
return LOG_WARNING;
|
||||
case CLOG_ERROR:
|
||||
return LOG_ERR;
|
||||
case CLOG_SEC:
|
||||
return LOG_CRIT;
|
||||
default:
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int string_to_syslog_level(string s)
|
||||
{
|
||||
if (boost::iequals(s, "debug"))
|
||||
return LOG_DEBUG;
|
||||
if (boost::iequals(s, "info") ||
|
||||
boost::iequals(s, "notice"))
|
||||
return LOG_INFO;
|
||||
if (boost::iequals(s, "warning") ||
|
||||
boost::iequals(s, "warn"))
|
||||
return LOG_WARNING;
|
||||
if (boost::iequals(s, "error") ||
|
||||
boost::iequals(s, "err"))
|
||||
return LOG_ERR;
|
||||
if (boost::iequals(s, "crit") ||
|
||||
boost::iequals(s, "critical") ||
|
||||
boost::iequals(s, "emerg"))
|
||||
return LOG_CRIT;
|
||||
|
||||
// err on the side of noise!
|
||||
return LOG_DEBUG;
|
||||
}
|
||||
|
||||
int string_to_syslog_facility(string s)
|
||||
{
|
||||
if (boost::iequals(s, "auth"))
|
||||
return LOG_AUTH;
|
||||
if (boost::iequals(s, "authpriv"))
|
||||
return LOG_AUTHPRIV;
|
||||
if (boost::iequals(s, "cron"))
|
||||
return LOG_CRON;
|
||||
if (boost::iequals(s, "daemon"))
|
||||
return LOG_DAEMON;
|
||||
if (boost::iequals(s, "ftp"))
|
||||
return LOG_FTP;
|
||||
if (boost::iequals(s, "kern"))
|
||||
return LOG_KERN;
|
||||
if (boost::iequals(s, "local0"))
|
||||
return LOG_LOCAL0;
|
||||
if (boost::iequals(s, "local1"))
|
||||
return LOG_LOCAL1;
|
||||
if (boost::iequals(s, "local2"))
|
||||
return LOG_LOCAL2;
|
||||
if (boost::iequals(s, "local3"))
|
||||
return LOG_LOCAL3;
|
||||
if (boost::iequals(s, "local4"))
|
||||
return LOG_LOCAL4;
|
||||
if (boost::iequals(s, "local5"))
|
||||
return LOG_LOCAL5;
|
||||
if (boost::iequals(s, "local6"))
|
||||
return LOG_LOCAL6;
|
||||
if (boost::iequals(s, "local7"))
|
||||
return LOG_LOCAL7;
|
||||
if (boost::iequals(s, "lpr"))
|
||||
return LOG_LPR;
|
||||
if (boost::iequals(s, "mail"))
|
||||
return LOG_MAIL;
|
||||
if (boost::iequals(s, "news"))
|
||||
return LOG_NEWS;
|
||||
if (boost::iequals(s, "syslog"))
|
||||
return LOG_SYSLOG;
|
||||
if (boost::iequals(s, "user"))
|
||||
return LOG_USER;
|
||||
if (boost::iequals(s, "uucp"))
|
||||
return LOG_UUCP;
|
||||
|
||||
// default to USER
|
||||
return LOG_USER;
|
||||
}
|
||||
|
||||
void LogEntry::log_to_syslog(string level, string facility)
|
||||
{
|
||||
int min = string_to_syslog_level(level);
|
||||
int l = clog_type_to_syslog_level(type);
|
||||
if (l <= min) {
|
||||
int f = string_to_syslog_facility(facility);
|
||||
syslog(l | f, "%s", stringify(*this).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void LogEntry::encode(bufferlist& bl) const
|
||||
{
|
||||
ENCODE_START(2, 2, bl);
|
||||
|
@ -35,7 +35,10 @@ typedef enum {
|
||||
/*
|
||||
* Given a clog log_type, return the equivalent syslog priority
|
||||
*/
|
||||
int clog_type_to_syslog_prio(clog_type t);
|
||||
int clog_type_to_syslog_level(clog_type t);
|
||||
|
||||
int string_to_syslog_level(string s);
|
||||
int string_to_syslog_facility(string s);
|
||||
|
||||
|
||||
struct LogEntryKey {
|
||||
@ -66,6 +69,8 @@ struct LogEntry {
|
||||
|
||||
LogEntryKey key() const { return LogEntryKey(who, stamp, seq); }
|
||||
|
||||
void log_to_syslog(string level, string facility);
|
||||
|
||||
void encode(bufferlist& bl) const;
|
||||
void decode(bufferlist::iterator& bl);
|
||||
void dump(Formatter *f) const;
|
||||
|
@ -42,8 +42,12 @@ OPTION(log_flush_on_exit, OPT_BOOL, true)
|
||||
|
||||
OPTION(clog_to_monitors, OPT_BOOL, true)
|
||||
OPTION(clog_to_syslog, OPT_BOOL, false)
|
||||
OPTION(clog_to_syslog_level, OPT_STR, "info") // this level and above
|
||||
OPTION(clog_to_syslog_facility, OPT_STR, "daemon")
|
||||
|
||||
OPTION(mon_cluster_log_to_syslog, OPT_BOOL, false)
|
||||
OPTION(mon_cluster_log_to_syslog_level, OPT_STR, "info") // this level and above
|
||||
OPTION(mon_cluster_log_to_syslog_facility, OPT_STR, "daemon")
|
||||
OPTION(mon_cluster_log_file, OPT_STR, "/var/log/ceph/$cluster.log")
|
||||
|
||||
DEFAULT_SUBSYS(0, 5)
|
||||
|
@ -128,7 +128,8 @@ void LogMonitor::update_from_paxos()
|
||||
string s = ss.str();
|
||||
|
||||
if (g_conf->mon_cluster_log_to_syslog) {
|
||||
syslog(clog_type_to_syslog_prio(le.type) | LOG_USER, "%s", s.c_str());
|
||||
le.log_to_syslog(g_conf->mon_cluster_log_to_syslog_level,
|
||||
g_conf->mon_cluster_log_to_syslog_facility);
|
||||
}
|
||||
if (g_conf->mon_cluster_log_file.length()) {
|
||||
blog.append(s + "\n");
|
||||
|
Loading…
Reference in New Issue
Block a user