Merge lp:~thumper/juju-core/use-loggo into lp:~juju/juju-core/trunk
- use-loggo
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | William Reade |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1250 |
Proposed branch: | lp:~thumper/juju-core/use-loggo |
Merge into: | lp:~juju/juju-core/trunk |
Diff against target: |
1039 lines (+177/-249) 19 files modified
charm/dir_test.go (+4/-4) charm/repo_test.go (+10/-6) cmd/builddb/main.go (+12/-19) cmd/charmd/main.go (+0/-3) cmd/charmload/main.go (+0/-3) cmd/juju/main_test.go (+8/-2) cmd/logging.go (+22/-14) cmd/logging_test.go (+10/-36) cmd/supercommand_test.go (+1/-7) environs/cloudinit/cloudinit.go (+2/-2) log/log.go (+12/-43) log/log_test.go (+49/-31) state/watcher/watcher_test.go (+0/-10) store/store_test.go (+5/-3) testing/log.go (+19/-8) worker/uniter/context_test.go (+0/-26) worker/uniter/jujuc/juju-log_test.go (+16/-30) worker/uniter/jujuc/server_test.go (+4/-0) worker/uniter/uniter_test.go (+3/-2) |
To merge this branch: | bzr merge lp:~thumper/juju-core/use-loggo |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+166611@code.launchpad.net |
Commit message
Description of the change
Integrate loggo as a hierarchical logger.
The existing logging is very flat and has very little control over what is output.
I wrote loggo as a Go port of a C++ library I wrote for nux/unity (my third or fourth logging library). Loggers are very lightweight objects that have a single pointer to the module. A module is defined by a dotted name, like "juju.uniter" or "juju.provider.
The existing log package has been updated to use the loggo methods so we don't have to change all the call sites immediately. However we should start to move to more detailed modules for logging as we can have better control over it.
We should, as a soon to be done step, provide a way, probably using set-env, to configure logging for various machine agents or unit agents. This would allow a high level of control over what information gets logged.
Tim Penhey (thumper) wrote : | # |
Dave Cheney (dave-cheney) wrote : | # |
LGTM.
On Fri, May 31, 2013 at 12:47 PM, Tim Penhey <email address hidden>wrote:
> The proposal to merge lp:~thumper/juju-core/use-loggo into lp:juju-core
> has been updated.
>
> Description changed to:
>
> Integrate loggo as a hierarchical logger.
>
> The existing logging is very flat and has very little control over what is
> output.
>
> I wrote loggo as a Go port of a C++ library I wrote for nux/unity (my
> third or fourth logging library). Loggers are very lightweight objects
> that have a single pointer to the module. A module is defined by a dotted
> name, like "juju.uniter" or "juju.provider.
> depth of nesting. Logging levels are inherited unless explicitly set. The
> root logger, identified by the module "" (empty string), defaults to
> WARNING.
>
> The existing log package has been updated to use the loggo methods so we
> don't have to change all the call sites immediately. However we should
> start to move to more detailed modules for logging as we can have better
> control over it.
>
> We should, as a soon to be done step, provide a way, probably using
> set-env, to configure logging for various machine agents or unit agents.
> This would allow a high level of control over what information gets logged.
>
> https:/
>
> For more details, see:
> https:/
> --
> https:/
> Your team juju hackers is requested to review the proposed merge of
> lp:~thumper/juju-core/use-loggo into lp:juju-core.
>
Frank Mueller (themue) wrote : | # |
LGTM
https:/
File cmd/logging.go (right):
https:/
cmd/logging.go:26: // TODO: rename verbose to --show-log
TODO for whom? Use // TODO(nick) ...
https:/
File worker/
https:/
worker/
log writer to catch interesting log messages.
Again // TODO(nick) ...
John A Meinel (jameinel) wrote : | # |
Just to codify it, the switch to loggo LGTM, but I think I uncovered a
couple bugs in loggo itself. (if you do SetLoggingLevel
actually doesn't emit logger.Debug() messages (the check is
getEffectiveLevel() > level rather than getEffectiveLevel() >= level).
I'd like us to get some of that sorted out before then.
Tim Penhey (thumper) wrote : | # |
On 03/06/13 21:21, <email address hidden> wrote:
> Just to codify it, the switch to loggo LGTM, but I think I uncovered a
> couple bugs in loggo itself. (if you do SetLoggingLevel
> actually doesn't emit logger.Debug() messages (the check is
> getEffectiveLevel() > level rather than getEffectiveLevel() >= level).
Yes it does, this is just a misunderstanding.
Tests for this are in loggo/writer_
John A Meinel (jameinel) wrote : | # |
...
> Yes it does, this is just a misunderstanding.
> Tests for this are in loggo/writer_
Right, I had the comparison turned around. LGTM
Tim Penhey (thumper) wrote : | # |
*** Submitted:
Integrate loggo as a hierarchical logger.
The existing logging is very flat and has very little control over what
is output.
I wrote loggo as a Go port of a C++ library I wrote for nux/unity (my
third or fourth logging library). Loggers are very lightweight objects
that have a single pointer to the module. A module is defined by a
dotted name, like "juju.uniter" or "juju.provider.
limit to the depth of nesting. Logging levels are inherited unless
explicitly set. The root logger, identified by the module "" (empty
string), defaults to WARNING.
The existing log package has been updated to use the loggo methods so we
don't have to change all the call sites immediately. However we should
start to move to more detailed modules for logging as we can have better
control over it.
We should, as a soon to be done step, provide a way, probably using
set-env, to configure logging for various machine agents or unit agents.
This would allow a high level of control over what information gets
logged.
R=mue, jameinel
CC=
https:/
Preview Diff
1 | === modified file 'charm/dir_test.go' | |||
2 | --- charm/dir_test.go 2013-05-02 15:55:42 +0000 | |||
3 | +++ charm/dir_test.go 2013-06-04 23:43:27 +0000 | |||
4 | @@ -10,7 +10,6 @@ | |||
5 | 10 | "io/ioutil" | 10 | "io/ioutil" |
6 | 11 | . "launchpad.net/gocheck" | 11 | . "launchpad.net/gocheck" |
7 | 12 | "launchpad.net/juju-core/charm" | 12 | "launchpad.net/juju-core/charm" |
8 | 13 | "launchpad.net/juju-core/log" | ||
9 | 14 | "launchpad.net/juju-core/testing" | 13 | "launchpad.net/juju-core/testing" |
10 | 15 | "os" | 14 | "os" |
11 | 16 | "path/filepath" | 15 | "path/filepath" |
12 | @@ -18,7 +17,9 @@ | |||
13 | 18 | "syscall" | 17 | "syscall" |
14 | 19 | ) | 18 | ) |
15 | 20 | 19 | ||
17 | 21 | type DirSuite struct{} | 20 | type DirSuite struct { |
18 | 21 | testing.LoggingSuite | ||
19 | 22 | } | ||
20 | 22 | 23 | ||
21 | 23 | var _ = Suite(&DirSuite{}) | 24 | var _ = Suite(&DirSuite{}) |
22 | 24 | 25 | ||
23 | @@ -121,7 +122,6 @@ | |||
24 | 121 | 122 | ||
25 | 122 | // Bug #864164: Must complain if charm hooks aren't executable | 123 | // Bug #864164: Must complain if charm hooks aren't executable |
26 | 123 | func (s *DirSuite) TestBundleToWithNonExecutableHooks(c *C) { | 124 | func (s *DirSuite) TestBundleToWithNonExecutableHooks(c *C) { |
27 | 124 | defer log.SetTarget(log.SetTarget(c)) | ||
28 | 125 | hooks := []string{"install", "start", "config-changed", "upgrade-charm", "stop"} | 125 | hooks := []string{"install", "start", "config-changed", "upgrade-charm", "stop"} |
29 | 126 | for _, relName := range []string{"foo", "bar", "self"} { | 126 | for _, relName := range []string{"foo", "bar", "self"} { |
30 | 127 | for _, kind := range []string{"joined", "changed", "departed", "broken"} { | 127 | for _, kind := range []string{"joined", "changed", "departed", "broken"} { |
31 | @@ -140,7 +140,7 @@ | |||
32 | 140 | tlog := c.GetTestLog() | 140 | tlog := c.GetTestLog() |
33 | 141 | for _, hook := range hooks { | 141 | for _, hook := range hooks { |
34 | 142 | fullpath := filepath.Join(dir.Path, "hooks", hook) | 142 | fullpath := filepath.Join(dir.Path, "hooks", hook) |
36 | 143 | exp := fmt.Sprintf(`^(.|\n)*WARNING charm: making "%s" executable in charm(.|\n)*$`, fullpath) | 143 | exp := fmt.Sprintf(`^(.|\n)*WARNING juju charm: making "%s" executable in charm(.|\n)*$`, fullpath) |
37 | 144 | c.Assert(tlog, Matches, exp, Commentf("hook %q was not made executable", fullpath)) | 144 | c.Assert(tlog, Matches, exp, Commentf("hook %q was not made executable", fullpath)) |
38 | 145 | } | 145 | } |
39 | 146 | 146 | ||
40 | 147 | 147 | ||
41 | === modified file 'charm/repo_test.go' | |||
42 | --- charm/repo_test.go 2013-05-02 15:55:42 +0000 | |||
43 | +++ charm/repo_test.go 2013-06-04 23:43:27 +0000 | |||
44 | @@ -11,7 +11,6 @@ | |||
45 | 11 | "io/ioutil" | 11 | "io/ioutil" |
46 | 12 | . "launchpad.net/gocheck" | 12 | . "launchpad.net/gocheck" |
47 | 13 | "launchpad.net/juju-core/charm" | 13 | "launchpad.net/juju-core/charm" |
48 | 14 | "launchpad.net/juju-core/log" | ||
49 | 15 | "launchpad.net/juju-core/testing" | 14 | "launchpad.net/juju-core/testing" |
50 | 16 | "net" | 15 | "net" |
51 | 17 | "net/http" | 16 | "net/http" |
52 | @@ -150,6 +149,7 @@ | |||
53 | 150 | } | 149 | } |
54 | 151 | 150 | ||
55 | 152 | type StoreSuite struct { | 151 | type StoreSuite struct { |
56 | 152 | testing.LoggingSuite | ||
57 | 153 | server *MockStore | 153 | server *MockStore |
58 | 154 | store *charm.CharmStore | 154 | store *charm.CharmStore |
59 | 155 | oldCacheDir string | 155 | oldCacheDir string |
60 | @@ -158,19 +158,24 @@ | |||
61 | 158 | var _ = Suite(&StoreSuite{}) | 158 | var _ = Suite(&StoreSuite{}) |
62 | 159 | 159 | ||
63 | 160 | func (s *StoreSuite) SetUpSuite(c *C) { | 160 | func (s *StoreSuite) SetUpSuite(c *C) { |
64 | 161 | s.LoggingSuite.SetUpSuite(c) | ||
65 | 161 | s.server = NewMockStore(c) | 162 | s.server = NewMockStore(c) |
66 | 162 | s.oldCacheDir = charm.CacheDir | 163 | s.oldCacheDir = charm.CacheDir |
67 | 163 | } | 164 | } |
68 | 164 | 165 | ||
69 | 165 | func (s *StoreSuite) SetUpTest(c *C) { | 166 | func (s *StoreSuite) SetUpTest(c *C) { |
70 | 167 | s.LoggingSuite.SetUpTest(c) | ||
71 | 166 | charm.CacheDir = c.MkDir() | 168 | charm.CacheDir = c.MkDir() |
72 | 167 | s.store = charm.NewStore("http://127.0.0.1:4444") | 169 | s.store = charm.NewStore("http://127.0.0.1:4444") |
73 | 168 | s.server.downloads = nil | 170 | s.server.downloads = nil |
74 | 169 | } | 171 | } |
75 | 170 | 172 | ||
76 | 173 | // Uses the TearDownTest from testing.LoggingSuite | ||
77 | 174 | |||
78 | 171 | func (s *StoreSuite) TearDownSuite(c *C) { | 175 | func (s *StoreSuite) TearDownSuite(c *C) { |
79 | 172 | charm.CacheDir = s.oldCacheDir | 176 | charm.CacheDir = s.oldCacheDir |
80 | 173 | s.server.lis.Close() | 177 | s.server.lis.Close() |
81 | 178 | s.LoggingSuite.TearDownSuite(c) | ||
82 | 174 | } | 179 | } |
83 | 175 | 180 | ||
84 | 176 | func (s *StoreSuite) TestMissing(c *C) { | 181 | func (s *StoreSuite) TestMissing(c *C) { |
85 | @@ -192,9 +197,8 @@ | |||
86 | 192 | } | 197 | } |
87 | 193 | 198 | ||
88 | 194 | func (s *StoreSuite) TestWarning(c *C) { | 199 | func (s *StoreSuite) TestWarning(c *C) { |
89 | 195 | defer log.SetTarget(log.SetTarget(c)) | ||
90 | 196 | curl := charm.MustParseURL("cs:series/unwise") | 200 | curl := charm.MustParseURL("cs:series/unwise") |
92 | 197 | expect := `.* WARNING charm: charm store reports for "cs:series/unwise": foolishness` + "\n" | 201 | expect := `.* WARNING juju charm: charm store reports for "cs:series/unwise": foolishness` + "\n" |
93 | 198 | r, err := s.store.Latest(curl) | 202 | r, err := s.store.Latest(curl) |
94 | 199 | c.Assert(r, Equals, 23) | 203 | c.Assert(r, Equals, 23) |
95 | 200 | c.Assert(err, IsNil) | 204 | c.Assert(err, IsNil) |
96 | @@ -495,9 +499,9 @@ | |||
97 | 495 | c.Assert(err, IsNil) | 499 | c.Assert(err, IsNil) |
98 | 496 | c.Assert(ch.Revision(), Equals, 1) | 500 | c.Assert(ch.Revision(), Equals, 1) |
99 | 497 | c.Assert(c.GetTestLog(), Matches, ` | 501 | c.Assert(c.GetTestLog(), Matches, ` |
103 | 498 | .* WARNING charm: failed to load charm at ".*/series/blah": .* | 502 | .* WARNING juju charm: failed to load charm at ".*/series/blah": .* |
104 | 499 | .* WARNING charm: failed to load charm at ".*/series/blah.charm": .* | 503 | .* WARNING juju charm: failed to load charm at ".*/series/blah.charm": .* |
105 | 500 | .* WARNING charm: failed to load charm at ".*/series/upgrade2": .* | 504 | .* WARNING juju charm: failed to load charm at ".*/series/upgrade2": .* |
106 | 501 | `[1:]) | 505 | `[1:]) |
107 | 502 | } | 506 | } |
108 | 503 | 507 | ||
109 | 504 | 508 | ||
110 | === modified file 'cmd/builddb/main.go' | |||
111 | --- cmd/builddb/main.go 2013-05-02 15:55:42 +0000 | |||
112 | +++ cmd/builddb/main.go 2013-06-04 23:43:27 +0000 | |||
113 | @@ -5,15 +5,15 @@ | |||
114 | 5 | 5 | ||
115 | 6 | import ( | 6 | import ( |
116 | 7 | "fmt" | 7 | "fmt" |
117 | 8 | "os" | ||
118 | 9 | "path/filepath" | ||
119 | 10 | "time" | ||
120 | 11 | |||
121 | 8 | "launchpad.net/juju-core/charm" | 12 | "launchpad.net/juju-core/charm" |
122 | 9 | "launchpad.net/juju-core/environs" | 13 | "launchpad.net/juju-core/environs" |
123 | 10 | "launchpad.net/juju-core/juju" | 14 | "launchpad.net/juju-core/juju" |
124 | 11 | "launchpad.net/juju-core/log" | ||
125 | 12 | "launchpad.net/juju-core/state/api/params" | 15 | "launchpad.net/juju-core/state/api/params" |
130 | 13 | stdlog "log" | 16 | "launchpad.net/loggo" |
127 | 14 | "os" | ||
128 | 15 | "path/filepath" | ||
129 | 16 | "time" | ||
131 | 17 | ) | 17 | ) |
132 | 18 | 18 | ||
133 | 19 | // Import the providers. | 19 | // Import the providers. |
134 | @@ -21,8 +21,9 @@ | |||
135 | 21 | _ "launchpad.net/juju-core/environs/all" | 21 | _ "launchpad.net/juju-core/environs/all" |
136 | 22 | ) | 22 | ) |
137 | 23 | 23 | ||
138 | 24 | var logger = loggo.GetLogger("juju.builddb") | ||
139 | 25 | |||
140 | 24 | func main() { | 26 | func main() { |
141 | 25 | log.SetTarget(stdlog.New(os.Stdout, "", stdlog.LstdFlags)) | ||
142 | 26 | if err := build(); err != nil { | 27 | if err := build(); err != nil { |
143 | 27 | fmt.Fprintf(os.Stderr, "%v\n", err) | 28 | fmt.Fprintf(os.Stderr, "%v\n", err) |
144 | 28 | os.Exit(1) | 29 | os.Exit(1) |
145 | @@ -56,13 +57,13 @@ | |||
146 | 56 | return err | 57 | return err |
147 | 57 | } | 58 | } |
148 | 58 | 59 | ||
150 | 59 | log.Infof("builddb: Waiting for unit to reach %q status...", params.StatusStarted) | 60 | logger.Info("Waiting for unit to reach %q status...", params.StatusStarted) |
151 | 60 | unit := units[0] | 61 | unit := units[0] |
152 | 61 | last, info, err := unit.Status() | 62 | last, info, err := unit.Status() |
153 | 62 | if err != nil { | 63 | if err != nil { |
154 | 63 | return err | 64 | return err |
155 | 64 | } | 65 | } |
157 | 65 | logStatus(last, info) | 66 | logger.Info("Unit status is %q: %s", last, info) |
158 | 66 | for last != params.StatusStarted { | 67 | for last != params.StatusStarted { |
159 | 67 | time.Sleep(2 * time.Second) | 68 | time.Sleep(2 * time.Second) |
160 | 68 | if err := unit.Refresh(); err != nil { | 69 | if err := unit.Refresh(); err != nil { |
161 | @@ -73,7 +74,7 @@ | |||
162 | 73 | return err | 74 | return err |
163 | 74 | } | 75 | } |
164 | 75 | if status != last { | 76 | if status != last { |
166 | 76 | logStatus(status, info) | 77 | logger.Info("Unit status is %q: %s", status, info) |
167 | 77 | last = status | 78 | last = status |
168 | 78 | } | 79 | } |
169 | 79 | } | 80 | } |
170 | @@ -81,15 +82,7 @@ | |||
171 | 81 | if !ok { | 82 | if !ok { |
172 | 82 | return fmt.Errorf("cannot retrieve files: build unit lacks a public-address") | 83 | return fmt.Errorf("cannot retrieve files: build unit lacks a public-address") |
173 | 83 | } | 84 | } |
176 | 84 | log.Noticef("builddb: Built files published at http://%s", addr) | 85 | logger.Info("Built files published at http://%s", addr) |
177 | 85 | log.Noticef("builddb: Remember to destroy the environment when you're done...") | 86 | logger.Info("Remember to destroy the environment when you're done...") |
178 | 86 | return nil | 87 | return nil |
179 | 87 | } | 88 | } |
180 | 88 | |||
181 | 89 | func logStatus(status params.Status, info string) { | ||
182 | 90 | if info == "" { | ||
183 | 91 | log.Infof("builddb: Unit status is %q", status) | ||
184 | 92 | } else { | ||
185 | 93 | log.Infof("builddb: Unit status is %q: %s", status, info) | ||
186 | 94 | } | ||
187 | 95 | } | ||
188 | 96 | 89 | ||
189 | === modified file 'cmd/charmd/main.go' | |||
190 | --- cmd/charmd/main.go 2013-05-02 15:55:42 +0000 | |||
191 | +++ cmd/charmd/main.go 2013-06-04 23:43:27 +0000 | |||
192 | @@ -7,16 +7,13 @@ | |||
193 | 7 | "fmt" | 7 | "fmt" |
194 | 8 | "io/ioutil" | 8 | "io/ioutil" |
195 | 9 | "launchpad.net/goyaml" | 9 | "launchpad.net/goyaml" |
196 | 10 | "launchpad.net/juju-core/log" | ||
197 | 11 | "launchpad.net/juju-core/store" | 10 | "launchpad.net/juju-core/store" |
198 | 12 | stdlog "log" | ||
199 | 13 | "net/http" | 11 | "net/http" |
200 | 14 | "os" | 12 | "os" |
201 | 15 | "path/filepath" | 13 | "path/filepath" |
202 | 16 | ) | 14 | ) |
203 | 17 | 15 | ||
204 | 18 | func main() { | 16 | func main() { |
205 | 19 | log.SetTarget(stdlog.New(os.Stdout, "", stdlog.LstdFlags)) | ||
206 | 20 | err := serve() | 17 | err := serve() |
207 | 21 | if err != nil { | 18 | if err != nil { |
208 | 22 | fmt.Fprintf(os.Stderr, "%v\n", err) | 19 | fmt.Fprintf(os.Stderr, "%v\n", err) |
209 | 23 | 20 | ||
210 | === modified file 'cmd/charmload/main.go' | |||
211 | --- cmd/charmload/main.go 2013-05-02 15:55:42 +0000 | |||
212 | +++ cmd/charmload/main.go 2013-06-04 23:43:27 +0000 | |||
213 | @@ -7,16 +7,13 @@ | |||
214 | 7 | "fmt" | 7 | "fmt" |
215 | 8 | "io/ioutil" | 8 | "io/ioutil" |
216 | 9 | "launchpad.net/goyaml" | 9 | "launchpad.net/goyaml" |
217 | 10 | "launchpad.net/juju-core/log" | ||
218 | 11 | "launchpad.net/juju-core/store" | 10 | "launchpad.net/juju-core/store" |
219 | 12 | "launchpad.net/lpad" | 11 | "launchpad.net/lpad" |
220 | 13 | stdlog "log" | ||
221 | 14 | "os" | 12 | "os" |
222 | 15 | "path/filepath" | 13 | "path/filepath" |
223 | 16 | ) | 14 | ) |
224 | 17 | 15 | ||
225 | 18 | func main() { | 16 | func main() { |
226 | 19 | log.SetTarget(stdlog.New(os.Stdout, "", stdlog.LstdFlags)) | ||
227 | 20 | err := load() | 17 | err := load() |
228 | 21 | if err != nil { | 18 | if err != nil { |
229 | 22 | fmt.Fprintf(os.Stderr, "%v\n", err) | 19 | fmt.Fprintf(os.Stderr, "%v\n", err) |
230 | 23 | 20 | ||
231 | === modified file 'cmd/juju/main_test.go' | |||
232 | --- cmd/juju/main_test.go 2013-05-28 02:05:06 +0000 | |||
233 | +++ cmd/juju/main_test.go 2013-06-04 23:43:27 +0000 | |||
234 | @@ -15,6 +15,7 @@ | |||
235 | 15 | _ "launchpad.net/juju-core/environs/dummy" | 15 | _ "launchpad.net/juju-core/environs/dummy" |
236 | 16 | "launchpad.net/juju-core/testing" | 16 | "launchpad.net/juju-core/testing" |
237 | 17 | "launchpad.net/juju-core/version" | 17 | "launchpad.net/juju-core/version" |
238 | 18 | "launchpad.net/loggo" | ||
239 | 18 | "os" | 19 | "os" |
240 | 19 | "os/exec" | 20 | "os/exec" |
241 | 20 | "path/filepath" | 21 | "path/filepath" |
242 | @@ -71,6 +72,10 @@ | |||
243 | 71 | return helpText(&SyncToolsCommand{}, "juju sync-tools") | 72 | return helpText(&SyncToolsCommand{}, "juju sync-tools") |
244 | 72 | } | 73 | } |
245 | 73 | 74 | ||
246 | 75 | func (s *MainSuite) TestTearDown(c *C) { | ||
247 | 76 | loggo.ResetLogging() | ||
248 | 77 | } | ||
249 | 78 | |||
250 | 74 | func (s *MainSuite) TestRunMain(c *C) { | 79 | func (s *MainSuite) TestRunMain(c *C) { |
251 | 75 | defer testing.MakeSampleHome(c).Restore() | 80 | defer testing.MakeSampleHome(c).Restore() |
252 | 76 | // The test array structure needs to be inline here as some of the | 81 | // The test array structure needs to be inline here as some of the |
253 | @@ -188,7 +193,7 @@ | |||
254 | 188 | c.Assert(out, Equals, "error: "+msg+"\n") | 193 | c.Assert(out, Equals, "error: "+msg+"\n") |
255 | 189 | content, err := ioutil.ReadFile(logpath) | 194 | content, err := ioutil.ReadFile(logpath) |
256 | 190 | c.Assert(err, IsNil) | 195 | c.Assert(err, IsNil) |
258 | 191 | fullmsg := fmt.Sprintf(`(.|\n)*ERROR command failed: %s\n`, msg) | 196 | fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* command failed: %s\n`, msg) |
259 | 192 | c.Assert(string(content), Matches, fullmsg) | 197 | c.Assert(string(content), Matches, fullmsg) |
260 | 193 | } | 198 | } |
261 | 194 | 199 | ||
262 | @@ -201,7 +206,7 @@ | |||
263 | 201 | c.Assert(out, Equals, "error: "+msg+"\n") | 206 | c.Assert(out, Equals, "error: "+msg+"\n") |
264 | 202 | content, err := ioutil.ReadFile(logpath) | 207 | content, err := ioutil.ReadFile(logpath) |
265 | 203 | c.Assert(err, IsNil) | 208 | c.Assert(err, IsNil) |
267 | 204 | fullmsg := fmt.Sprintf(`(.|\n)*ERROR command failed: %s\n`, msg) | 209 | fullmsg := fmt.Sprintf(`(.|\n)*ERROR .* command failed: %s\n`, msg) |
268 | 205 | c.Assert(string(content), Matches, fullmsg) | 210 | c.Assert(string(content), Matches, fullmsg) |
269 | 206 | } | 211 | } |
270 | 207 | 212 | ||
271 | @@ -295,6 +300,7 @@ | |||
272 | 295 | var globalFlags = []string{ | 300 | var globalFlags = []string{ |
273 | 296 | "--debug .*", | 301 | "--debug .*", |
274 | 297 | "-h, --help .*", | 302 | "-h, --help .*", |
275 | 303 | "--log-config .*", | ||
276 | 298 | "--log-file .*", | 304 | "--log-file .*", |
277 | 299 | "-v, --verbose .*", | 305 | "-v, --verbose .*", |
278 | 300 | } | 306 | } |
279 | 301 | 307 | ||
280 | === modified file 'cmd/logging.go' | |||
281 | --- cmd/logging.go 2013-05-02 15:55:42 +0000 | |||
282 | +++ cmd/logging.go 2013-06-04 23:43:27 +0000 | |||
283 | @@ -5,10 +5,10 @@ | |||
284 | 5 | 5 | ||
285 | 6 | import ( | 6 | import ( |
286 | 7 | "io" | 7 | "io" |
287 | 8 | "os" | ||
288 | 9 | |||
289 | 8 | "launchpad.net/gnuflag" | 10 | "launchpad.net/gnuflag" |
293 | 9 | "launchpad.net/juju-core/log" | 11 | "launchpad.net/loggo" |
291 | 10 | stdlog "log" | ||
292 | 11 | "os" | ||
294 | 12 | ) | 12 | ) |
295 | 13 | 13 | ||
296 | 14 | // Log supplies the necessary functionality for Commands that wish to set up | 14 | // Log supplies the necessary functionality for Commands that wish to set up |
297 | @@ -17,37 +17,45 @@ | |||
298 | 17 | Path string | 17 | Path string |
299 | 18 | Verbose bool | 18 | Verbose bool |
300 | 19 | Debug bool | 19 | Debug bool |
302 | 20 | log.Logger | 20 | Config string |
303 | 21 | } | 21 | } |
304 | 22 | 22 | ||
305 | 23 | // AddFlags adds appropriate flags to f. | 23 | // AddFlags adds appropriate flags to f. |
306 | 24 | func (l *Log) AddFlags(f *gnuflag.FlagSet) { | 24 | func (l *Log) AddFlags(f *gnuflag.FlagSet) { |
307 | 25 | f.StringVar(&l.Path, "log-file", "", "path to write log to") | 25 | f.StringVar(&l.Path, "log-file", "", "path to write log to") |
308 | 26 | // TODO: rename verbose to --show-log | ||
309 | 26 | f.BoolVar(&l.Verbose, "v", false, "if set, log additional messages") | 27 | f.BoolVar(&l.Verbose, "v", false, "if set, log additional messages") |
310 | 27 | f.BoolVar(&l.Verbose, "verbose", false, "if set, log additional messages") | 28 | f.BoolVar(&l.Verbose, "verbose", false, "if set, log additional messages") |
311 | 28 | f.BoolVar(&l.Debug, "debug", false, "if set, log debugging messages") | 29 | f.BoolVar(&l.Debug, "debug", false, "if set, log debugging messages") |
316 | 29 | } | 30 | f.StringVar(&l.Config, "log-config", "", "specify log levels for modules") |
313 | 30 | |||
314 | 31 | func (l *Log) Output(calldepth int, s string) error { | ||
315 | 32 | return l.Logger.Output(calldepth, s) | ||
317 | 33 | } | 31 | } |
318 | 34 | 32 | ||
319 | 35 | // Start starts logging using the given Context. | 33 | // Start starts logging using the given Context. |
320 | 36 | func (l *Log) Start(ctx *Context) (err error) { | 34 | func (l *Log) Start(ctx *Context) (err error) { |
321 | 37 | log.Debug = l.Debug | ||
322 | 38 | var target io.Writer | 35 | var target io.Writer |
323 | 39 | if l.Path != "" { | 36 | if l.Path != "" { |
324 | 40 | path := ctx.AbsPath(l.Path) | 37 | path := ctx.AbsPath(l.Path) |
325 | 41 | 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) |
326 | 42 | if err != nil { | 39 | if err != nil { |
328 | 43 | return | 40 | return err |
329 | 44 | } | 41 | } |
330 | 45 | } else if l.Verbose || l.Debug { | 42 | } else if l.Verbose || l.Debug { |
331 | 46 | target = ctx.Stderr | 43 | target = ctx.Stderr |
332 | 47 | } | 44 | } |
333 | 45 | |||
334 | 48 | if target != nil { | 46 | if target != nil { |
339 | 49 | l.Logger = stdlog.New(target, "", stdlog.LstdFlags) | 47 | writer := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{}) |
340 | 50 | log.SetTarget(l) | 48 | _, err = loggo.ReplaceDefaultWriter(writer) |
341 | 51 | } | 49 | if err != nil { |
342 | 52 | return | 50 | return err |
343 | 51 | } | ||
344 | 52 | } else { | ||
345 | 53 | loggo.RemoveWriter("default") | ||
346 | 54 | } | ||
347 | 55 | if l.Debug { | ||
348 | 56 | logger := loggo.GetLogger("juju") | ||
349 | 57 | logger.SetLogLevel(loggo.DEBUG) | ||
350 | 58 | } | ||
351 | 59 | loggo.ConfigureLogging(l.Config) | ||
352 | 60 | return nil | ||
353 | 53 | } | 61 | } |
354 | 54 | 62 | ||
355 | === modified file 'cmd/logging_test.go' | |||
356 | --- cmd/logging_test.go 2013-05-02 15:55:42 +0000 | |||
357 | +++ cmd/logging_test.go 2013-06-04 23:43:27 +0000 | |||
358 | @@ -13,7 +13,6 @@ | |||
359 | 13 | ) | 13 | ) |
360 | 14 | 14 | ||
361 | 15 | type LogSuite struct { | 15 | type LogSuite struct { |
362 | 16 | testing.LoggingSuite | ||
363 | 17 | } | 16 | } |
364 | 18 | 17 | ||
365 | 19 | var _ = Suite(&LogSuite{}) | 18 | var _ = Suite(&LogSuite{}) |
366 | @@ -28,53 +27,28 @@ | |||
367 | 28 | c.Assert(l.Path, Equals, "") | 27 | c.Assert(l.Path, Equals, "") |
368 | 29 | c.Assert(l.Verbose, Equals, false) | 28 | c.Assert(l.Verbose, Equals, false) |
369 | 30 | c.Assert(l.Debug, Equals, false) | 29 | c.Assert(l.Debug, Equals, false) |
370 | 30 | c.Assert(l.Config, Equals, "") | ||
371 | 31 | 31 | ||
373 | 32 | err = f.Parse(false, []string{"--log-file", "foo", "--verbose", "--debug"}) | 32 | err = f.Parse(false, []string{"--log-file", "foo", "--verbose", "--debug", |
374 | 33 | "--log-config=juju.cmd=INFO;juju.worker.deployer=DEBUG"}) | ||
375 | 33 | c.Assert(err, IsNil) | 34 | c.Assert(err, IsNil) |
376 | 34 | c.Assert(l.Path, Equals, "foo") | 35 | c.Assert(l.Path, Equals, "foo") |
377 | 35 | c.Assert(l.Verbose, Equals, true) | 36 | c.Assert(l.Verbose, Equals, true) |
378 | 36 | c.Assert(l.Debug, Equals, true) | 37 | c.Assert(l.Debug, Equals, true) |
407 | 37 | } | 38 | c.Assert(l.Config, Equals, "juju.cmd=INFO;juju.worker.deployer=DEBUG") |
380 | 38 | |||
381 | 39 | func (s *LogSuite) TestStart(c *C) { | ||
382 | 40 | for _, t := range []struct { | ||
383 | 41 | path string | ||
384 | 42 | verbose bool | ||
385 | 43 | debug bool | ||
386 | 44 | check Checker | ||
387 | 45 | }{ | ||
388 | 46 | {"", true, true, NotNil}, | ||
389 | 47 | {"", true, false, NotNil}, | ||
390 | 48 | {"", false, true, NotNil}, | ||
391 | 49 | {"", false, false, IsNil}, | ||
392 | 50 | {"foo", true, true, NotNil}, | ||
393 | 51 | {"foo", true, false, NotNil}, | ||
394 | 52 | {"foo", false, true, NotNil}, | ||
395 | 53 | {"foo", false, false, NotNil}, | ||
396 | 54 | } { | ||
397 | 55 | // commands always start with the log target set to its zero value. | ||
398 | 56 | log.SetTarget(nil) | ||
399 | 57 | |||
400 | 58 | l := &cmd.Log{Path: t.path, Verbose: t.verbose, Debug: t.debug} | ||
401 | 59 | ctx := testing.Context(c) | ||
402 | 60 | err := l.Start(ctx) | ||
403 | 61 | c.Assert(err, IsNil) | ||
404 | 62 | c.Assert(log.Target(), t.check) | ||
405 | 63 | c.Assert(log.Debug, Equals, t.debug) | ||
406 | 64 | } | ||
408 | 65 | } | 39 | } |
409 | 66 | 40 | ||
410 | 67 | func (s *LogSuite) TestStderr(c *C) { | 41 | func (s *LogSuite) TestStderr(c *C) { |
412 | 68 | l := &cmd.Log{Verbose: true} | 42 | l := &cmd.Log{Verbose: true, Config: "<root>=INFO"} |
413 | 69 | ctx := testing.Context(c) | 43 | ctx := testing.Context(c) |
414 | 70 | err := l.Start(ctx) | 44 | err := l.Start(ctx) |
415 | 71 | c.Assert(err, IsNil) | 45 | c.Assert(err, IsNil) |
416 | 72 | log.Infof("hello") | 46 | log.Infof("hello") |
418 | 73 | c.Assert(bufferString(ctx.Stderr), Matches, `^.* INFO hello\n`) | 47 | c.Assert(bufferString(ctx.Stderr), Matches, `^.* INFO .* hello\n`) |
419 | 74 | } | 48 | } |
420 | 75 | 49 | ||
421 | 76 | func (s *LogSuite) TestRelPathLog(c *C) { | 50 | func (s *LogSuite) TestRelPathLog(c *C) { |
423 | 77 | l := &cmd.Log{Path: "foo.log"} | 51 | l := &cmd.Log{Path: "foo.log", Config: "<root>=INFO"} |
424 | 78 | ctx := testing.Context(c) | 52 | ctx := testing.Context(c) |
425 | 79 | err := l.Start(ctx) | 53 | err := l.Start(ctx) |
426 | 80 | c.Assert(err, IsNil) | 54 | c.Assert(err, IsNil) |
427 | @@ -82,12 +56,12 @@ | |||
428 | 82 | c.Assert(bufferString(ctx.Stderr), Equals, "") | 56 | c.Assert(bufferString(ctx.Stderr), Equals, "") |
429 | 83 | content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) | 57 | content, err := ioutil.ReadFile(filepath.Join(ctx.Dir, "foo.log")) |
430 | 84 | c.Assert(err, IsNil) | 58 | c.Assert(err, IsNil) |
432 | 85 | c.Assert(string(content), Matches, `^.* INFO hello\n`) | 59 | c.Assert(string(content), Matches, `^.* INFO .* hello\n`) |
433 | 86 | } | 60 | } |
434 | 87 | 61 | ||
435 | 88 | func (s *LogSuite) TestAbsPathLog(c *C) { | 62 | func (s *LogSuite) TestAbsPathLog(c *C) { |
436 | 89 | path := filepath.Join(c.MkDir(), "foo.log") | 63 | path := filepath.Join(c.MkDir(), "foo.log") |
438 | 90 | l := &cmd.Log{Path: path} | 64 | l := &cmd.Log{Path: path, Config: "<root>=INFO"} |
439 | 91 | ctx := testing.Context(c) | 65 | ctx := testing.Context(c) |
440 | 92 | err := l.Start(ctx) | 66 | err := l.Start(ctx) |
441 | 93 | c.Assert(err, IsNil) | 67 | c.Assert(err, IsNil) |
442 | @@ -95,5 +69,5 @@ | |||
443 | 95 | c.Assert(bufferString(ctx.Stderr), Equals, "") | 69 | c.Assert(bufferString(ctx.Stderr), Equals, "") |
444 | 96 | content, err := ioutil.ReadFile(path) | 70 | content, err := ioutil.ReadFile(path) |
445 | 97 | c.Assert(err, IsNil) | 71 | c.Assert(err, IsNil) |
447 | 98 | c.Assert(string(content), Matches, `^.* INFO hello\n`) | 72 | c.Assert(string(content), Matches, `^.* INFO .* hello\n`) |
448 | 99 | } | 73 | } |
449 | 100 | 74 | ||
450 | === modified file 'cmd/supercommand_test.go' | |||
451 | --- cmd/supercommand_test.go 2013-05-21 22:09:29 +0000 | |||
452 | +++ cmd/supercommand_test.go 2013-06-04 23:43:27 +0000 | |||
453 | @@ -8,7 +8,6 @@ | |||
454 | 8 | 8 | ||
455 | 9 | . "launchpad.net/gocheck" | 9 | . "launchpad.net/gocheck" |
456 | 10 | "launchpad.net/juju-core/cmd" | 10 | "launchpad.net/juju-core/cmd" |
457 | 11 | "launchpad.net/juju-core/log" | ||
458 | 12 | "launchpad.net/juju-core/testing" | 11 | "launchpad.net/juju-core/testing" |
459 | 13 | ) | 12 | ) |
460 | 14 | 13 | ||
461 | @@ -104,17 +103,12 @@ | |||
462 | 104 | } | 103 | } |
463 | 105 | 104 | ||
464 | 106 | func (s *SuperCommandSuite) TestLogging(c *C) { | 105 | func (s *SuperCommandSuite) TestLogging(c *C) { |
465 | 107 | target, debug := log.Target(), log.Debug | ||
466 | 108 | defer func() { | ||
467 | 109 | log.SetTarget(target) | ||
468 | 110 | log.Debug = debug | ||
469 | 111 | }() | ||
470 | 112 | jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest", Log: &cmd.Log{}}) | 106 | jc := cmd.NewSuperCommand(cmd.SuperCommandParams{Name: "jujutest", Log: &cmd.Log{}}) |
471 | 113 | jc.Register(&TestCommand{Name: "blah"}) | 107 | jc.Register(&TestCommand{Name: "blah"}) |
472 | 114 | ctx := testing.Context(c) | 108 | ctx := testing.Context(c) |
473 | 115 | code := cmd.Main(jc, ctx, []string{"blah", "--option", "error", "--debug"}) | 109 | code := cmd.Main(jc, ctx, []string{"blah", "--option", "error", "--debug"}) |
474 | 116 | c.Assert(code, Equals, 1) | 110 | c.Assert(code, Equals, 1) |
476 | 117 | c.Assert(bufferString(ctx.Stderr), Matches, `^.* ERROR command failed: BAM! | 111 | c.Assert(bufferString(ctx.Stderr), Matches, `^.* ERROR .* command failed: BAM! |
477 | 118 | error: BAM! | 112 | error: BAM! |
478 | 119 | `) | 113 | `) |
479 | 120 | } | 114 | } |
480 | 121 | 115 | ||
481 | === modified file 'environs/cloudinit/cloudinit.go' | |||
482 | --- environs/cloudinit/cloudinit.go 2013-05-31 07:39:15 +0000 | |||
483 | +++ environs/cloudinit/cloudinit.go 2013-06-04 23:43:27 +0000 | |||
484 | @@ -11,7 +11,6 @@ | |||
485 | 11 | "launchpad.net/juju-core/constraints" | 11 | "launchpad.net/juju-core/constraints" |
486 | 12 | "launchpad.net/juju-core/environs/agent" | 12 | "launchpad.net/juju-core/environs/agent" |
487 | 13 | "launchpad.net/juju-core/environs/config" | 13 | "launchpad.net/juju-core/environs/config" |
488 | 14 | "launchpad.net/juju-core/log" | ||
489 | 15 | "launchpad.net/juju-core/log/syslog" | 14 | "launchpad.net/juju-core/log/syslog" |
490 | 16 | "launchpad.net/juju-core/state" | 15 | "launchpad.net/juju-core/state" |
491 | 17 | "launchpad.net/juju-core/state/api" | 16 | "launchpad.net/juju-core/state/api" |
492 | @@ -131,9 +130,10 @@ | |||
493 | 131 | fmt.Sprintf("echo -n %s > $bin/downloaded-url.txt", shquote(cfg.Tools.URL)), | 130 | fmt.Sprintf("echo -n %s > $bin/downloaded-url.txt", shquote(cfg.Tools.URL)), |
494 | 132 | ) | 131 | ) |
495 | 133 | 132 | ||
496 | 133 | // TODO (thumper): work out how to pass the logging config to the children | ||
497 | 134 | debugFlag := "" | 134 | debugFlag := "" |
498 | 135 | // TODO: disable debug mode by default when the system is stable. | 135 | // TODO: disable debug mode by default when the system is stable. |
500 | 136 | if true || log.Debug { | 136 | if true { |
501 | 137 | debugFlag = " --debug" | 137 | debugFlag = " --debug" |
502 | 138 | } | 138 | } |
503 | 139 | 139 | ||
504 | 140 | 140 | ||
505 | === modified file 'log/log.go' | |||
506 | --- log/log.go 2013-05-02 15:55:42 +0000 | |||
507 | +++ log/log.go 2013-06-04 23:43:27 +0000 | |||
508 | @@ -4,71 +4,40 @@ | |||
509 | 4 | package log | 4 | package log |
510 | 5 | 5 | ||
511 | 6 | import ( | 6 | import ( |
514 | 7 | "fmt" | 7 | "launchpad.net/loggo" |
513 | 8 | "sync" | ||
515 | 9 | ) | 8 | ) |
516 | 10 | 9 | ||
517 | 11 | type Logger interface { | ||
518 | 12 | Output(calldepth int, s string) error | ||
519 | 13 | } | ||
520 | 14 | |||
521 | 15 | var ( | 10 | var ( |
527 | 16 | target struct { | 11 | logger = loggo.GetLogger("juju") |
523 | 17 | sync.Mutex | ||
524 | 18 | logger Logger | ||
525 | 19 | } | ||
526 | 20 | Debug bool | ||
528 | 21 | ) | 12 | ) |
529 | 22 | 13 | ||
530 | 23 | // Target returns the current log target. | ||
531 | 24 | func Target() Logger { | ||
532 | 25 | target.Lock() | ||
533 | 26 | defer target.Unlock() | ||
534 | 27 | return target.logger | ||
535 | 28 | } | ||
536 | 29 | |||
537 | 30 | // SetTarget sets the logging target and returns its | ||
538 | 31 | // previous value. | ||
539 | 32 | func SetTarget(logger Logger) (prev Logger) { | ||
540 | 33 | target.Lock() | ||
541 | 34 | defer target.Unlock() | ||
542 | 35 | prev = target.logger | ||
543 | 36 | target.logger = logger | ||
544 | 37 | return | ||
545 | 38 | } | ||
546 | 39 | |||
547 | 40 | func logf(format string, a ...interface{}) error { | ||
548 | 41 | if target := Target(); target != nil { | ||
549 | 42 | const calldepth = 3 // magic | ||
550 | 43 | return target.Output(calldepth, fmt.Sprintf(format, a...)) | ||
551 | 44 | } | ||
552 | 45 | return nil | ||
553 | 46 | } | ||
554 | 47 | |||
555 | 48 | // Errorf logs a message using the ERROR priority. | 14 | // Errorf logs a message using the ERROR priority. |
556 | 49 | func Errorf(format string, a ...interface{}) error { | 15 | func Errorf(format string, a ...interface{}) error { |
558 | 50 | return logf("ERROR "+format, a...) | 16 | logger.Log(loggo.ERROR, format, a...) |
559 | 17 | return nil | ||
560 | 51 | } | 18 | } |
561 | 52 | 19 | ||
562 | 53 | // Warningf logs a message using the WARNING priority. | 20 | // Warningf logs a message using the WARNING priority. |
563 | 54 | func Warningf(format string, a ...interface{}) error { | 21 | func Warningf(format string, a ...interface{}) error { |
565 | 55 | return logf("WARNING "+format, a...) | 22 | logger.Log(loggo.WARNING, format, a...) |
566 | 23 | return nil | ||
567 | 56 | } | 24 | } |
568 | 57 | 25 | ||
569 | 58 | // Noticef logs a message using the NOTICE priority. | 26 | // Noticef logs a message using the NOTICE priority. |
570 | 27 | // Notice doesn't really convert to the loggo priorities... | ||
571 | 59 | func Noticef(format string, a ...interface{}) error { | 28 | func Noticef(format string, a ...interface{}) error { |
573 | 60 | return logf("NOTICE "+format, a...) | 29 | logger.Log(loggo.INFO, format, a...) |
574 | 30 | return nil | ||
575 | 61 | } | 31 | } |
576 | 62 | 32 | ||
577 | 63 | // Infof logs a message using the INFO priority. | 33 | // Infof logs a message using the INFO priority. |
578 | 64 | func Infof(format string, a ...interface{}) error { | 34 | func Infof(format string, a ...interface{}) error { |
580 | 65 | return logf("INFO "+format, a...) | 35 | logger.Log(loggo.INFO, format, a...) |
581 | 36 | return nil | ||
582 | 66 | } | 37 | } |
583 | 67 | 38 | ||
584 | 68 | // Debugf logs a message using the DEBUG priority. | 39 | // Debugf logs a message using the DEBUG priority. |
585 | 69 | func Debugf(format string, a ...interface{}) (err error) { | 40 | func Debugf(format string, a ...interface{}) (err error) { |
589 | 70 | if Debug { | 41 | logger.Log(loggo.DEBUG, format, a...) |
587 | 71 | return logf("DEBUG "+format, a...) | ||
588 | 72 | } | ||
590 | 73 | return nil | 42 | return nil |
591 | 74 | } | 43 | } |
592 | 75 | 44 | ||
593 | === modified file 'log/log_test.go' | |||
594 | --- log/log_test.go 2013-05-02 15:55:42 +0000 | |||
595 | +++ log/log_test.go 2013-06-04 23:43:27 +0000 | |||
596 | @@ -5,61 +5,79 @@ | |||
597 | 5 | 5 | ||
598 | 6 | import ( | 6 | import ( |
599 | 7 | "bytes" | 7 | "bytes" |
600 | 8 | "fmt" | ||
601 | 9 | "testing" | ||
602 | 10 | "time" | ||
603 | 11 | |||
604 | 8 | . "launchpad.net/gocheck" | 12 | . "launchpad.net/gocheck" |
605 | 9 | "launchpad.net/juju-core/log" | 13 | "launchpad.net/juju-core/log" |
608 | 10 | stdlog "log" | 14 | "launchpad.net/loggo" |
607 | 11 | "testing" | ||
609 | 12 | ) | 15 | ) |
610 | 13 | 16 | ||
611 | 14 | func Test(t *testing.T) { | 17 | func Test(t *testing.T) { |
612 | 15 | TestingT(t) | 18 | TestingT(t) |
613 | 16 | } | 19 | } |
614 | 17 | 20 | ||
623 | 18 | type suite struct{} | 21 | type testWriter struct { |
624 | 19 | 22 | bytes.Buffer | |
625 | 20 | var _ = Suite(suite{}) | 23 | } |
626 | 21 | 24 | ||
627 | 22 | func (suite) TestLoggerDebugFlag(c *C) { | 25 | type suite struct { |
628 | 23 | var buf bytes.Buffer | 26 | writer *testWriter |
629 | 24 | defer log.SetTarget(log.SetTarget(stdlog.New(&buf, "JUJU:", 0))) | 27 | oldWriter loggo.Writer |
630 | 25 | log.Debug = false | 28 | oldLevel loggo.Level |
631 | 29 | } | ||
632 | 30 | |||
633 | 31 | var _ = Suite(&suite{}) | ||
634 | 32 | |||
635 | 33 | func (t *testWriter) Write(level loggo.Level, module, filename string, line int, timestamp time.Time, message string) { | ||
636 | 34 | t.Buffer.WriteString(fmt.Sprintf("%s %s %s", level, module, message)) | ||
637 | 35 | } | ||
638 | 36 | |||
639 | 37 | func (s *suite) SetUpTest(c *C) { | ||
640 | 38 | var err error | ||
641 | 39 | s.writer = &testWriter{} | ||
642 | 40 | s.oldWriter, s.oldLevel, err = loggo.RemoveWriter("default") | ||
643 | 41 | c.Assert(err, IsNil) | ||
644 | 42 | err = loggo.RegisterWriter("test", s.writer, loggo.TRACE) | ||
645 | 43 | c.Assert(err, IsNil) | ||
646 | 44 | logger := loggo.GetLogger("juju") | ||
647 | 45 | logger.SetLogLevel(loggo.TRACE) | ||
648 | 46 | } | ||
649 | 47 | |||
650 | 48 | func (s *suite) TearDownTest(c *C) { | ||
651 | 49 | _, _, err := loggo.RemoveWriter("test") | ||
652 | 50 | c.Assert(err, IsNil) | ||
653 | 51 | err = loggo.RegisterWriter("default", s.oldWriter, s.oldLevel) | ||
654 | 52 | c.Assert(err, IsNil) | ||
655 | 53 | } | ||
656 | 54 | |||
657 | 55 | func (s *suite) TestLoggerDebug(c *C) { | ||
658 | 26 | input := "Hello World" | 56 | input := "Hello World" |
659 | 27 | log.Debugf(input) | 57 | log.Debugf(input) |
665 | 28 | c.Assert(buf.String(), Equals, "") | 58 | c.Assert(s.writer.String(), Equals, "DEBUG juju "+input) |
661 | 29 | buf.Reset() | ||
662 | 30 | log.Debug = true | ||
663 | 31 | log.Debugf(input) | ||
664 | 32 | c.Assert(buf.String(), Equals, "JUJU:DEBUG "+input+"\n") | ||
666 | 33 | } | 59 | } |
667 | 34 | 60 | ||
671 | 35 | func (suite) TestInfoLogger(c *C) { | 61 | func (s *suite) TestInfoLogger(c *C) { |
669 | 36 | var buf bytes.Buffer | ||
670 | 37 | defer log.SetTarget(log.SetTarget(stdlog.New(&buf, "JUJU:", 0))) | ||
672 | 38 | input := "Hello World" | 62 | input := "Hello World" |
673 | 39 | log.Infof(input) | 63 | log.Infof(input) |
675 | 40 | c.Assert(buf.String(), Equals, "JUJU:INFO "+input+"\n") | 64 | c.Assert(s.writer.String(), Equals, "INFO juju "+input) |
676 | 41 | } | 65 | } |
677 | 42 | 66 | ||
681 | 43 | func (suite) TestErrorLogger(c *C) { | 67 | func (s *suite) TestErrorLogger(c *C) { |
679 | 44 | var buf bytes.Buffer | ||
680 | 45 | defer log.SetTarget(log.SetTarget(stdlog.New(&buf, "JUJU:", 0))) | ||
682 | 46 | input := "Hello World" | 68 | input := "Hello World" |
683 | 47 | log.Errorf(input) | 69 | log.Errorf(input) |
685 | 48 | c.Assert(buf.String(), Equals, "JUJU:ERROR "+input+"\n") | 70 | c.Assert(s.writer.String(), Equals, "ERROR juju "+input) |
686 | 49 | } | 71 | } |
687 | 50 | 72 | ||
691 | 51 | func (suite) TestWarningLogger(c *C) { | 73 | func (s *suite) TestWarningLogger(c *C) { |
689 | 52 | var buf bytes.Buffer | ||
690 | 53 | defer log.SetTarget(log.SetTarget(stdlog.New(&buf, "JUJU:", 0))) | ||
692 | 54 | input := "Hello World" | 74 | input := "Hello World" |
693 | 55 | log.Warningf(input) | 75 | log.Warningf(input) |
695 | 56 | c.Assert(buf.String(), Equals, "JUJU:WARNING "+input+"\n") | 76 | c.Assert(s.writer.String(), Equals, "WARNING juju "+input) |
696 | 57 | } | 77 | } |
697 | 58 | 78 | ||
701 | 59 | func (suite) TestNoticeLogger(c *C) { | 79 | func (s *suite) TestNoticeLogger(c *C) { |
699 | 60 | var buf bytes.Buffer | ||
700 | 61 | defer log.SetTarget(log.SetTarget(stdlog.New(&buf, "JUJU:", 0))) | ||
702 | 62 | input := "Hello World" | 80 | input := "Hello World" |
703 | 63 | log.Noticef(input) | 81 | log.Noticef(input) |
705 | 64 | c.Assert(buf.String(), Equals, "JUJU:NOTICE "+input+"\n") | 82 | c.Assert(s.writer.String(), Equals, "INFO juju "+input) |
706 | 65 | } | 83 | } |
707 | 66 | 84 | ||
708 | === modified file 'state/watcher/watcher_test.go' | |||
709 | --- state/watcher/watcher_test.go 2013-05-02 15:55:42 +0000 | |||
710 | +++ state/watcher/watcher_test.go 2013-06-04 23:43:27 +0000 | |||
711 | @@ -7,7 +7,6 @@ | |||
712 | 7 | "labix.org/v2/mgo" | 7 | "labix.org/v2/mgo" |
713 | 8 | "labix.org/v2/mgo/txn" | 8 | "labix.org/v2/mgo/txn" |
714 | 9 | . "launchpad.net/gocheck" | 9 | . "launchpad.net/gocheck" |
715 | 10 | "launchpad.net/juju-core/log" | ||
716 | 11 | "launchpad.net/juju-core/state/watcher" | 10 | "launchpad.net/juju-core/state/watcher" |
717 | 12 | "launchpad.net/juju-core/testing" | 11 | "launchpad.net/juju-core/testing" |
718 | 13 | "launchpad.net/tomb" | 12 | "launchpad.net/tomb" |
719 | @@ -359,15 +358,6 @@ | |||
720 | 359 | const N = 500 | 358 | const N = 500 |
721 | 360 | const T = 10 | 359 | const T = 10 |
722 | 361 | 360 | ||
723 | 362 | // Too much data.. doesn't help. | ||
724 | 363 | debug := log.Debug | ||
725 | 364 | defer func() { log.Debug = debug }() | ||
726 | 365 | log.Debug = false | ||
727 | 366 | // There is a data race on log.Debug. To avoid this race stop the | ||
728 | 367 | // watcher before restoring the value of log.Debug so the watcher | ||
729 | 368 | // does not observe a stale value of log.Debug. | ||
730 | 369 | defer s.w.Stop() | ||
731 | 370 | |||
732 | 371 | c.Logf("Creating %d documents, %d per transaction...", N, T) | 361 | c.Logf("Creating %d documents, %d per transaction...", N, T) |
733 | 372 | ops := make([]txn.Op, T) | 362 | ops := make([]txn.Op, T) |
734 | 373 | for i := 0; i < (N / T); i++ { | 363 | for i := 0; i < (N / T); i++ { |
735 | 374 | 364 | ||
736 | === modified file 'store/store_test.go' | |||
737 | --- store/store_test.go 2013-05-02 15:55:42 +0000 | |||
738 | +++ store/store_test.go 2013-06-04 23:43:27 +0000 | |||
739 | @@ -10,7 +10,6 @@ | |||
740 | 10 | "labix.org/v2/mgo/bson" | 10 | "labix.org/v2/mgo/bson" |
741 | 11 | . "launchpad.net/gocheck" | 11 | . "launchpad.net/gocheck" |
742 | 12 | "launchpad.net/juju-core/charm" | 12 | "launchpad.net/juju-core/charm" |
743 | 13 | "launchpad.net/juju-core/log" | ||
744 | 14 | "launchpad.net/juju-core/store" | 13 | "launchpad.net/juju-core/store" |
745 | 15 | "launchpad.net/juju-core/testing" | 14 | "launchpad.net/juju-core/testing" |
746 | 16 | "strconv" | 15 | "strconv" |
747 | @@ -29,6 +28,7 @@ | |||
748 | 29 | type StoreSuite struct { | 28 | type StoreSuite struct { |
749 | 30 | MgoSuite | 29 | MgoSuite |
750 | 31 | testing.HTTPSuite | 30 | testing.HTTPSuite |
751 | 31 | testing.LoggingSuite | ||
752 | 32 | store *store.Store | 32 | store *store.Store |
753 | 33 | } | 33 | } |
754 | 34 | 34 | ||
755 | @@ -37,23 +37,25 @@ | |||
756 | 37 | func (s *StoreSuite) SetUpSuite(c *C) { | 37 | func (s *StoreSuite) SetUpSuite(c *C) { |
757 | 38 | s.MgoSuite.SetUpSuite(c) | 38 | s.MgoSuite.SetUpSuite(c) |
758 | 39 | s.HTTPSuite.SetUpSuite(c) | 39 | s.HTTPSuite.SetUpSuite(c) |
759 | 40 | s.LoggingSuite.SetUpSuite(c) | ||
760 | 40 | } | 41 | } |
761 | 41 | 42 | ||
762 | 42 | func (s *StoreSuite) TearDownSuite(c *C) { | 43 | func (s *StoreSuite) TearDownSuite(c *C) { |
763 | 44 | s.LoggingSuite.TearDownSuite(c) | ||
764 | 43 | s.HTTPSuite.TearDownSuite(c) | 45 | s.HTTPSuite.TearDownSuite(c) |
765 | 44 | s.MgoSuite.TearDownSuite(c) | 46 | s.MgoSuite.TearDownSuite(c) |
766 | 45 | } | 47 | } |
767 | 46 | 48 | ||
768 | 47 | func (s *StoreSuite) SetUpTest(c *C) { | 49 | func (s *StoreSuite) SetUpTest(c *C) { |
769 | 48 | s.MgoSuite.SetUpTest(c) | 50 | s.MgoSuite.SetUpTest(c) |
770 | 51 | s.LoggingSuite.SetUpTest(c) | ||
771 | 49 | var err error | 52 | var err error |
772 | 50 | s.store, err = store.Open(s.Addr) | 53 | s.store, err = store.Open(s.Addr) |
773 | 51 | c.Assert(err, IsNil) | 54 | c.Assert(err, IsNil) |
774 | 52 | log.SetTarget(c) | ||
775 | 53 | log.Debug = true | ||
776 | 54 | } | 55 | } |
777 | 55 | 56 | ||
778 | 56 | func (s *StoreSuite) TearDownTest(c *C) { | 57 | func (s *StoreSuite) TearDownTest(c *C) { |
779 | 58 | s.LoggingSuite.TearDownTest(c) | ||
780 | 57 | s.HTTPSuite.TearDownTest(c) | 59 | s.HTTPSuite.TearDownTest(c) |
781 | 58 | if s.store != nil { | 60 | if s.store != nil { |
782 | 59 | s.store.Close() | 61 | s.store.Close() |
783 | 60 | 62 | ||
784 | === modified file 'testing/log.go' | |||
785 | --- testing/log.go 2013-05-02 15:55:42 +0000 | |||
786 | +++ testing/log.go 2013-06-04 23:43:27 +0000 | |||
787 | @@ -4,8 +4,11 @@ | |||
788 | 4 | package testing | 4 | package testing |
789 | 5 | 5 | ||
790 | 6 | import ( | 6 | import ( |
791 | 7 | "fmt" | ||
792 | 8 | "time" | ||
793 | 9 | |||
794 | 7 | . "launchpad.net/gocheck" | 10 | . "launchpad.net/gocheck" |
796 | 8 | "launchpad.net/juju-core/log" | 11 | "launchpad.net/loggo" |
797 | 9 | ) | 12 | ) |
798 | 10 | 13 | ||
799 | 11 | // LoggingSuite redirects the juju logger to the test logger | 14 | // LoggingSuite redirects the juju logger to the test logger |
800 | @@ -14,18 +17,26 @@ | |||
801 | 14 | restoreLog func() | 17 | restoreLog func() |
802 | 15 | } | 18 | } |
803 | 16 | 19 | ||
804 | 20 | type gocheckWriter struct { | ||
805 | 21 | c *C | ||
806 | 22 | } | ||
807 | 23 | |||
808 | 24 | func (w *gocheckWriter) Write(level loggo.Level, module, filename string, line int, timestamp time.Time, message string) { | ||
809 | 25 | // Magic calldepth value... | ||
810 | 26 | w.c.Output(3, fmt.Sprintf("%s %s %s", level, module, message)) | ||
811 | 27 | } | ||
812 | 28 | |||
813 | 17 | func (t *LoggingSuite) SetUpSuite(c *C) {} | 29 | func (t *LoggingSuite) SetUpSuite(c *C) {} |
814 | 18 | func (t *LoggingSuite) TearDownSuite(c *C) {} | 30 | func (t *LoggingSuite) TearDownSuite(c *C) {} |
815 | 19 | 31 | ||
816 | 20 | func (t *LoggingSuite) SetUpTest(c *C) { | 32 | func (t *LoggingSuite) SetUpTest(c *C) { |
823 | 21 | target, debug := log.SetTarget(c), log.Debug | 33 | loggo.ResetWriters() |
824 | 22 | t.restoreLog = func() { | 34 | loggo.ReplaceDefaultWriter(&gocheckWriter{c}) |
825 | 23 | log.SetTarget(target) | 35 | loggo.ResetLogging() |
826 | 24 | log.Debug = debug | 36 | loggo.GetLogger("juju").SetLogLevel(loggo.DEBUG) |
821 | 25 | } | ||
822 | 26 | log.Debug = true | ||
827 | 27 | } | 37 | } |
828 | 28 | 38 | ||
829 | 29 | func (t *LoggingSuite) TearDownTest(c *C) { | 39 | func (t *LoggingSuite) TearDownTest(c *C) { |
831 | 30 | t.restoreLog() | 40 | loggo.ResetLogging() |
832 | 41 | loggo.ResetWriters() | ||
833 | 31 | } | 42 | } |
834 | 32 | 43 | ||
835 | === modified file 'worker/uniter/context_test.go' | |||
836 | --- worker/uniter/context_test.go 2013-05-27 13:16:23 +0000 | |||
837 | +++ worker/uniter/context_test.go 2013-06-04 23:43:27 +0000 | |||
838 | @@ -8,7 +8,6 @@ | |||
839 | 8 | "io/ioutil" | 8 | "io/ioutil" |
840 | 9 | . "launchpad.net/gocheck" | 9 | . "launchpad.net/gocheck" |
841 | 10 | "launchpad.net/juju-core/juju/testing" | 10 | "launchpad.net/juju-core/juju/testing" |
842 | 11 | "launchpad.net/juju-core/log" | ||
843 | 12 | "launchpad.net/juju-core/state" | 11 | "launchpad.net/juju-core/state" |
844 | 13 | "launchpad.net/juju-core/utils" | 12 | "launchpad.net/juju-core/utils" |
845 | 14 | "launchpad.net/juju-core/worker/uniter" | 13 | "launchpad.net/juju-core/worker/uniter" |
846 | @@ -197,23 +196,7 @@ | |||
847 | 197 | }, | 196 | }, |
848 | 198 | } | 197 | } |
849 | 199 | 198 | ||
850 | 200 | type logRecorder struct { | ||
851 | 201 | c *C | ||
852 | 202 | prefix string | ||
853 | 203 | lines []string | ||
854 | 204 | } | ||
855 | 205 | |||
856 | 206 | func (l *logRecorder) Output(calldepth int, s string) error { | ||
857 | 207 | if strings.HasPrefix(s, l.prefix) { | ||
858 | 208 | l.lines = append(l.lines, s[len(l.prefix):]) | ||
859 | 209 | } | ||
860 | 210 | l.c.Logf("%s", s) | ||
861 | 211 | return nil | ||
862 | 212 | } | ||
863 | 213 | |||
864 | 214 | func (s *RunHookSuite) TestRunHook(c *C) { | 199 | func (s *RunHookSuite) TestRunHook(c *C) { |
865 | 215 | logger := &logRecorder{c: c, prefix: "INFO worker/uniter: HOOK "} | ||
866 | 216 | defer log.SetTarget(log.SetTarget(logger)) | ||
867 | 217 | uuid, err := utils.NewUUID() | 200 | uuid, err := utils.NewUUID() |
868 | 218 | c.Assert(err, IsNil) | 201 | c.Assert(err, IsNil) |
869 | 219 | for i, t := range runHookTests { | 202 | for i, t := range runHookTests { |
870 | @@ -229,7 +212,6 @@ | |||
871 | 229 | charmDir, outPath = makeCharm(c, spec) | 212 | charmDir, outPath = makeCharm(c, spec) |
872 | 230 | } | 213 | } |
873 | 231 | toolsDir := c.MkDir() | 214 | toolsDir := c.MkDir() |
874 | 232 | logger.lines = nil | ||
875 | 233 | t0 := time.Now() | 215 | t0 := time.Now() |
876 | 234 | err := ctx.RunHook("something-happened", charmDir, toolsDir, "/path/to/socket") | 216 | err := ctx.RunHook("something-happened", charmDir, toolsDir, "/path/to/socket") |
877 | 235 | if t.err == "" { | 217 | if t.err == "" { |
878 | @@ -244,17 +226,9 @@ | |||
879 | 244 | } | 226 | } |
880 | 245 | AssertEnv(c, outPath, charmDir, env, uuid.String()) | 227 | AssertEnv(c, outPath, charmDir, env, uuid.String()) |
881 | 246 | } | 228 | } |
882 | 247 | var expectLog []string | ||
883 | 248 | if t.spec.stdout != "" { | ||
884 | 249 | expectLog = append(expectLog, splitLine(t.spec.stdout)...) | ||
885 | 250 | } | ||
886 | 251 | if t.spec.stderr != "" { | ||
887 | 252 | expectLog = append(expectLog, splitLine(t.spec.stderr)...) | ||
888 | 253 | } | ||
889 | 254 | if t.spec.background != "" && time.Now().Sub(t0) > 5*time.Second { | 229 | if t.spec.background != "" && time.Now().Sub(t0) > 5*time.Second { |
890 | 255 | c.Errorf("background process holding up hook execution") | 230 | c.Errorf("background process holding up hook execution") |
891 | 256 | } | 231 | } |
892 | 257 | c.Assert(logger.lines, DeepEquals, expectLog) | ||
893 | 258 | } | 232 | } |
894 | 259 | } | 233 | } |
895 | 260 | 234 | ||
896 | 261 | 235 | ||
897 | === modified file 'worker/uniter/jujuc/juju-log_test.go' | |||
898 | --- worker/uniter/jujuc/juju-log_test.go 2013-05-02 15:55:42 +0000 | |||
899 | +++ worker/uniter/jujuc/juju-log_test.go 2013-06-04 23:43:27 +0000 | |||
900 | @@ -4,14 +4,13 @@ | |||
901 | 4 | package jujuc_test | 4 | package jujuc_test |
902 | 5 | 5 | ||
903 | 6 | import ( | 6 | import ( |
904 | 7 | "bytes" | ||
905 | 8 | "fmt" | 7 | "fmt" |
906 | 8 | |||
907 | 9 | . "launchpad.net/gocheck" | 9 | . "launchpad.net/gocheck" |
908 | 10 | "launchpad.net/juju-core/cmd" | 10 | "launchpad.net/juju-core/cmd" |
909 | 11 | "launchpad.net/juju-core/log" | ||
910 | 12 | "launchpad.net/juju-core/testing" | 11 | "launchpad.net/juju-core/testing" |
911 | 13 | "launchpad.net/juju-core/worker/uniter/jujuc" | 12 | "launchpad.net/juju-core/worker/uniter/jujuc" |
913 | 14 | stdlog "log" | 13 | "launchpad.net/loggo" |
914 | 15 | ) | 14 | ) |
915 | 16 | 15 | ||
916 | 17 | type JujuLogSuite struct { | 16 | type JujuLogSuite struct { |
917 | @@ -20,36 +19,27 @@ | |||
918 | 20 | 19 | ||
919 | 21 | var _ = Suite(&JujuLogSuite{}) | 20 | var _ = Suite(&JujuLogSuite{}) |
920 | 22 | 21 | ||
921 | 23 | func pushLog(debug bool) (*bytes.Buffer, func()) { | ||
922 | 24 | oldTarget, oldDebug := log.Target(), log.Debug | ||
923 | 25 | var buf bytes.Buffer | ||
924 | 26 | log.SetTarget(stdlog.New(&buf, "JUJU:", 0)) | ||
925 | 27 | log.Debug = debug | ||
926 | 28 | return &buf, func() { | ||
927 | 29 | log.SetTarget(oldTarget) | ||
928 | 30 | log.Debug = oldDebug | ||
929 | 31 | } | ||
930 | 32 | } | ||
931 | 33 | |||
932 | 34 | var commonLogTests = []struct { | 22 | var commonLogTests = []struct { |
936 | 35 | debugEnabled bool | 23 | debugFlag bool |
937 | 36 | debugFlag bool | 24 | level loggo.Level |
935 | 37 | target string | ||
938 | 38 | }{ | 25 | }{ |
943 | 39 | {false, false, "JUJU:INFO"}, | 26 | {false, loggo.INFO}, |
944 | 40 | {false, true, ""}, | 27 | {true, loggo.DEBUG}, |
941 | 41 | {true, false, "JUJU:INFO"}, | ||
942 | 42 | {true, true, "JUJU:DEBUG"}, | ||
945 | 43 | } | 28 | } |
946 | 44 | 29 | ||
947 | 45 | func assertLogs(c *C, ctx jujuc.Context, badge string) { | 30 | func assertLogs(c *C, ctx jujuc.Context, badge string) { |
948 | 31 | loggo.ConfigureLogging("juju=DEBUG") | ||
949 | 32 | writer := &loggo.TestWriter{} | ||
950 | 33 | old_writer, err := loggo.ReplaceDefaultWriter(writer) | ||
951 | 34 | c.Assert(err, IsNil) | ||
952 | 35 | defer loggo.ReplaceDefaultWriter(old_writer) | ||
953 | 46 | msg1 := "the chickens" | 36 | msg1 := "the chickens" |
954 | 47 | msg2 := "are 110% AWESOME" | 37 | msg2 := "are 110% AWESOME" |
955 | 48 | com, err := jujuc.NewCommand(ctx, "juju-log") | 38 | com, err := jujuc.NewCommand(ctx, "juju-log") |
956 | 49 | c.Assert(err, IsNil) | 39 | c.Assert(err, IsNil) |
957 | 50 | for _, t := range commonLogTests { | 40 | for _, t := range commonLogTests { |
960 | 51 | buf, pop := pushLog(t.debugEnabled) | 41 | writer.Clear() |
961 | 52 | defer pop() | 42 | c.Assert(err, IsNil) |
962 | 53 | 43 | ||
963 | 54 | var args []string | 44 | var args []string |
964 | 55 | if t.debugFlag { | 45 | if t.debugFlag { |
965 | @@ -59,13 +49,9 @@ | |||
966 | 59 | } | 49 | } |
967 | 60 | code := cmd.Main(com, &cmd.Context{}, args) | 50 | code := cmd.Main(com, &cmd.Context{}, args) |
968 | 61 | c.Assert(code, Equals, 0) | 51 | c.Assert(code, Equals, 0) |
976 | 62 | 52 | c.Assert(writer.Log, HasLen, 1) | |
977 | 63 | if t.target == "" { | 53 | c.Assert(writer.Log[0].Level, Equals, t.level) |
978 | 64 | c.Assert(buf.String(), Equals, "") | 54 | c.Assert(writer.Log[0].Message, Equals, fmt.Sprintf("%s: %s %s", badge, msg1, msg2)) |
972 | 65 | } else { | ||
973 | 66 | expect := fmt.Sprintf("%s %s: %s %s\n", t.target, badge, msg1, msg2) | ||
974 | 67 | c.Assert(buf.String(), Equals, expect) | ||
975 | 68 | } | ||
979 | 69 | } | 55 | } |
980 | 70 | } | 56 | } |
981 | 71 | 57 | ||
982 | 72 | 58 | ||
983 | === modified file 'worker/uniter/jujuc/server_test.go' | |||
984 | --- worker/uniter/jujuc/server_test.go 2013-05-02 15:55:42 +0000 | |||
985 | +++ worker/uniter/jujuc/server_test.go 2013-06-04 23:43:27 +0000 | |||
986 | @@ -10,6 +10,7 @@ | |||
987 | 10 | "launchpad.net/gnuflag" | 10 | "launchpad.net/gnuflag" |
988 | 11 | . "launchpad.net/gocheck" | 11 | . "launchpad.net/gocheck" |
989 | 12 | "launchpad.net/juju-core/cmd" | 12 | "launchpad.net/juju-core/cmd" |
990 | 13 | "launchpad.net/juju-core/testing" | ||
991 | 13 | "launchpad.net/juju-core/worker/uniter/jujuc" | 14 | "launchpad.net/juju-core/worker/uniter/jujuc" |
992 | 14 | "net/rpc" | 15 | "net/rpc" |
993 | 15 | "os" | 16 | "os" |
994 | @@ -65,6 +66,7 @@ | |||
995 | 65 | } | 66 | } |
996 | 66 | 67 | ||
997 | 67 | type ServerSuite struct { | 68 | type ServerSuite struct { |
998 | 69 | testing.LoggingSuite | ||
999 | 68 | server *jujuc.Server | 70 | server *jujuc.Server |
1000 | 69 | sockPath string | 71 | sockPath string |
1001 | 70 | err chan error | 72 | err chan error |
1002 | @@ -73,6 +75,7 @@ | |||
1003 | 73 | var _ = Suite(&ServerSuite{}) | 75 | var _ = Suite(&ServerSuite{}) |
1004 | 74 | 76 | ||
1005 | 75 | func (s *ServerSuite) SetUpTest(c *C) { | 77 | func (s *ServerSuite) SetUpTest(c *C) { |
1006 | 78 | s.LoggingSuite.SetUpTest(c) | ||
1007 | 76 | s.sockPath = filepath.Join(c.MkDir(), "test.sock") | 79 | s.sockPath = filepath.Join(c.MkDir(), "test.sock") |
1008 | 77 | srv, err := jujuc.NewServer(factory, s.sockPath) | 80 | srv, err := jujuc.NewServer(factory, s.sockPath) |
1009 | 78 | c.Assert(err, IsNil) | 81 | c.Assert(err, IsNil) |
1010 | @@ -87,6 +90,7 @@ | |||
1011 | 87 | c.Assert(<-s.err, IsNil) | 90 | c.Assert(<-s.err, IsNil) |
1012 | 88 | _, err := os.Open(s.sockPath) | 91 | _, err := os.Open(s.sockPath) |
1013 | 89 | c.Assert(os.IsNotExist(err), Equals, true) | 92 | c.Assert(os.IsNotExist(err), Equals, true) |
1014 | 93 | s.LoggingSuite.TearDownTest(c) | ||
1015 | 90 | } | 94 | } |
1016 | 91 | 95 | ||
1017 | 92 | func (s *ServerSuite) Call(c *C, req jujuc.Request) (resp jujuc.Response, err error) { | 96 | func (s *ServerSuite) Call(c *C, req jujuc.Request) (resp jujuc.Response, err error) { |
1018 | 93 | 97 | ||
1019 | === modified file 'worker/uniter/uniter_test.go' | |||
1020 | --- worker/uniter/uniter_test.go 2013-05-31 08:33:34 +0000 | |||
1021 | +++ worker/uniter/uniter_test.go 2013-06-04 23:43:27 +0000 | |||
1022 | @@ -168,15 +168,16 @@ | |||
1023 | 168 | } | 168 | } |
1024 | 169 | 169 | ||
1025 | 170 | func (ctx *context) matchLogHooks(c *C) (match bool, overshoot bool) { | 170 | func (ctx *context) matchLogHooks(c *C) (match bool, overshoot bool) { |
1026 | 171 | // TODO: fix this to actually use a log writer to catch interesting log messages. | ||
1027 | 171 | // hookPattern matches juju-log calls as generated by writeHook. | 172 | // hookPattern matches juju-log calls as generated by writeHook. |
1029 | 172 | hookPattern := fmt.Sprintf(`^.* INFO `+ | 173 | hookPattern := fmt.Sprintf(`^.* INFO juju `+ |
1030 | 173 | `u/0(| [a-z0-9-]+:[0-9]+)`+ // juju-log badge; group matches relation id | 174 | `u/0(| [a-z0-9-]+:[0-9]+)`+ // juju-log badge; group matches relation id |
1031 | 174 | `: %s`+ // JUJU_ENV_UUID (context badge; prevents cross-test pollution) | 175 | `: %s`+ // JUJU_ENV_UUID (context badge; prevents cross-test pollution) |
1032 | 175 | ` ([0-9a-z-/ ]+)$`, // foo-relation-joined bar/123 | 176 | ` ([0-9a-z-/ ]+)$`, // foo-relation-joined bar/123 |
1033 | 176 | ctx.uuid, | 177 | ctx.uuid, |
1034 | 177 | ) | 178 | ) |
1035 | 178 | // donePattern matches uniter logging that indicates a hook has run. | 179 | // donePattern matches uniter logging that indicates a hook has run. |
1037 | 179 | donePattern := `^.* (INFO|ERROR) worker/uniter: (ran "[a-z0-9-]+" hook|hook failed)` | 180 | donePattern := `^.* (INFO|ERROR) juju worker/uniter: (ran "[a-z0-9-]+" hook|hook failed)` |
1038 | 180 | hookRegexp := regexp.MustCompile(hookPattern) | 181 | hookRegexp := regexp.MustCompile(hookPattern) |
1039 | 181 | doneRegexp := regexp.MustCompile(donePattern) | 182 | doneRegexp := regexp.MustCompile(donePattern) |
1040 | 182 | 183 |
Reviewers: mp+166611_ code.launchpad. net,
Message:
Please take a look.
Description:
https:/ /code.launchpad .net/~thumper/ juju-core/ use-loggo/ +merge/ 166611
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/9738051/
Affected files: main.go main_test. go d_test. go cloudinit/ cloudinit. go watcher_ test.go uniter/ context_ test.go uniter/ jujuc/juju- log_test. go uniter/ jujuc/server_ test.go uniter/ uniter_ test.go
A [revision details]
M charm/dir_test.go
M charm/repo_test.go
M cmd/builddb/main.go
M cmd/charmd/main.go
M cmd/charmload/
M cmd/juju/
M cmd/logging.go
M cmd/logging_test.go
M cmd/supercomman
M environs/
M log/log.go
M log/log_test.go
M state/watcher/
M store/store_test.go
M testing/log.go
M worker/
M worker/
M worker/
M worker/