void Logger::_open_log()
{
Mutex::Locker l(logger_lock);
+ struct stat st;
+
+ if (!g_conf.log)
+ return;
filename = "";
if (g_conf.use_abspaths) {
}
filename = g_conf.logger_dir;
+
+ // make (feeble) attempt to create logger_dir
+ if (::stat(filename.c_str(), &st))
+ ::mkdir(filename.c_str(), 0750);
+
filename += "/";
if (g_conf.log_name) {
filename += g_conf.log_name;
}
filename += name;
- if (append)
- out.open(filename.c_str(), ofstream::out|ofstream::app);
- else
- out.open(filename.c_str(), ofstream::out);
-
+ out.open(filename.c_str(), append ? ofstream::out|ofstream::app : ofstream::out);
+ if (!out.is_open()) {
+ generic_dout(0) << "failed to open '" << filename << "'" << dendl;
+ return; // we fail
+ }
+
+ // success
+ open = true;
+
if (logger_list.empty()) {
// init logger
if (!g_conf.clock_tare)
long Logger::inc(int key, long v)
{
- if (!g_conf.log) return 0;
+ if (!open || !g_conf.log)
+ return 0;
logger_lock.Lock();
int i = type->lookup_key(key);
vals[i] += v;
double Logger::finc(int key, double v)
{
- if (!g_conf.log) return 0;
+ if (!open || !g_conf.log)
+ return 0;
logger_lock.Lock();
int i = type->lookup_key(key);
fvals[i] += v;
long Logger::set(int key, long v)
{
- if (!g_conf.log) return 0;
+ if (!open || !g_conf.log)
+ return 0;
logger_lock.Lock();
int i = type->lookup_key(key);
//cout << this << " set " << i << " to " << v << std::endl;
double Logger::fset(int key, double v)
{
- if (!g_conf.log) return 0;
+ if (!open || !g_conf.log)
+ return 0;
logger_lock.Lock();
int i = type->lookup_key(key);
//cout << this << " fset " << i << " to " << v << std::endl;
double Logger::favg(int key, double v)
{
- if (!g_conf.log) return 0;
+ if (!open || !g_conf.log)
+ return 0;
logger_lock.Lock();
int i = type->lookup_key(key);
vals[i]++;
long Logger::get(int key)
{
- if (!g_conf.log) return 0;
+ if (!open || !g_conf.log)
+ return 0;
logger_lock.Lock();
int i = type->lookup_key(key);
long r = 0;
string name, filename;
bool append;
LogType *type;
+ bool open;
// values for this instance
vector<long> vals;
vector<double> fvals;
- vector< vector<double> > vals_to_avg;
+ vector< vector<double> > vals_to_avg; // for calculating variance
ofstream out;
public:
Logger(string n, LogType *t, bool ap=false) :
- name(n), append(ap), type(t),
- vals(t->num_keys), fvals(t->num_keys), vals_to_avg(t->num_keys),
+ name(n), append(ap), type(t), open(false),
+ vals(t->num_keys), fvals(t->num_keys),
wrote_header_last(10000) {
_open_log();
}