]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
debug: allow output and output symlinks to go in different directories
authorSage Weil <sage@newdream.net>
Fri, 5 Dec 2008 00:27:09 +0000 (16:27 -0800)
committerSage Weil <sage@newdream.net>
Fri, 5 Dec 2008 00:33:39 +0000 (16:33 -0800)
src/common/debug.cc
src/common/debug.h
src/config.cc
src/config.h

index 834f4f51e74b3567910da4b7ea666d72be3e0fd2..1a73f83369b680b0f29cf51ce10312cd34429dc3 100644 (file)
@@ -13,16 +13,15 @@ using namespace std;
 Mutex _dout_lock("_dout_lock", false, false /* no lockdep */);  
 ostream *_dout = &std::cout;
 ostream *_derr = &std::cerr;
-char _dout_file[100] = {0};
 char _dout_dir[1000] = {0};
+char _dout_symlink_dir[1000] = {0};
+char _dout_path[1000] = {0};
 char _dout_symlink_path[1000] = {0};
 bool _dout_is_open = false;
 bool _dout_need_open = true;
 
 void _dout_open_log()
 {
-  char fn[80];
-
   // logging enabled?
   if (!(g_conf.dout_dir && g_conf.file_logs)) {
     _dout_need_open = false;
@@ -30,10 +29,7 @@ void _dout_open_log()
   }
 
   // calculate log dir, filename, etc.
-  if (!_dout_file[0]) {
-    char hostname[80];
-    gethostname(hostname, 79);
-    
+  if (!_dout_path[0]) {
     if (g_conf.dout_dir[0] == '/') 
       strcpy(_dout_dir, g_conf.dout_dir);
     else {
@@ -41,44 +37,52 @@ void _dout_open_log()
       strcat(_dout_dir, "/");
       strcat(_dout_dir, g_conf.dout_dir);
     }
-    sprintf(_dout_file, "%s.%d", hostname, getpid());
+
+    if (g_conf.dout_sym_dir[0] == '/') 
+      strcpy(_dout_symlink_dir, g_conf.dout_sym_dir);
+    else {
+      getcwd(_dout_symlink_dir, 100);
+      strcat(_dout_symlink_dir, "/");
+      strcat(_dout_symlink_dir, g_conf.dout_sym_dir);
+    }
+
+    char hostname[80];
+    gethostname(hostname, 79);
+    sprintf(_dout_path, "%s/%s.%d", _dout_dir, hostname, getpid());
   }
 
   if (_dout && _dout_is_open)
     delete _dout;
 
-  sprintf(fn, "%s/%s", _dout_dir, _dout_file);
-  std::ofstream *out = new std::ofstream(fn, ios::trunc|ios::out);
+  std::ofstream *out = new std::ofstream(_dout_path, ios::trunc|ios::out);
   if (!out->is_open()) {
-    std::cerr << "error opening output file " << fn << std::endl;
+    std::cerr << "error opening output file " << _dout_path << std::endl;
     delete out;
     _dout = &std::cout;
   } else {
     _dout_need_open = false;
     _dout_is_open = true;
     _dout = out;
-    *_dout << g_clock.now() << " --- opened log " << fn << " ---" << std::endl;
+    *_dout << g_clock.now() << " --- opened log " << _dout_path << " ---" << std::endl;
   }
 }
 
 int _dout_rename_output_file()  // after calling daemon()
 {
   if (g_conf.dout_dir && g_conf.file_logs) {
-    char oldfn[100];
-    char newfn[100];
+    char oldpath[1000];
     char hostname[80];
     gethostname(hostname, 79);
-    
-    sprintf(oldfn, "%s/%s", _dout_dir, _dout_file);
-    sprintf(newfn, "%s/%s.%d", _dout_dir, hostname, getpid());
-    dout(0) << "---- renamed log " << oldfn << " -> " << newfn << " ----" << dendl;
-    ::rename(oldfn, newfn);
-    sprintf(_dout_file, "%s.%d", hostname, getpid());
+
+    strcpy(oldpath, _dout_path);
+    sprintf(_dout_path, "%s/%s.%d", _dout_dir, hostname, getpid());
+    dout(0) << "---- renamed log " << oldpath << " -> " << _dout_path << " ----" << dendl;
+    ::rename(oldpath, _dout_path);
 
     if (_dout_symlink_path[0]) {
-      // new symlink
+      // fix symlink
       ::unlink(_dout_symlink_path);
-      ::symlink(_dout_file, _dout_symlink_path);
+      ::symlink(_dout_path, _dout_symlink_path);
     }
   }
   return 0;
@@ -90,7 +94,7 @@ int _dout_create_courtesy_output_symlink(const char *type, int n)
     if (_dout_need_open)
       _dout_open_log();
 
-    sprintf(_dout_symlink_path, "%s/%s%d", _dout_dir, type, n);
+    sprintf(_dout_symlink_path, "%s/%s%d", _dout_symlink_dir, type, n);
 
     // rotate out old symlink
     int n = 0;
@@ -114,9 +118,9 @@ int _dout_create_courtesy_output_symlink(const char *type, int n)
       n--;
     }
 
-    ::symlink(_dout_file, _dout_symlink_path);
+    ::symlink(_dout_path, _dout_symlink_path);
     dout(0) << "---- created symlink " << _dout_symlink_path
-           << " -> " << _dout_file << " ----" << dendl;
+           << " -> " << _dout_path << " ----" << dendl;
   }
   return 0;
 }
index ae857ce14f7a06a527b8189caa6e498d64897fca..be4c14d38391f83d52816d3bd1b874d475db81a4 100644 (file)
@@ -18,9 +18,6 @@ extern ostream *_derr;
 extern Mutex _dout_lock;
 
 extern bool _dout_need_open;
-extern char _dout_file[100];
-extern char _dout_dir[1000];
-extern char _dout_symlink_path[1000];
 extern bool _dout_is_open;
 
 extern void _dout_open_log();
index 88c3fb44c0cb0766d7856120243399ad1b1092ef..097ebccbc2a0399308a1d25e12b051278dda414c 100644 (file)
@@ -202,6 +202,7 @@ md_config_t g_conf = {
   logger_calc_variance: true,
 
   dout_dir: "out",    // if daemonize == true
+  dout_sym_dir: "out",    // if daemonize == true
   
   fake_clock: false,
   fakemessenger_serialize: true,
@@ -686,8 +687,11 @@ void parse_config_options(std::vector<const char*>& args, bool open)
     
     
     else if (//strcmp(args[i], "-o") == 0 ||
-            strcmp(args[i], "--doutdir") == 0) 
+            strcmp(args[i], "--dout_dir") == 0) 
       g_conf.dout_dir = args[++i];
+    else if (//strcmp(args[i], "-o") == 0 ||
+            strcmp(args[i], "--dout_sym_dir") == 0) 
+      g_conf.dout_sym_dir = args[++i];
 
     else if (strcmp(args[i], "--lockdep") == 0)
       g_lockdep = atoi(args[++i]);
index 35c0a4671242263b9d31a8e007ab40a163fb629d..6b75d68068f4aa4981d235d5c1cf37af5cb43dce 100644 (file)
@@ -65,6 +65,7 @@ struct md_config_t {
   bool logger_calc_variance;
 
   const char *dout_dir;
+  const char *dout_sym_dir;
 
   bool fake_clock;
   bool fakemessenger_serialize;