Skip to content

Commit

Permalink
mon: put cluster log at /var/log/ceph/$cluster.log and/or send to syslog
Browse files Browse the repository at this point in the history
Also, stop breaking it down by event severity on disk.  If you want that,
use syslog.

Fixes: ceph#2497
Backport: dho
Signed-off-by: Sage Weil <[email protected]>
Reviewed-by: Joao Eduardo Luis <[email protected]>
Reviewed-by: Greg Farnum <[email protected]>
  • Loading branch information
Sage Weil committed Jun 6, 2012
1 parent 37705ed commit 47b202e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 58 deletions.
22 changes: 0 additions & 22 deletions src/common/LogClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@

#define dout_subsys ceph_subsys_monc

/*
* Given a clog log_type, return the equivalent syslog priority
*/
static inline 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;
}
}

LogClient::LogClient(CephContext *cct, Messenger *m, MonMap *mm,
enum logclient_flag_t flags)
: cct(cct), messenger(m), monmap(mm), is_mon(flags & FLAG_MON),
Expand Down
25 changes: 25 additions & 0 deletions src/common/LogEntry.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@

#include <syslog.h>

#include "LogEntry.h"
#include "Formatter.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

void LogEntryKey::encode(bufferlist& bl) const
{
::encode(who, bl);
Expand Down
6 changes: 6 additions & 0 deletions src/common/LogEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ typedef enum {
CLOG_ERROR = 4,
} clog_type;

/*
* Given a clog log_type, return the equivalent syslog priority
*/
int clog_type_to_syslog_prio(clog_type t);


struct LogEntryKey {
entity_inst_t who;
utime_t stamp;
Expand Down
3 changes: 3 additions & 0 deletions src/common/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ OPTION(log_flush_on_exit, OPT_BOOL, true)
OPTION(clog_to_monitors, OPT_BOOL, true)
OPTION(clog_to_syslog, OPT_BOOL, false)

OPTION(mon_cluster_log_to_syslog, OPT_BOOL, false)
OPTION(mon_cluster_log_file, OPT_STR, "/var/log/ceph/$cluster.log")

DEFAULT_SUBSYS(0, 5)
SUBSYS(lockdep, 0, 5)
SUBSYS(context, 0, 5)
Expand Down
56 changes: 21 additions & 35 deletions src/mon/LogMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*
*/

#include <sstream>
#include <syslog.h>

#include "LogMonitor.h"
#include "Monitor.h"
Expand All @@ -24,9 +26,8 @@
#include "common/Timer.h"

#include "osd/osd_types.h"

#include "common/errno.h"
#include "common/config.h"
#include <sstream>

#define dout_subsys ceph_subsys_mon
#undef dout_prefix
Expand Down Expand Up @@ -97,11 +98,6 @@ void LogMonitor::update_from_paxos()
assert(paxosv >= summary.version);

bufferlist blog;
bufferlist blogdebug;
bufferlist bloginfo;
bufferlist blogwarn;
bufferlist blogerr;
bufferlist blogsec;

if (summary.version != paxos->get_stashed_version()) {
bufferlist latest;
Expand All @@ -127,21 +123,14 @@ void LogMonitor::update_from_paxos()

stringstream ss;
ss << le;
string s;
getline(ss, s);
s += "\n";

blog.append(s);
if (le.type >= CLOG_DEBUG)
blogdebug.append(s);
if (le.type >= CLOG_INFO)
bloginfo.append(s);
if (le.type == CLOG_SEC)
blogsec.append(s);
if (le.type >= CLOG_WARN)
blogwarn.append(s);
if (le.type >= CLOG_ERROR)
blogerr.append(s);
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());
}
if (g_conf->mon_cluster_log_file.length()) {
blog.append(s + "\n");
}

summary.add(le);
}
Expand All @@ -153,19 +142,16 @@ void LogMonitor::update_from_paxos()
::encode(summary, bl);
paxos->stash_latest(paxosv, bl);

if (blog.length())
mon->store->append_bl_ss(blog, "log", NULL);
if (blogdebug.length())
mon->store->append_bl_ss(blogdebug, "log.debug", NULL);
if (bloginfo.length())
mon->store->append_bl_ss(bloginfo, "log.info", NULL);
if (blogsec.length())
mon->store->append_bl_ss(bloginfo, "log.security", NULL);
if (blogwarn.length())
mon->store->append_bl_ss(blogwarn, "log.warn", NULL);
if (blogerr.length())
mon->store->append_bl_ss(blogerr, "log.err", NULL);

if (blog.length()) {
int fd = ::open(g_conf->mon_cluster_log_file.c_str(), O_WRONLY|O_APPEND|O_CREAT, 0600);
if (fd < 0) {
int err = -errno;
dout(1) << "unable to write to " << g_conf->mon_cluster_log_file << ": " << cpp_strerror(err) << dendl;
} else {
blog.write_fd(fd);
TEMP_FAILURE_RETRY(::close(fd));
}
}

// trim
unsigned max = g_conf->mon_max_log_epochs;
Expand Down
2 changes: 1 addition & 1 deletion src/vstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ $COSDDEBUG
[mon]
$DAEMONOPTS
$CMONDEBUG
mon cluster log file = out/cluster.mon.\$id.log
EOF
fi

Expand Down

0 comments on commit 47b202e

Please sign in to comment.