You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/10/13 01:20:42 UTC

svn commit: r1397737 - in /incubator/mesos/trunk/src: logging/logging.cpp logging/logging.hpp master/master.cpp slave/slave.cpp webui/master/static/controllers.js

Author: benh
Date: Fri Oct 12 23:20:41 2012
New Revision: 1397737

URL: http://svn.apache.org/viewvc?rev=1397737&view=rev
Log:
Fixed log viewing with mesos-local.sh runs.

From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/7061

Modified:
    incubator/mesos/trunk/src/logging/logging.cpp
    incubator/mesos/trunk/src/logging/logging.hpp
    incubator/mesos/trunk/src/master/master.cpp
    incubator/mesos/trunk/src/slave/slave.cpp
    incubator/mesos/trunk/src/webui/master/static/controllers.js

Modified: incubator/mesos/trunk/src/logging/logging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/logging/logging.cpp?rev=1397737&r1=1397736&r2=1397737&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.cpp (original)
+++ incubator/mesos/trunk/src/logging/logging.cpp Fri Oct 12 23:20:41 2012
@@ -30,8 +30,10 @@
 #include <process/timeout.hpp>
 
 #include <stout/duration.hpp>
+#include <stout/format.hpp>
 #include <stout/numify.hpp>
 #include <stout/os.hpp>
+#include <stout/path.hpp>
 #include <stout/stringify.hpp>
 #include <stout/try.hpp>
 
@@ -138,6 +140,11 @@ private:
 };
 
 
+// Persistent copy of argv0 since InitGoogleLogging requires the
+// string we pass to it to be accessible indefinitely.
+string argv0;
+
+
 void initialize(const string& _argv0, const Flags& flags)
 {
   static Once* initialized = new Once();
@@ -146,9 +153,7 @@ void initialize(const string& _argv0, co
     return;
   }
 
-  // Persistent copy of argv0 since InitGoogleLogging requires the
-  // string we pass to it to be accessible indefinitely.
-  static string argv0 = _argv0;
+  argv0 = _argv0;
 
   // Set glog's parameters through Google Flags variables.
   if (flags.log_dir.isSome()) {
@@ -181,6 +186,31 @@ void initialize(const string& _argv0, co
   initialized->done();
 }
 
+
+Try<string> getLogFile(google::LogSeverity severity)
+{
+  if (FLAGS_log_dir.empty()) {
+    return Try<string>::error("The 'log_dir' option was not specified");
+  }
+
+  string suffix;
+  switch (severity) {
+    case google::INFO:    suffix = ".INFO";    break;
+    case google::WARNING: suffix = ".WARNING"; break;
+    case google::ERROR:   suffix = ".ERROR";   break;
+    default:
+      return Try<string>::error(
+          strings::format("Unknown log severity: %d", severity).get());
+  }
+
+  Try<string> basename = os::basename(argv0);
+  if (basename.isError()) {
+    return basename;
+  }
+
+  return path::join(FLAGS_log_dir, basename.get()) + suffix;
+}
+
 } // namespace logging {
 } // namespace internal {
 } // namespace mesos {

Modified: incubator/mesos/trunk/src/logging/logging.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/logging/logging.hpp?rev=1397737&r1=1397736&r2=1397737&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.hpp (original)
+++ incubator/mesos/trunk/src/logging/logging.hpp Fri Oct 12 23:20:41 2012
@@ -28,12 +28,19 @@
 
 #include "logging/flags.hpp"
 
+#include "stout/try.hpp"
+
 namespace mesos {
 namespace internal {
 namespace logging {
 
 void initialize(const std::string& argv0, const Flags& flags);
 
+
+// Returns the log file for the provided severity level.
+// LogSeverity is one of {INFO, WARNING, ERROR}.
+Try<std::string> getLogFile(google::LogSeverity severity);
+
 } // namespace logging {
 } // namespace internal {
 } // namespace mesos {

Modified: incubator/mesos/trunk/src/master/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.cpp?rev=1397737&r1=1397736&r2=1397737&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.cpp (original)
+++ incubator/mesos/trunk/src/master/master.cpp Fri Oct 12 23:20:41 2012
@@ -37,6 +37,7 @@
 #include "flags/flags.hpp"
 
 #include "logging/flags.hpp"
+#include "logging/logging.hpp"
 
 #include "master/allocator.hpp"
 #include "master/flags.hpp"
@@ -455,13 +456,14 @@ void Master::initialize()
   provide("", path::join(flags.webui_dir, "master/static/index.html"));
   provide("static", path::join(flags.webui_dir, "master/static"));
 
-  // TODO(benh): Ask glog for file name (i.e., mesos-master.INFO).
-  // Blocked on http://code.google.com/p/google-glog/issues/detail?id=116
-  // Alternatively, initialize() could take the executable name.
   if (flags.log_dir.isSome()) {
-    string path = path::join(flags.log_dir.get(), "mesos-master.INFO");
-    files->attach(path, "/log")
-      .onAny(defer(self(), &Self::fileAttached, params::_1, path));
+    Try<string> log = logging::getLogFile(google::INFO);
+    if (log.isError()) {
+      LOG(ERROR) << "Master log file cannot be found: " << log.error();
+    } else {
+      files->attach(log.get(), "/master/log")
+        .onAny(defer(self(), &Self::fileAttached, params::_1, log.get()));
+    }
   }
 }
 

Modified: incubator/mesos/trunk/src/slave/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.cpp?rev=1397737&r1=1397736&r2=1397737&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave/slave.cpp Fri Oct 12 23:20:41 2012
@@ -41,6 +41,8 @@
 #include "common/protobuf_utils.hpp"
 #include "common/type_utils.hpp"
 
+#include "logging/logging.hpp"
+
 #include "slave/flags.hpp"
 #include "slave/paths.hpp"
 #include "slave/slave.hpp"
@@ -296,13 +298,14 @@ void Slave::initialize()
   route("/stats.json", bind(&http::json::stats, cref(*this), params::_1));
   route("/state.json", bind(&http::json::state, cref(*this), params::_1));
 
-  // TODO(benh): Ask glog for file name (i.e., mesos-slave.INFO).
-  // Blocked on http://code.google.com/p/google-glog/issues/detail?id=116
-  // Alternatively, initialize() could take the executable name.
   if (flags.log_dir.isSome()) {
-    string path = path::join(flags.log_dir.get(), "mesos-slave.INFO");
-    files->attach(path, "/log")
-      .onAny(defer(self(), &Self::fileAttached, params::_1, path));
+    Try<string> log = logging::getLogFile(google::INFO);
+    if (log.isError()) {
+      LOG(ERROR) << "Slave log file cannot be found: " << log.error();
+    } else {
+      files->attach(log.get(), "/slave/log")
+        .onAny(defer(self(), &Self::fileAttached, params::_1, log.get()));
+    }
   }
 }
 

Modified: incubator/mesos/trunk/src/webui/master/static/controllers.js
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/static/controllers.js?rev=1397737&r1=1397736&r2=1397737&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/static/controllers.js (original)
+++ incubator/mesos/trunk/src/webui/master/static/controllers.js Fri Oct 12 23:20:41 2012
@@ -281,7 +281,7 @@ function HomeCtrl($scope) {
     if (!$scope.state.log_dir) {
       $('#no-log-dir-modal').modal('show');
     } else {
-      var url = '/files/read.json?path=/log';
+      var url = '/files/read.json?path=/master/log';
       var pailer =
         window.open('/static/pailer.html', url, 'width=580px, height=700px');
 
@@ -378,7 +378,7 @@ function SlaveCtrl($scope, $routeParams,
     if (!$scope.state.log_dir) {
       $('#no-log-dir-modal').modal('show');
     } else {
-      var url = 'http://' + host + '/files/read.json?path=/log';
+      var url = 'http://' + host + '/files/read.json?path=/slave/log';
       var pailer =
         window.open('/static/pailer.html', url, 'width=580px, height=700px');