Merge lp:~thumper/juju-core/show-log into lp:~go-bot/juju-core/trunk
- show-log
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | John A Meinel |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1792 |
Proposed branch: | lp:~thumper/juju-core/show-log |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
206 lines (+69/-23) 3 files modified
cmd/juju/main_test.go (+3/-2) cmd/logging.go (+29/-18) cmd/logging_test.go (+37/-3) |
To merge this branch: | bzr merge lp:~thumper/juju-core/show-log |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+185193@code.launchpad.net |
Commit message
Make show-log an explicit arg.
This is part of the prelude to making --verbose mean
something else.
Also now, you can specify a log file and ask for show-log
and the logging goes to both places.
There is now a deprecation warning written out if people use
--verbose.
Description of the change
Make show-log an explicit arg.
This is part of the prelude to making --verbose mean
something else.
Also now, you can specify a log file and ask for show-log
and the logging goes to both places.
There is now a deprecation warning written out if people use
--verbose.
Tim Penhey (thumper) wrote : | # |
Ian Booth (wallyworld) wrote : | # |
Yay. LGTM
Ian Booth (wallyworld) wrote : | # |
Yay. LGTM
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~thumper/juju-core/show-log into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
-------
PANIC: addmachine.go:0: AddMachineSuite
[LOG] 37.26979 INFO juju mongod: error command line: unknown option sslOnNormalPorts
[LOG] 37.26983 INFO juju mongod: use --help for help
... Panic: no reachable servers (PC=0x414321)
/usr/lib/
in panic
/home/tarmac/
in MgoDial
/home/tarmac/
in MgoSuite.SetUpTest
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.SetUpTest
-------
PANIC: addmachine.go:0: AddMachineSuite
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)
/usr/lib/
in panic
/usr/lib/
in panicstring
/usr/lib/
in sigpanic
/home/tarmac/
in State.SetAdminM
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.
-------
PANIC: addmachine_
... Panic: Fixture has panicked (see related PANIC)
-------
PANIC: addmachine.go:0: AddRelationSuit
... Panic: no reachable servers (PC=0x414321)
/usr/lib/
in panic
/home/tarmac/
in MgoDial
/home/tarmac/
in MgoSuite.SetUpTest
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.SetUpTest
-------
PANIC: addmachine.go:0: AddRelationSuit
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)
/usr/lib/
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~thumper/juju-core/show-log into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
-------
PANIC: addmachine.go:0: AddMachineSuite
... Panic: no reachable servers (PC=0x414321)
/usr/lib/
in panic
/home/tarmac/
in MgoDial
/home/tarmac/
in MgoSuite.SetUpTest
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.SetUpTest
-------
PANIC: addmachine.go:0: AddMachineSuite
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)
/usr/lib/
in panic
/usr/lib/
in panicstring
/usr/lib/
in sigpanic
/home/tarmac/
in State.SetAdminM
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.
-------
PANIC: addmachine_
... Panic: Fixture has panicked (see related PANIC)
-------
PANIC: addmachine.go:0: AddRelationSuit
... Panic: no reachable servers (PC=0x414321)
/usr/lib/
in panic
/home/tarmac/
in MgoDial
/home/tarmac/
in MgoSuite.SetUpTest
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.SetUpTest
-------
PANIC: addmachine.go:0: AddRelationSuit
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)
/usr/lib/
in panic
/usr/lib/
in panicstring
/usr/lib/
in sigpani...
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~thumper/juju-core/show-log into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
-------
PANIC: addmachine.go:0: AddMachineSuite
[LOG] 61.02621 INFO juju mongod: error command line: unknown option sslOnNormalPorts
[LOG] 61.02625 INFO juju mongod: use --help for help
... Panic: no reachable servers (PC=0x414321)
/usr/lib/
in panic
/home/tarmac/
in MgoDial
/home/tarmac/
in MgoSuite.SetUpTest
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.SetUpTest
-------
PANIC: addmachine.go:0: AddMachineSuite
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)
/usr/lib/
in panic
/usr/lib/
in panicstring
/usr/lib/
in sigpanic
/home/tarmac/
in State.SetAdminM
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.
-------
PANIC: addmachine_
... Panic: Fixture has panicked (see related PANIC)
-------
PANIC: addmachine.go:0: AddRelationSuit
... Panic: no reachable servers (PC=0x414321)
/usr/lib/
in panic
/home/tarmac/
in MgoDial
/home/tarmac/
in MgoSuite.SetUpTest
/home/tarmac/
in JujuConnSuite.
/home/tarmac/
in RepoSuite.SetUpTest
-------
PANIC: addmachine.go:0: AddRelationSuit
... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x414321)
/usr/lib/
John A Meinel (jameinel) wrote : | # |
I should have fixed the problem on the bot, I'll follow up if it keeps failing.
Preview Diff
1 | === modified file 'cmd/juju/main_test.go' |
2 | --- cmd/juju/main_test.go 2013-08-21 18:38:22 +0000 |
3 | +++ cmd/juju/main_test.go 2013-09-12 04:14:12 +0000 |
4 | @@ -192,7 +192,7 @@ |
5 | // Check global args work when specified before command |
6 | msg := breakJuju(c, "Bootstrap") |
7 | logpath := filepath.Join(c.MkDir(), "log") |
8 | - out := badrun(c, 1, "--log-file", logpath, "--verbose", "--debug", "bootstrap") |
9 | + out := badrun(c, 1, "--log-file", logpath, "bootstrap") |
10 | c.Assert(out, gc.Equals, "error: "+msg+"\n") |
11 | content, err := ioutil.ReadFile(logpath) |
12 | c.Assert(err, gc.IsNil) |
13 | @@ -205,7 +205,7 @@ |
14 | // Check global args work when specified after command |
15 | msg := breakJuju(c, "Bootstrap") |
16 | logpath := filepath.Join(c.MkDir(), "log") |
17 | - out := badrun(c, 1, "bootstrap", "--log-file", logpath, "--verbose", "--debug") |
18 | + out := badrun(c, 1, "bootstrap", "--log-file", logpath) |
19 | c.Assert(out, gc.Equals, "error: "+msg+"\n") |
20 | content, err := ioutil.ReadFile(logpath) |
21 | c.Assert(err, gc.IsNil) |
22 | @@ -313,6 +313,7 @@ |
23 | "-h, --help .*", |
24 | "--log-config .*", |
25 | "--log-file .*", |
26 | + "--show-log .*", |
27 | "-v, --verbose .*", |
28 | } |
29 | |
30 | |
31 | === modified file 'cmd/logging.go' |
32 | --- cmd/logging.go 2013-06-20 11:03:10 +0000 |
33 | +++ cmd/logging.go 2013-09-12 04:14:12 +0000 |
34 | @@ -4,7 +4,6 @@ |
35 | package cmd |
36 | |
37 | import ( |
38 | - "io" |
39 | "os" |
40 | |
41 | "launchpad.net/gnuflag" |
42 | @@ -17,6 +16,7 @@ |
43 | Path string |
44 | Verbose bool |
45 | Debug bool |
46 | + ShowLog bool |
47 | Config string |
48 | } |
49 | |
50 | @@ -28,38 +28,49 @@ |
51 | f.BoolVar(&l.Verbose, "verbose", false, "if set, log additional messages") |
52 | f.BoolVar(&l.Debug, "debug", false, "if set, log debugging messages") |
53 | f.StringVar(&l.Config, "log-config", "", "specify log levels for modules") |
54 | + f.BoolVar(&l.ShowLog, "show-log", false, "if set, write the log file to stderr") |
55 | } |
56 | |
57 | // Start starts logging using the given Context. |
58 | -func (l *Log) Start(ctx *Context) (err error) { |
59 | - var target io.Writer |
60 | +func (l *Log) Start(ctx *Context) error { |
61 | if l.Path != "" { |
62 | path := ctx.AbsPath(l.Path) |
63 | - target, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) |
64 | + target, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) |
65 | if err != nil { |
66 | return err |
67 | } |
68 | - } else if l.Verbose || l.Debug { |
69 | - target = ctx.Stderr |
70 | - } |
71 | - |
72 | - if target != nil { |
73 | writer := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{}) |
74 | - _, err = loggo.ReplaceDefaultWriter(writer) |
75 | + err = loggo.RegisterWriter("logfile", writer, loggo.TRACE) |
76 | + if err != nil { |
77 | + return err |
78 | + } |
79 | + } |
80 | + level := loggo.WARNING |
81 | + if l.Verbose { |
82 | + ctx.Stdout.Write([]byte("verbose is deprecated with the current meaning, use show-log\n")) |
83 | + l.ShowLog = true |
84 | + } |
85 | + if l.ShowLog { |
86 | + level = loggo.INFO |
87 | + } |
88 | + if l.Debug { |
89 | + l.ShowLog = true |
90 | + level = loggo.DEBUG |
91 | + } |
92 | + |
93 | + if l.ShowLog { |
94 | + // We replace the default writer to use ctx.Stderr rather than os.Stderr. |
95 | + writer := loggo.NewSimpleWriter(ctx.Stderr, &loggo.DefaultFormatter{}) |
96 | + _, err := loggo.ReplaceDefaultWriter(writer) |
97 | if err != nil { |
98 | return err |
99 | } |
100 | } else { |
101 | loggo.RemoveWriter("default") |
102 | } |
103 | - if l.Verbose || l.Debug { |
104 | - level := loggo.INFO |
105 | - if l.Debug { |
106 | - level = loggo.DEBUG |
107 | - } |
108 | - // Set the level on the root logger. |
109 | - loggo.GetLogger("").SetLogLevel(level) |
110 | - } |
111 | + // Set the level on the root logger. |
112 | + loggo.GetLogger("").SetLogLevel(level) |
113 | + // Override the logging config with specified logging config. |
114 | loggo.ConfigureLoggers(l.Config) |
115 | return nil |
116 | } |
117 | |
118 | === modified file 'cmd/logging_test.go' |
119 | --- cmd/logging_test.go 2013-08-19 11:17:19 +0000 |
120 | +++ cmd/logging_test.go 2013-09-12 04:14:12 +0000 |
121 | @@ -20,6 +20,11 @@ |
122 | |
123 | var _ = gc.Suite(&LogSuite{}) |
124 | |
125 | +func (s *LogSuite) TearDownTest(c *gc.C) { |
126 | + loggo.ResetLoggers() |
127 | + loggo.ResetWriters() |
128 | +} |
129 | + |
130 | func (s *LogSuite) TestAddFlags(c *gc.C) { |
131 | l := &cmd.Log{} |
132 | f := testing.NewFlagSet() |
133 | @@ -48,6 +53,8 @@ |
134 | c.Assert(err, gc.IsNil) |
135 | |
136 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.INFO) |
137 | + c.Assert(testing.Stderr(ctx), gc.Equals, "") |
138 | + c.Assert(testing.Stdout(ctx), gc.Equals, "verbose is deprecated with the current meaning, use show-log\n") |
139 | } |
140 | |
141 | func (s *LogSuite) TestDebugSetsLogLevel(c *gc.C) { |
142 | @@ -57,6 +64,19 @@ |
143 | c.Assert(err, gc.IsNil) |
144 | |
145 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.DEBUG) |
146 | + c.Assert(testing.Stderr(ctx), gc.Equals, "") |
147 | + c.Assert(testing.Stdout(ctx), gc.Equals, "") |
148 | +} |
149 | + |
150 | +func (s *LogSuite) TestShowLogSetsLogLevel(c *gc.C) { |
151 | + l := &cmd.Log{ShowLog: true} |
152 | + ctx := testing.Context(c) |
153 | + err := l.Start(ctx) |
154 | + c.Assert(err, gc.IsNil) |
155 | + |
156 | + c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.INFO) |
157 | + c.Assert(testing.Stderr(ctx), gc.Equals, "") |
158 | + c.Assert(testing.Stdout(ctx), gc.Equals, "") |
159 | } |
160 | |
161 | func (s *LogSuite) TestStderr(c *gc.C) { |
162 | @@ -65,7 +85,7 @@ |
163 | err := l.Start(ctx) |
164 | c.Assert(err, gc.IsNil) |
165 | log.Infof("hello") |
166 | - c.Assert(bufferString(ctx.Stderr), gc.Matches, `^.* INFO .* hello\n`) |
167 | + c.Assert(testing.Stderr(ctx), gc.Matches, `^.* INFO .* hello\n`) |
168 | } |
169 | |
170 | func (s *LogSuite) TestRelPathLog(c *gc.C) { |
171 | @@ -74,10 +94,11 @@ |
172 | err := l.Start(ctx) |
173 | c.Assert(err, gc.IsNil) |
174 | log.Infof("hello") |
175 | - c.Assert(bufferString(ctx.Stderr), gc.Equals, "") |
176 | content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) |
177 | c.Assert(err, gc.IsNil) |
178 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) |
179 | + c.Assert(testing.Stderr(ctx), gc.Equals, "") |
180 | + c.Assert(testing.Stdout(ctx), gc.Equals, "") |
181 | } |
182 | |
183 | func (s *LogSuite) TestAbsPathLog(c *gc.C) { |
184 | @@ -87,8 +108,21 @@ |
185 | err := l.Start(ctx) |
186 | c.Assert(err, gc.IsNil) |
187 | log.Infof("hello") |
188 | - c.Assert(bufferString(ctx.Stderr), gc.Equals, "") |
189 | + c.Assert(testing.Stderr(ctx), gc.Equals, "") |
190 | content, err := ioutil.ReadFile(path) |
191 | c.Assert(err, gc.IsNil) |
192 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) |
193 | } |
194 | + |
195 | +func (s *LogSuite) TestLoggingToFileAndStderr(c *gc.C) { |
196 | + l := &cmd.Log{Path: "foo.log", Config: "<root>=INFO", ShowLog: true} |
197 | + ctx := testing.Context(c) |
198 | + err := l.Start(ctx) |
199 | + c.Assert(err, gc.IsNil) |
200 | + log.Infof("hello") |
201 | + content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) |
202 | + c.Assert(err, gc.IsNil) |
203 | + c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) |
204 | + c.Assert(testing.Stderr(ctx), gc.Matches, `^.* INFO .* hello\n`) |
205 | + c.Assert(testing.Stdout(ctx), gc.Equals, "") |
206 | +} |
Reviewers: mp+185193_ code.launchpad. net,
Message:
Please take a look.
Description:
Make show-log an explicit arg.
This is part of the prelude to making --verbose mean
something else.
Also now, you can specify a log file and ask for show-log
and the logging goes to both places.
There is now a deprecation warning written out if people use
--verbose.
https:/ /code.launchpad .net/~thumper/ juju-core/ show-log/ +merge/ 185193
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/13352052/
Affected files (+71, -23 lines): main_test. go
A [revision details]
M cmd/juju/
M cmd/logging.go
M cmd/logging_test.go
Index: [revision details] 20130912013106- u5aifia59afghpi v
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: cmd/logging.go
=== modified file 'cmd/logging.go'
--- cmd/logging.go 2013-06-20 11:03:10 +0000
+++ cmd/logging.go 2013-09-12 03:48:50 +0000
@@ -4,7 +4,6 @@
package cmd
import (
- "io"
"os"
"launchpad. net/gnuflag"
@@ -17,6 +16,7 @@
Path string
Verbose bool
Debug bool
+ ShowLog bool
Config string
}
@@ -28,38 +28,49 @@ &l.Verbose, "verbose", false, "if set, log additional messages") &l.Debug, "debug", false, "if set, log debugging messages") &l.Config, "log-config", "", "specify log levels for modules") &l.ShowLog, "show-log", false, "if set, write the log file to
f.BoolVar(
f.BoolVar(
f.StringVar(
+ f.BoolVar(
stderr")
}
// Start starts logging using the given Context. os.O_APPEND| os.O_CREATE, os.O_APPEND| os.O_CREATE, Writer( target, &loggo. DefaultFormatte r{}) faultWriter( writer) riter(" logfile" , writer, loggo.TRACE) Write([ ]byte(" verbose is deprecated with the current meaning, Writer( ctx.Stderr, &loggo. DefaultFormatte r{}) faultWriter( writer) RemoveWriter( "default" ) ("").SetLogLeve l(level) (""...
-func (l *Log) Start(ctx *Context) (err error) {
- var target io.Writer
+func (l *Log) Start(ctx *Context) error {
if l.Path != "" {
path := ctx.AbsPath(l.Path)
- target, err = os.OpenFile(path, os.O_WRONLY|
0644)
+ target, err := os.OpenFile(path, os.O_WRONLY|
0644)
if err != nil {
return err
}
- } else if l.Verbose || l.Debug {
- target = ctx.Stderr
- }
-
- if target != nil {
writer := loggo.NewSimple
- _, err = loggo.ReplaceDe
+ err = loggo.RegisterW
+ if err != nil {
+ return err
+ }
+ }
+ level := loggo.WARNING
+ if l.Verbose {
+ ctx.Stdout.
use show-log\n"))
+ l.ShowLog = true
+ }
+ if l.ShowLog {
+ level = loggo.INFO
+ }
+ if l.Debug {
+ l.ShowLog = true
+ level = loggo.DEBUG
+ }
+
+ if l.ShowLog {
+ // We replace the default writer to use ctx.Stderr rather than os.Stderr.
+ writer := loggo.NewSimple
+ _, err := loggo.ReplaceDe
if err != nil {
return err
}
} else {
loggo.
}
- if l.Verbose || l.Debug {
- level := loggo.INFO
- if l.Debug {
- level = loggo.DEBUG
- }
- // Set the level on the root logger.
- loggo.GetLogger
- }
+ // Set the level on the root logger.
+ loggo.GetLogger