mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject incubator-mynewt-newt git commit: Bug fix for -o option (log file).
Date Wed, 09 Mar 2016 23:28:56 GMT
Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 6d5c21828 -> a99216bd0


Bug fix for -o option (log file).

Configure logging twice.  First just configure the filter for stderr;
second configure the logfile if there is one.  This needs to happen in
two steps so that the log level is configured prior to the attempt to
open the log file.  The correct log level needs to be applied to file
error messages.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/a99216bd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a99216bd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a99216bd

Branch: refs/heads/develop
Commit: a99216bd0910f6340a188b0dbced37160637f5b0
Parents: 6d5c218
Author: Christopher Collins <ccollins476ad@gmail.com>
Authored: Wed Mar 9 15:27:36 2016 -0800
Committer: Christopher Collins <ccollins476ad@gmail.com>
Committed: Wed Mar 9 15:27:36 2016 -0800

----------------------------------------------------------------------
 newt/newt.go |  2 +-
 util/util.go | 31 +++++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a99216bd/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 4f53f83..13516bd 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -69,7 +69,7 @@ func newtCmd() *cobra.Command {
 				verbosity = util.VERBOSITY_VERBOSE
 			}
 
-			err := util.Init(NewtLogLevel, verbosity, newtLogFile)
+			err := util.Init(NewtLogLevel, newtLogFile, verbosity)
 			if err != nil {
 				cli.NewtUsage(nil, err)
 			}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a99216bd/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index a7d1a68..86f3fe0 100644
--- a/util/util.go
+++ b/util/util.go
@@ -154,12 +154,7 @@ func Max(x, y int) int {
 	return y
 }
 
-// Initialize the util module
-func Init(level string, verbosity int, logFile string) error {
-	if level == "" {
-		level = "WARN"
-	}
-
+func initLog(level string, logFile string) error {
 	var writer io.Writer
 	if logFile == "" {
 		writer = os.Stderr
@@ -180,6 +175,30 @@ func Init(level string, verbosity int, logFile string) error {
 	}
 
 	log.SetOutput(filter)
+
+	return nil
+}
+
+// Initialize the util module
+func Init(logLevel string, logFile string, verbosity int) error {
+	if logLevel == "" {
+		logLevel = "WARN"
+	}
+
+	// Configure logging twice.  First just configure the filter for stderr;
+	// second configure the logfile if there is one.  This needs to happen in
+	// two steps so that the log level is configured prior to the attempt to
+	// open the log file.  The correct log level needs to be applied to file
+	// error messages.
+	if err := initLog(logLevel, ""); err != nil {
+		return err
+	}
+	if logFile != "" {
+		if err := initLog(logLevel, logFile); err != nil {
+			return err
+		}
+	}
+
 	Verbosity = verbosity
 
 	return nil


Mime
View raw message