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 | 192 | // Check global args work when specified before command | 192 | // Check global args work when specified before command |
6 | 193 | msg := breakJuju(c, "Bootstrap") | 193 | msg := breakJuju(c, "Bootstrap") |
7 | 194 | logpath := filepath.Join(c.MkDir(), "log") | 194 | logpath := filepath.Join(c.MkDir(), "log") |
9 | 195 | out := badrun(c, 1, "--log-file", logpath, "--verbose", "--debug", "bootstrap") | 195 | out := badrun(c, 1, "--log-file", logpath, "bootstrap") |
10 | 196 | c.Assert(out, gc.Equals, "error: "+msg+"\n") | 196 | c.Assert(out, gc.Equals, "error: "+msg+"\n") |
11 | 197 | content, err := ioutil.ReadFile(logpath) | 197 | content, err := ioutil.ReadFile(logpath) |
12 | 198 | c.Assert(err, gc.IsNil) | 198 | c.Assert(err, gc.IsNil) |
13 | @@ -205,7 +205,7 @@ | |||
14 | 205 | // Check global args work when specified after command | 205 | // Check global args work when specified after command |
15 | 206 | msg := breakJuju(c, "Bootstrap") | 206 | msg := breakJuju(c, "Bootstrap") |
16 | 207 | logpath := filepath.Join(c.MkDir(), "log") | 207 | logpath := filepath.Join(c.MkDir(), "log") |
18 | 208 | out := badrun(c, 1, "bootstrap", "--log-file", logpath, "--verbose", "--debug") | 208 | out := badrun(c, 1, "bootstrap", "--log-file", logpath) |
19 | 209 | c.Assert(out, gc.Equals, "error: "+msg+"\n") | 209 | c.Assert(out, gc.Equals, "error: "+msg+"\n") |
20 | 210 | content, err := ioutil.ReadFile(logpath) | 210 | content, err := ioutil.ReadFile(logpath) |
21 | 211 | c.Assert(err, gc.IsNil) | 211 | c.Assert(err, gc.IsNil) |
22 | @@ -313,6 +313,7 @@ | |||
23 | 313 | "-h, --help .*", | 313 | "-h, --help .*", |
24 | 314 | "--log-config .*", | 314 | "--log-config .*", |
25 | 315 | "--log-file .*", | 315 | "--log-file .*", |
26 | 316 | "--show-log .*", | ||
27 | 316 | "-v, --verbose .*", | 317 | "-v, --verbose .*", |
28 | 317 | } | 318 | } |
29 | 318 | 319 | ||
30 | 319 | 320 | ||
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 | 4 | package cmd | 4 | package cmd |
36 | 5 | 5 | ||
37 | 6 | import ( | 6 | import ( |
38 | 7 | "io" | ||
39 | 8 | "os" | 7 | "os" |
40 | 9 | 8 | ||
41 | 10 | "launchpad.net/gnuflag" | 9 | "launchpad.net/gnuflag" |
42 | @@ -17,6 +16,7 @@ | |||
43 | 17 | Path string | 16 | Path string |
44 | 18 | Verbose bool | 17 | Verbose bool |
45 | 19 | Debug bool | 18 | Debug bool |
46 | 19 | ShowLog bool | ||
47 | 20 | Config string | 20 | Config string |
48 | 21 | } | 21 | } |
49 | 22 | 22 | ||
50 | @@ -28,38 +28,49 @@ | |||
51 | 28 | f.BoolVar(&l.Verbose, "verbose", false, "if set, log additional messages") | 28 | f.BoolVar(&l.Verbose, "verbose", false, "if set, log additional messages") |
52 | 29 | f.BoolVar(&l.Debug, "debug", false, "if set, log debugging messages") | 29 | f.BoolVar(&l.Debug, "debug", false, "if set, log debugging messages") |
53 | 30 | f.StringVar(&l.Config, "log-config", "", "specify log levels for modules") | 30 | f.StringVar(&l.Config, "log-config", "", "specify log levels for modules") |
54 | 31 | f.BoolVar(&l.ShowLog, "show-log", false, "if set, write the log file to stderr") | ||
55 | 31 | } | 32 | } |
56 | 32 | 33 | ||
57 | 33 | // Start starts logging using the given Context. | 34 | // Start starts logging using the given Context. |
60 | 34 | func (l *Log) Start(ctx *Context) (err error) { | 35 | func (l *Log) Start(ctx *Context) error { |
59 | 35 | var target io.Writer | ||
61 | 36 | if l.Path != "" { | 36 | if l.Path != "" { |
62 | 37 | path := ctx.AbsPath(l.Path) | 37 | path := ctx.AbsPath(l.Path) |
64 | 38 | target, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) | 38 | target, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) |
65 | 39 | if err != nil { | 39 | if err != nil { |
66 | 40 | return err | 40 | return err |
67 | 41 | } | 41 | } |
68 | 42 | } else if l.Verbose || l.Debug { | ||
69 | 43 | target = ctx.Stderr | ||
70 | 44 | } | ||
71 | 45 | |||
72 | 46 | if target != nil { | ||
73 | 47 | writer := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{}) | 42 | writer := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{}) |
75 | 48 | _, err = loggo.ReplaceDefaultWriter(writer) | 43 | err = loggo.RegisterWriter("logfile", writer, loggo.TRACE) |
76 | 44 | if err != nil { | ||
77 | 45 | return err | ||
78 | 46 | } | ||
79 | 47 | } | ||
80 | 48 | level := loggo.WARNING | ||
81 | 49 | if l.Verbose { | ||
82 | 50 | ctx.Stdout.Write([]byte("verbose is deprecated with the current meaning, use show-log\n")) | ||
83 | 51 | l.ShowLog = true | ||
84 | 52 | } | ||
85 | 53 | if l.ShowLog { | ||
86 | 54 | level = loggo.INFO | ||
87 | 55 | } | ||
88 | 56 | if l.Debug { | ||
89 | 57 | l.ShowLog = true | ||
90 | 58 | level = loggo.DEBUG | ||
91 | 59 | } | ||
92 | 60 | |||
93 | 61 | if l.ShowLog { | ||
94 | 62 | // We replace the default writer to use ctx.Stderr rather than os.Stderr. | ||
95 | 63 | writer := loggo.NewSimpleWriter(ctx.Stderr, &loggo.DefaultFormatter{}) | ||
96 | 64 | _, err := loggo.ReplaceDefaultWriter(writer) | ||
97 | 49 | if err != nil { | 65 | if err != nil { |
98 | 50 | return err | 66 | return err |
99 | 51 | } | 67 | } |
100 | 52 | } else { | 68 | } else { |
101 | 53 | loggo.RemoveWriter("default") | 69 | loggo.RemoveWriter("default") |
102 | 54 | } | 70 | } |
111 | 55 | if l.Verbose || l.Debug { | 71 | // Set the level on the root logger. |
112 | 56 | level := loggo.INFO | 72 | loggo.GetLogger("").SetLogLevel(level) |
113 | 57 | if l.Debug { | 73 | // Override the logging config with specified logging config. |
106 | 58 | level = loggo.DEBUG | ||
107 | 59 | } | ||
108 | 60 | // Set the level on the root logger. | ||
109 | 61 | loggo.GetLogger("").SetLogLevel(level) | ||
110 | 62 | } | ||
114 | 63 | loggo.ConfigureLoggers(l.Config) | 74 | loggo.ConfigureLoggers(l.Config) |
115 | 64 | return nil | 75 | return nil |
116 | 65 | } | 76 | } |
117 | 66 | 77 | ||
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 | 20 | 20 | ||
123 | 21 | var _ = gc.Suite(&LogSuite{}) | 21 | var _ = gc.Suite(&LogSuite{}) |
124 | 22 | 22 | ||
125 | 23 | func (s *LogSuite) TearDownTest(c *gc.C) { | ||
126 | 24 | loggo.ResetLoggers() | ||
127 | 25 | loggo.ResetWriters() | ||
128 | 26 | } | ||
129 | 27 | |||
130 | 23 | func (s *LogSuite) TestAddFlags(c *gc.C) { | 28 | func (s *LogSuite) TestAddFlags(c *gc.C) { |
131 | 24 | l := &cmd.Log{} | 29 | l := &cmd.Log{} |
132 | 25 | f := testing.NewFlagSet() | 30 | f := testing.NewFlagSet() |
133 | @@ -48,6 +53,8 @@ | |||
134 | 48 | c.Assert(err, gc.IsNil) | 53 | c.Assert(err, gc.IsNil) |
135 | 49 | 54 | ||
136 | 50 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.INFO) | 55 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.INFO) |
137 | 56 | c.Assert(testing.Stderr(ctx), gc.Equals, "") | ||
138 | 57 | c.Assert(testing.Stdout(ctx), gc.Equals, "verbose is deprecated with the current meaning, use show-log\n") | ||
139 | 51 | } | 58 | } |
140 | 52 | 59 | ||
141 | 53 | func (s *LogSuite) TestDebugSetsLogLevel(c *gc.C) { | 60 | func (s *LogSuite) TestDebugSetsLogLevel(c *gc.C) { |
142 | @@ -57,6 +64,19 @@ | |||
143 | 57 | c.Assert(err, gc.IsNil) | 64 | c.Assert(err, gc.IsNil) |
144 | 58 | 65 | ||
145 | 59 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.DEBUG) | 66 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.DEBUG) |
146 | 67 | c.Assert(testing.Stderr(ctx), gc.Equals, "") | ||
147 | 68 | c.Assert(testing.Stdout(ctx), gc.Equals, "") | ||
148 | 69 | } | ||
149 | 70 | |||
150 | 71 | func (s *LogSuite) TestShowLogSetsLogLevel(c *gc.C) { | ||
151 | 72 | l := &cmd.Log{ShowLog: true} | ||
152 | 73 | ctx := testing.Context(c) | ||
153 | 74 | err := l.Start(ctx) | ||
154 | 75 | c.Assert(err, gc.IsNil) | ||
155 | 76 | |||
156 | 77 | c.Assert(loggo.GetLogger("").LogLevel(), gc.Equals, loggo.INFO) | ||
157 | 78 | c.Assert(testing.Stderr(ctx), gc.Equals, "") | ||
158 | 79 | c.Assert(testing.Stdout(ctx), gc.Equals, "") | ||
159 | 60 | } | 80 | } |
160 | 61 | 81 | ||
161 | 62 | func (s *LogSuite) TestStderr(c *gc.C) { | 82 | func (s *LogSuite) TestStderr(c *gc.C) { |
162 | @@ -65,7 +85,7 @@ | |||
163 | 65 | err := l.Start(ctx) | 85 | err := l.Start(ctx) |
164 | 66 | c.Assert(err, gc.IsNil) | 86 | c.Assert(err, gc.IsNil) |
165 | 67 | log.Infof("hello") | 87 | log.Infof("hello") |
167 | 68 | c.Assert(bufferString(ctx.Stderr), gc.Matches, `^.* INFO .* hello\n`) | 88 | c.Assert(testing.Stderr(ctx), gc.Matches, `^.* INFO .* hello\n`) |
168 | 69 | } | 89 | } |
169 | 70 | 90 | ||
170 | 71 | func (s *LogSuite) TestRelPathLog(c *gc.C) { | 91 | func (s *LogSuite) TestRelPathLog(c *gc.C) { |
171 | @@ -74,10 +94,11 @@ | |||
172 | 74 | err := l.Start(ctx) | 94 | err := l.Start(ctx) |
173 | 75 | c.Assert(err, gc.IsNil) | 95 | c.Assert(err, gc.IsNil) |
174 | 76 | log.Infof("hello") | 96 | log.Infof("hello") |
175 | 77 | c.Assert(bufferString(ctx.Stderr), gc.Equals, "") | ||
176 | 78 | content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) | 97 | content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) |
177 | 79 | c.Assert(err, gc.IsNil) | 98 | c.Assert(err, gc.IsNil) |
178 | 80 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) | 99 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) |
179 | 100 | c.Assert(testing.Stderr(ctx), gc.Equals, "") | ||
180 | 101 | c.Assert(testing.Stdout(ctx), gc.Equals, "") | ||
181 | 81 | } | 102 | } |
182 | 82 | 103 | ||
183 | 83 | func (s *LogSuite) TestAbsPathLog(c *gc.C) { | 104 | func (s *LogSuite) TestAbsPathLog(c *gc.C) { |
184 | @@ -87,8 +108,21 @@ | |||
185 | 87 | err := l.Start(ctx) | 108 | err := l.Start(ctx) |
186 | 88 | c.Assert(err, gc.IsNil) | 109 | c.Assert(err, gc.IsNil) |
187 | 89 | log.Infof("hello") | 110 | log.Infof("hello") |
189 | 90 | c.Assert(bufferString(ctx.Stderr), gc.Equals, "") | 111 | c.Assert(testing.Stderr(ctx), gc.Equals, "") |
190 | 91 | content, err := ioutil.ReadFile(path) | 112 | content, err := ioutil.ReadFile(path) |
191 | 92 | c.Assert(err, gc.IsNil) | 113 | c.Assert(err, gc.IsNil) |
192 | 93 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) | 114 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) |
193 | 94 | } | 115 | } |
194 | 116 | |||
195 | 117 | func (s *LogSuite) TestLoggingToFileAndStderr(c *gc.C) { | ||
196 | 118 | l := &cmd.Log{Path: "foo.log", Config: "<root>=INFO", ShowLog: true} | ||
197 | 119 | ctx := testing.Context(c) | ||
198 | 120 | err := l.Start(ctx) | ||
199 | 121 | c.Assert(err, gc.IsNil) | ||
200 | 122 | log.Infof("hello") | ||
201 | 123 | content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) | ||
202 | 124 | c.Assert(err, gc.IsNil) | ||
203 | 125 | c.Assert(string(content), gc.Matches, `^.* INFO .* hello\n`) | ||
204 | 126 | c.Assert(testing.Stderr(ctx), gc.Matches, `^.* INFO .* hello\n`) | ||
205 | 127 | c.Assert(testing.Stdout(ctx), gc.Equals, "") | ||
206 | 128 | } |
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