Repository: mesos
Updated Branches:
  refs/heads/master 6a8aac9c2 -> 7c366bad6


Added support for specifying logging level via flag.

minloglevel flag is passed as an argument to the command line and it
configures the level of logging to stderr and file. It can take INFO,
WARNING, ERROR or FATAL values. All log messages at or above the
configured log level will be printed.

If 'quiet' flag is also passed to the command line, minloglevel will
affect just the logs from file (if configured by log_dir flag)

Review: https://reviews.apache.org/r/19357


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/7c366bad
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/7c366bad
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/7c366bad

Branch: refs/heads/master
Commit: 7c366bad61e8c241797ef5c92562e0539c0dd02a
Parents: 6a8aac9
Author: Alexandra Sava <[email protected]>
Authored: Mon Mar 24 12:38:12 2014 -0700
Committer: Vinod Kone <[email protected]>
Committed: Mon Mar 24 12:38:12 2014 -0700

----------------------------------------------------------------------
 src/logging/flags.hpp                     |  8 ++++
 src/logging/logging.cpp                   | 52 +++++++++++++++++++++++++-
 src/logging/logging.hpp                   |  8 ++++
 src/master/master.cpp                     |  8 +++-
 src/slave/slave.cpp                       |  8 +++-
 src/webui/master/static/js/controllers.js | 14 +++++++
 6 files changed, 93 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7c366bad/src/logging/flags.hpp
----------------------------------------------------------------------
diff --git a/src/logging/flags.hpp b/src/logging/flags.hpp
index e2e4afc..457feee 100644
--- a/src/logging/flags.hpp
+++ b/src/logging/flags.hpp
@@ -38,6 +38,13 @@ public:
         "Disable logging to stderr",
         false);
 
+    add(&Flags::minloglevel,
+        "minloglevel",
+        "Log message at or above this level; if quiet flag\n"
+        "is used, this will affect just the logs from log_dir\n"
+        "(if specified)",
+        "INFO");
+
     add(&Flags::log_dir,
         "log_dir",
         "Location to put log files (no default, nothing\n"
@@ -51,6 +58,7 @@ public:
   }
 
   bool quiet;
+  std::string minloglevel;
   Option<std::string> log_dir;
   int logbufsecs;
 };

http://git-wip-us.apache.org/repos/asf/mesos/blob/7c366bad/src/logging/logging.cpp
----------------------------------------------------------------------
diff --git a/src/logging/logging.cpp b/src/logging/logging.cpp
index a46a3f1..176e49a 100644
--- a/src/logging/logging.cpp
+++ b/src/logging/logging.cpp
@@ -91,6 +91,51 @@ void handler(int signal)
 }
 
 
+void createLogFile(google::LogSeverity severity)
+{
+  if (severity < google::INFO || severity > google::FATAL) {
+    severity = google::INFO;
+  }
+
+  // Log this message in order to create the log file; also
+  // recreate the file if it has been created on a previous run.
+  string msg = "Logging " + string(google::GetLogSeverityName(severity)) +
+               " level started!";
+  switch(severity) {
+    case 0:
+      LOG(INFO) << msg;
+      break;
+    case 1:
+      LOG(WARNING) << msg;
+      break;
+    case 2:
+      LOG(ERROR) << msg;
+      break;
+  }
+}
+
+
+google::LogSeverity getMinLogLevel(const string& minloglevel)
+{
+  if (minloglevel == "INFO") {
+    return google::INFO;
+  }
+  if (minloglevel == "WARNING") {
+    return google::WARNING;
+  }
+  if (minloglevel == "ERROR") {
+    return google::ERROR;
+  }
+  if (minloglevel == "FATAL") {
+    return google::FATAL;
+  }
+
+  // Return the default value of logging (INFO) if an invalid
+  // value is passed to minloglevel flag.
+  return google::INFO;
+}
+
+
 void initialize(
     const string& _argv0,
     const Flags& flags,
@@ -105,6 +150,8 @@ void initialize(
   argv0 = _argv0;
 
   // Set glog's parameters through Google Flags variables.
+  FLAGS_minloglevel = getMinLogLevel(flags.minloglevel);
+
   if (flags.log_dir.isSome()) {
     Try<Nothing> mkdir = os::mkdir(flags.log_dir.get());
     if (mkdir.isError()) {
@@ -130,12 +177,15 @@ void initialize(
       FLAGS_minloglevel = 3; // FATAL.
     }
   } else {
-    FLAGS_stderrthreshold = 0; // INFO.
+    FLAGS_stderrthreshold = FLAGS_minloglevel;
   }
 
   FLAGS_logbufsecs = flags.logbufsecs;
 
   google::InitGoogleLogging(argv0.c_str());
+  if (flags.log_dir.isSome() && FLAGS_minloglevel != google::FATAL) {
+    createLogFile(FLAGS_minloglevel);
+  }
 
   VLOG(1) << "Logging to " <<
     (flags.log_dir.isSome() ? flags.log_dir.get() : "STDERR");

http://git-wip-us.apache.org/repos/asf/mesos/blob/7c366bad/src/logging/logging.hpp
----------------------------------------------------------------------
diff --git a/src/logging/logging.hpp b/src/logging/logging.hpp
index 3c24211..39c2934 100644
--- a/src/logging/logging.hpp
+++ b/src/logging/logging.hpp
@@ -39,6 +39,14 @@ void initialize(
 // LogSeverity is one of {INFO, WARNING, ERROR}.
 Try<std::string> getLogFile(google::LogSeverity severity);
 
+
+// Creates the log file for the provided severity.
+void createLogFile(google::LogSeverity severity);
+
+
+// Returns the minimum level of logging as a number.
+google::LogSeverity getMinLogLevel(const std::string& minloglevel);
+
 } // namespace logging {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/7c366bad/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 544144d..a951a7a 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -512,8 +512,12 @@ void Master::initialize()
   provide("", path::join(flags.webui_dir, "master/static/index.html"));
   provide("static", path::join(flags.webui_dir, "master/static"));
 
-  if (flags.log_dir.isSome()) {
-    Try<string> log = logging::getLogFile(google::INFO);
+  // No need to access FATAL log file; if the program
+  // is still running, there definitely haven't been any
+  // FATAL logs yet; a FATAL log will cause the program to crash.
+  google::LogSeverity minloglevel = logging::getMinLogLevel(flags.minloglevel);
+  if (flags.log_dir.isSome() && minloglevel != google::FATAL) {
+    Try<string> log = logging::getLogFile(minloglevel);
     if (log.isError()) {
       LOG(ERROR) << "Master log file cannot be found: " << log.error();
     } else {

http://git-wip-us.apache.org/repos/asf/mesos/blob/7c366bad/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index d8d3e0f..7298606 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -266,8 +266,12 @@ void Slave::initialize()
   route("/stats.json", None(), lambda::bind(&Http::stats, http, lambda::_1));
   route("/state.json", None(), lambda::bind(&Http::state, http, lambda::_1));
 
-  if (flags.log_dir.isSome()) {
-    Try<string> log = logging::getLogFile(google::INFO);
+  // No need to access FATAL log file; if the program
+  // is still running, there definitely haven't been any
+  // FATAL logs yet; a FATAL log will cause the program to crash.
+  google::LogSeverity minloglevel = logging::getMinLogLevel(flags.minloglevel);
+  if (flags.log_dir.isSome() && minloglevel != google::FATAL) {
+    Try<string> log = logging::getLogFile(minloglevel);
     if (log.isError()) {
       LOG(ERROR) << "Slave log file cannot be found: " << log.error();
     } else {

http://git-wip-us.apache.org/repos/asf/mesos/blob/7c366bad/src/webui/master/static/js/controllers.js
----------------------------------------------------------------------
diff --git a/src/webui/master/static/js/controllers.js 
b/src/webui/master/static/js/controllers.js
index afb24fb..4b8487e 100644
--- a/src/webui/master/static/js/controllers.js
+++ b/src/webui/master/static/js/controllers.js
@@ -340,6 +340,13 @@
           "Set the 'log_dir' option if you wish to access the logs.",
           [{label: 'Continue'}]
         ).open();
+      } else if ($scope.state.flags.minloglevel == "FATAL") {
+        $dialog.messageBox(
+          'No FATAL logs yet',
+          "The configured log level is FATAL. For more meaningful logs,\
+          please set 'minloglevel' flag to INFO, WARNING or ERROR.",
+          [{label: 'Continue'}]
+        ).open();
       } else {
         pailer(
             $scope.$location.host() + ':' + $scope.$location.port(),
@@ -405,6 +412,13 @@
             "Set the 'log_dir' option if you wish to access the logs.",
             [{label: 'Continue'}]
           ).open();
+        } else if ($scope.state.flags.minloglevel == "FATAL") {
+          $dialog.messageBox(
+            'No FATAL logs yet',
+            "The configured log level is FATAL. For more meaningful logs, 
please set \
+            'minloglevel' flag to INFO, WARNING or ERROR.",
+            [{label: 'Continue'}]
+          ).open();
         } else {
           pailer(host, '/slave/log', 'Mesos Slave');
         }

Reply via email to