Merge lp:~vishvananda/nova/log-fix into lp:~hudson-openstack/nova/trunk
- log-fix
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Soren Hansen |
Approved revision: | 724 |
Merged at revision: | 711 |
Proposed branch: | lp:~vishvananda/nova/log-fix |
Merge into: | lp:~hudson-openstack/nova/trunk |
Diff against target: |
871 lines (+148/-130) 35 files modified
bin/nova-ajax-console-proxy (+1/-1) bin/nova-api (+3/-3) bin/nova-combined (+1/-2) bin/nova-compute (+4/-0) bin/nova-console (+4/-0) bin/nova-dhcpbridge (+1/-1) bin/nova-direct-api (+2/-0) bin/nova-import-canonical-imagestore (+2/-0) bin/nova-instancemonitor (+0/-3) bin/nova-manage (+1/-2) bin/nova-network (+4/-0) bin/nova-scheduler (+4/-0) bin/nova-volume (+4/-0) nova/api/openstack/auth.py (+0/-1) nova/api/openstack/backup_schedules.py (+0/-1) nova/api/openstack/images.py (+0/-2) nova/api/openstack/servers.py (+0/-1) nova/api/openstack/shared_ip_groups.py (+0/-2) nova/api/openstack/zones.py (+0/-1) nova/console/manager.py (+1/-1) nova/console/xvp.py (+1/-1) nova/log.py (+78/-53) nova/service.py (+0/-3) nova/test.py (+1/-1) nova/tests/fake_flags.py (+1/-0) nova/tests/test_auth.py (+0/-9) nova/tests/test_console.py (+0/-2) nova/tests/test_direct.py (+0/-1) nova/tests/test_localization.py (+0/-1) nova/tests/test_log.py (+30/-33) nova/twistd.py (+1/-1) nova/utils.py (+1/-1) nova/wsgi.py (+0/-1) run_tests.py (+2/-1) run_tests.sh (+1/-1) |
To merge this branch: | bzr merge lp:~vishvananda/nova/log-fix |
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Thierry Carrez (community) | Approve | ||
Devin Carlen (community) | Approve | ||
termie (community) | Approve | ||
Review via email: mp+50554@code.launchpad.net |
Commit message
Description of the change
Fixes various issues regarding verbose logging and logging errors on import.
* Adds a call to logging.reset() after flags are loaded via FLAGS()
* Uses logfile flag to log properly during run_tests
* Only adds handlers to root logger
* Removes the stream handler if logfile is set
* Syslog handler is in addition to logfile or stream handler
* Removed need for logging.
Vish Ishaya (vishvananda) wrote : | # |
The main issue is that how logging is configured is heavily dependent on flags. There are a number of ways to get into our code:
a) nova-* bin files
b) tests through nose
c) external code importing files
We can do all configuration without the initialized flag if we do something like
import sys
from nova import flags
flags.FLAGS(
from nova import log as logging
at the top of every file that may be run from the command line. I find this ugly and fragile. If someone tries to use our code and fails to do these commands, logging will break. Also the flags are modified in various places, including tests, and nova-api after loading the paste.deploy conf.
An alternative to the initialized attribute is to cache the values of the relevant logging flags, and just check them for changes each time we log. I'm a little concerned about the performance of this option, especially for the default_log_levels flag which is a list and potentially expensive to check for changes every time we want to write a log message.
Perhaps the best option would be to put a logging_setup() in the end of flags.call(), so it will reset the logging conf after loading flags.
Vish Ishaya (vishvananda) wrote : | # |
Ok I switched it to the Final option above. To reset the logging config because the flags have changed, there is a logging.reset() method.
I'm calling the method automatically at the end of flag parsing, but if this seems too messy, then we can manually add a logging.reset() after each call to FLAGS(sys.argv)
Thierry Carrez (ttx) wrote : | # |
This is currently not fixing bug 721285.
Calling logging.reset() does not actually reset the logging level for instances of NovaLogger based on --verbose flag, since NovaLogger.
Todd Willey (xtoddx) wrote : | # |
You can wipe out all references to basicConfig in the log module. All the logging.basicConfig call does is set up handlers for the root logger if they don't exist yet. Since NovaRootLogger will always have handlers, it becomes a no-op without having to re-define it. So you can remove
* The definition of basicConfig
* Setting the logging.basicConfig function
* The check in the top-level audit() function that calls basicConfig
By returning on the first call to 'error' in the NovaLogger.
You should set the "nova" value of loggerDict to be the root logger as well, otherwise you'll get a new instance when you call logging.
Instead of checking the class of loggers in the 'reset' function, you should probably check if they have a 'setup_from_flags' function, since it allows better duck-typing. It would also keep you from making the explicit call to the root logger.
I'd also vote for keeping the call to reset() away from the flags library, and put in in the binaries immediately after they call FLAGS(). Also, nova-api is changing soon so that it doesn't mangle flags (ttx has a branch).
Todd Willey (xtoddx) wrote : | # |
To address TTX's point, I think both the root logger and NovaLogger instances should look at both --verbose and --default_
Vish Ishaya (vishvananda) wrote : | # |
> This is currently not fixing bug 721285.
>
> Calling logging.reset() does not actually reset the logging level for
> instances of NovaLogger based on --verbose flag, since
> NovaLogger.
> NovaLogger should probably setLevel based on the contents of --verbose like
> NovaRootLogger does.
If a logger is explicitly set to a value, verbose should have no affect on it. If a logger has the value NOTSET, the root logger will pick it up and log it according to its own verbosity, so we don't need to set the individual loggers separately. That said, if the flags change to remove default_log_levels, then the reset will not pick it up, so I'll set it back to notset in that case.
Vish Ishaya (vishvananda) wrote : | # |
> You can wipe out all references to basicConfig in the log module. All the
> logging.basicConfig call does is set up handlers for the root logger if they
> don't exist yet. Since NovaRootLogger will always have handlers, it becomes a
> no-op without having to re-define it. So you can remove
> * The definition of basicConfig
> * Setting the logging.basicConfig function
> * The check in the top-level audit() function that calls basicConfig
done.
>
> By returning on the first call to 'error' in the NovaLogger.
> stop environment dumps.
good catch
>
> You should set the "nova" value of loggerDict to be the root logger as well,
> otherwise you'll get a new instance when you call logging.
> It will require fixing the parent links in other loggers, and possibly using
> the same locking mechanics (see logging). That will also let the loop in
> reset find the root logger.
Good call.
>
> Instead of checking the class of loggers in the 'reset' function, you should
> probably check if they have a 'setup_from_flags' function, since it allows
> better duck-typing. It would also keep you from making the explicit call to
> the root logger.
The explicit call was fixed by above. Not sure that i see the value of duck-typing here.
>
> I'd also vote for keeping the call to reset() away from the flags library, and
> put in in the binaries immediately after they call FLAGS(). Also, nova-api is
> changing soon so that it doesn't mangle flags (ttx has a branch).
I'm ok with this although i find it annoying that we have to put this code in multiple places. Perhaps a utils.py function called parse_flags that does both?
Todd Willey (xtoddx) wrote : | # |
I'd be good with with a method in utils that does both flag parsing & log reset.
Vish Ishaya (vishvananda) wrote : | # |
As per Todd and termie's suggestions, I put in an explicit logging.setup after each call to FLAGS(). I also put the flag parsing directly into the bin files as this is a bit more explicit. As it is now, logging doesn't do anything on import except for override the type of the default logger. Everything else happens in .setup()
termie (termie) wrote : | # |
594: extra newline was added
860: necessary newline was removed
It'd be nice to have the modifications to fake_flags.py "tests.log" and "tests.sqlite" be taken out of this patch.
termie (termie) wrote : | # |
(as well as the removal of the db in run_tests.py)
- 723. By Vish Ishaya
-
remove changes to test db
termie (termie) wrote : | # |
those numbers are now 585 and 848...
Vish Ishaya (vishvananda) wrote : | # |
> those numbers are now 585 and 848...
fixed
- 724. By Vish Ishaya
-
fixed newline and moved import fake_flags into run_tests where it makes more sense
Thierry Carrez (ttx) wrote : | # |
Tested & fixes bug 721285 alright now !
Preview Diff
1 | === modified file 'bin/nova-ajax-console-proxy' | |||
2 | --- bin/nova-ajax-console-proxy 2011-01-10 21:44:45 +0000 | |||
3 | +++ bin/nova-ajax-console-proxy 2011-02-22 00:22:48 +0000 | |||
4 | @@ -25,7 +25,6 @@ | |||
5 | 25 | 25 | ||
6 | 26 | import exceptions | 26 | import exceptions |
7 | 27 | import gettext | 27 | import gettext |
8 | 28 | import logging | ||
9 | 29 | import os | 28 | import os |
10 | 30 | import sys | 29 | import sys |
11 | 31 | import time | 30 | import time |
12 | @@ -130,6 +129,7 @@ | |||
13 | 130 | if __name__ == '__main__': | 129 | if __name__ == '__main__': |
14 | 131 | utils.default_flagfile() | 130 | utils.default_flagfile() |
15 | 132 | FLAGS(sys.argv) | 131 | FLAGS(sys.argv) |
16 | 132 | logging.setup() | ||
17 | 133 | server = wsgi.Server() | 133 | server = wsgi.Server() |
18 | 134 | acp = AjaxConsoleProxy() | 134 | acp = AjaxConsoleProxy() |
19 | 135 | acp.register_listeners() | 135 | acp.register_listeners() |
20 | 136 | 136 | ||
21 | === modified file 'bin/nova-api' | |||
22 | --- bin/nova-api 2011-01-21 21:10:26 +0000 | |||
23 | +++ bin/nova-api 2011-02-22 00:22:48 +0000 | |||
24 | @@ -39,9 +39,7 @@ | |||
25 | 39 | from nova import version | 39 | from nova import version |
26 | 40 | from nova import wsgi | 40 | from nova import wsgi |
27 | 41 | 41 | ||
28 | 42 | logging.basicConfig() | ||
29 | 43 | LOG = logging.getLogger('nova.api') | 42 | LOG = logging.getLogger('nova.api') |
30 | 44 | LOG.setLevel(logging.DEBUG) | ||
31 | 45 | 43 | ||
32 | 46 | FLAGS = flags.FLAGS | 44 | FLAGS = flags.FLAGS |
33 | 47 | 45 | ||
34 | @@ -71,7 +69,8 @@ | |||
35 | 71 | return | 69 | return |
36 | 72 | 70 | ||
37 | 73 | # NOTE(todd): redo logging config, verbose could be set in paste config | 71 | # NOTE(todd): redo logging config, verbose could be set in paste config |
39 | 74 | logging.basicConfig() | 72 | logging.reset() |
40 | 73 | |||
41 | 75 | server = wsgi.Server() | 74 | server = wsgi.Server() |
42 | 76 | for app in apps: | 75 | for app in apps: |
43 | 77 | server.start(*app) | 76 | server.start(*app) |
44 | @@ -80,6 +79,7 @@ | |||
45 | 80 | 79 | ||
46 | 81 | if __name__ == '__main__': | 80 | if __name__ == '__main__': |
47 | 82 | FLAGS(sys.argv) | 81 | FLAGS(sys.argv) |
48 | 82 | logging.setup() | ||
49 | 83 | LOG.audit(_("Starting nova-api node (version %s)"), | 83 | LOG.audit(_("Starting nova-api node (version %s)"), |
50 | 84 | version.version_string_with_vcs()) | 84 | version.version_string_with_vcs()) |
51 | 85 | conf = wsgi.paste_config_file('nova-api.conf') | 85 | conf = wsgi.paste_config_file('nova-api.conf') |
52 | 86 | 86 | ||
53 | === modified file 'bin/nova-combined' | |||
54 | --- bin/nova-combined 2011-02-15 00:11:29 +0000 | |||
55 | +++ bin/nova-combined 2011-02-22 00:22:48 +0000 | |||
56 | @@ -49,7 +49,7 @@ | |||
57 | 49 | if __name__ == '__main__': | 49 | if __name__ == '__main__': |
58 | 50 | utils.default_flagfile() | 50 | utils.default_flagfile() |
59 | 51 | FLAGS(sys.argv) | 51 | FLAGS(sys.argv) |
61 | 52 | logging.basicConfig() | 52 | logging.setup() |
62 | 53 | 53 | ||
63 | 54 | compute = service.Service.create(binary='nova-compute') | 54 | compute = service.Service.create(binary='nova-compute') |
64 | 55 | network = service.Service.create(binary='nova-network') | 55 | network = service.Service.create(binary='nova-network') |
65 | @@ -73,7 +73,6 @@ | |||
66 | 73 | apps.append((app, getattr(FLAGS, "%s_port" % api), | 73 | apps.append((app, getattr(FLAGS, "%s_port" % api), |
67 | 74 | getattr(FLAGS, "%s_host" % api))) | 74 | getattr(FLAGS, "%s_host" % api))) |
68 | 75 | if len(apps) > 0: | 75 | if len(apps) > 0: |
69 | 76 | logging.basicConfig() | ||
70 | 77 | server = wsgi.Server() | 76 | server = wsgi.Server() |
71 | 78 | for app in apps: | 77 | for app in apps: |
72 | 79 | server.start(*app) | 78 | server.start(*app) |
73 | 80 | 79 | ||
74 | === modified file 'bin/nova-compute' | |||
75 | --- bin/nova-compute 2010-12-15 19:02:33 +0000 | |||
76 | +++ bin/nova-compute 2011-02-22 00:22:48 +0000 | |||
77 | @@ -36,10 +36,14 @@ | |||
78 | 36 | 36 | ||
79 | 37 | gettext.install('nova', unicode=1) | 37 | gettext.install('nova', unicode=1) |
80 | 38 | 38 | ||
81 | 39 | from nova import flags | ||
82 | 40 | from nova import log as logging | ||
83 | 39 | from nova import service | 41 | from nova import service |
84 | 40 | from nova import utils | 42 | from nova import utils |
85 | 41 | 43 | ||
86 | 42 | if __name__ == '__main__': | 44 | if __name__ == '__main__': |
87 | 43 | utils.default_flagfile() | 45 | utils.default_flagfile() |
88 | 46 | flags.FLAGS(sys.argv) | ||
89 | 47 | logging.setup() | ||
90 | 44 | service.serve() | 48 | service.serve() |
91 | 45 | service.wait() | 49 | service.wait() |
92 | 46 | 50 | ||
93 | === modified file 'bin/nova-console' | |||
94 | --- bin/nova-console 2011-01-05 20:16:14 +0000 | |||
95 | +++ bin/nova-console 2011-02-22 00:22:48 +0000 | |||
96 | @@ -35,10 +35,14 @@ | |||
97 | 35 | 35 | ||
98 | 36 | gettext.install('nova', unicode=1) | 36 | gettext.install('nova', unicode=1) |
99 | 37 | 37 | ||
100 | 38 | from nova import flags | ||
101 | 39 | from nova import log as logging | ||
102 | 38 | from nova import service | 40 | from nova import service |
103 | 39 | from nova import utils | 41 | from nova import utils |
104 | 40 | 42 | ||
105 | 41 | if __name__ == '__main__': | 43 | if __name__ == '__main__': |
106 | 42 | utils.default_flagfile() | 44 | utils.default_flagfile() |
107 | 45 | flags.FLAGS(sys.argv) | ||
108 | 46 | logging.setup() | ||
109 | 43 | service.serve() | 47 | service.serve() |
110 | 44 | service.wait() | 48 | service.wait() |
111 | 45 | 49 | ||
112 | === modified file 'bin/nova-dhcpbridge' | |||
113 | --- bin/nova-dhcpbridge 2011-01-24 15:19:51 +0000 | |||
114 | +++ bin/nova-dhcpbridge 2011-02-22 00:22:48 +0000 | |||
115 | @@ -102,7 +102,7 @@ | |||
116 | 102 | flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile) | 102 | flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile) |
117 | 103 | utils.default_flagfile(flagfile) | 103 | utils.default_flagfile(flagfile) |
118 | 104 | argv = FLAGS(sys.argv) | 104 | argv = FLAGS(sys.argv) |
120 | 105 | logging.basicConfig() | 105 | logging.setup() |
121 | 106 | interface = os.environ.get('DNSMASQ_INTERFACE', 'br0') | 106 | interface = os.environ.get('DNSMASQ_INTERFACE', 'br0') |
122 | 107 | if int(os.environ.get('TESTING', '0')): | 107 | if int(os.environ.get('TESTING', '0')): |
123 | 108 | FLAGS.fake_rabbit = True | 108 | FLAGS.fake_rabbit = True |
124 | 109 | 109 | ||
125 | === modified file 'bin/nova-direct-api' | |||
126 | --- bin/nova-direct-api 2011-01-18 13:48:50 +0000 | |||
127 | +++ bin/nova-direct-api 2011-02-22 00:22:48 +0000 | |||
128 | @@ -35,6 +35,7 @@ | |||
129 | 35 | gettext.install('nova', unicode=1) | 35 | gettext.install('nova', unicode=1) |
130 | 36 | 36 | ||
131 | 37 | from nova import flags | 37 | from nova import flags |
132 | 38 | from nova import log as logging | ||
133 | 38 | from nova import utils | 39 | from nova import utils |
134 | 39 | from nova import wsgi | 40 | from nova import wsgi |
135 | 40 | from nova.api import direct | 41 | from nova.api import direct |
136 | @@ -48,6 +49,7 @@ | |||
137 | 48 | if __name__ == '__main__': | 49 | if __name__ == '__main__': |
138 | 49 | utils.default_flagfile() | 50 | utils.default_flagfile() |
139 | 50 | FLAGS(sys.argv) | 51 | FLAGS(sys.argv) |
140 | 52 | logging.setup() | ||
141 | 51 | 53 | ||
142 | 52 | direct.register_service('compute', compute_api.API()) | 54 | direct.register_service('compute', compute_api.API()) |
143 | 53 | direct.register_service('reflect', direct.Reflection()) | 55 | direct.register_service('reflect', direct.Reflection()) |
144 | 54 | 56 | ||
145 | === modified file 'bin/nova-import-canonical-imagestore' | |||
146 | --- bin/nova-import-canonical-imagestore 2010-12-14 23:22:03 +0000 | |||
147 | +++ bin/nova-import-canonical-imagestore 2011-02-22 00:22:48 +0000 | |||
148 | @@ -41,6 +41,7 @@ | |||
149 | 41 | gettext.install('nova', unicode=1) | 41 | gettext.install('nova', unicode=1) |
150 | 42 | 42 | ||
151 | 43 | from nova import flags | 43 | from nova import flags |
152 | 44 | from nova import log as logging | ||
153 | 44 | from nova import utils | 45 | from nova import utils |
154 | 45 | from nova.objectstore import image | 46 | from nova.objectstore import image |
155 | 46 | 47 | ||
156 | @@ -92,6 +93,7 @@ | |||
157 | 92 | """Main entry point.""" | 93 | """Main entry point.""" |
158 | 93 | utils.default_flagfile() | 94 | utils.default_flagfile() |
159 | 94 | argv = FLAGS(sys.argv) | 95 | argv = FLAGS(sys.argv) |
160 | 96 | logging.setup() | ||
161 | 95 | images = get_images() | 97 | images = get_images() |
162 | 96 | 98 | ||
163 | 97 | if len(argv) == 2: | 99 | if len(argv) == 2: |
164 | 98 | 100 | ||
165 | === modified file 'bin/nova-instancemonitor' | |||
166 | --- bin/nova-instancemonitor 2011-01-04 05:26:41 +0000 | |||
167 | +++ bin/nova-instancemonitor 2011-02-22 00:22:48 +0000 | |||
168 | @@ -41,9 +41,6 @@ | |||
169 | 41 | from nova import twistd | 41 | from nova import twistd |
170 | 42 | from nova.compute import monitor | 42 | from nova.compute import monitor |
171 | 43 | 43 | ||
172 | 44 | # TODO(todd): shouldn't this be done with flags? And what about verbose? | ||
173 | 45 | logging.getLogger('boto').setLevel(logging.WARN) | ||
174 | 46 | |||
175 | 47 | LOG = logging.getLogger('nova.instancemonitor') | 44 | LOG = logging.getLogger('nova.instancemonitor') |
176 | 48 | 45 | ||
177 | 49 | 46 | ||
178 | 50 | 47 | ||
179 | === modified file 'bin/nova-manage' | |||
180 | --- bin/nova-manage 2011-02-17 21:39:03 +0000 | |||
181 | +++ bin/nova-manage 2011-02-22 00:22:48 +0000 | |||
182 | @@ -86,8 +86,6 @@ | |||
183 | 86 | from nova.cloudpipe import pipelib | 86 | from nova.cloudpipe import pipelib |
184 | 87 | from nova.db import migration | 87 | from nova.db import migration |
185 | 88 | 88 | ||
186 | 89 | |||
187 | 90 | logging.basicConfig() | ||
188 | 91 | FLAGS = flags.FLAGS | 89 | FLAGS = flags.FLAGS |
189 | 92 | flags.DECLARE('fixed_range', 'nova.network.manager') | 90 | flags.DECLARE('fixed_range', 'nova.network.manager') |
190 | 93 | flags.DECLARE('num_networks', 'nova.network.manager') | 91 | flags.DECLARE('num_networks', 'nova.network.manager') |
191 | @@ -710,6 +708,7 @@ | |||
192 | 710 | """Parse options and call the appropriate class/method.""" | 708 | """Parse options and call the appropriate class/method.""" |
193 | 711 | utils.default_flagfile() | 709 | utils.default_flagfile() |
194 | 712 | argv = FLAGS(sys.argv) | 710 | argv = FLAGS(sys.argv) |
195 | 711 | logging.setup() | ||
196 | 713 | 712 | ||
197 | 714 | script_name = argv.pop(0) | 713 | script_name = argv.pop(0) |
198 | 715 | if len(argv) < 1: | 714 | if len(argv) < 1: |
199 | 716 | 715 | ||
200 | === modified file 'bin/nova-network' | |||
201 | --- bin/nova-network 2010-12-15 19:02:33 +0000 | |||
202 | +++ bin/nova-network 2011-02-22 00:22:48 +0000 | |||
203 | @@ -36,10 +36,14 @@ | |||
204 | 36 | 36 | ||
205 | 37 | gettext.install('nova', unicode=1) | 37 | gettext.install('nova', unicode=1) |
206 | 38 | 38 | ||
207 | 39 | from nova import flags | ||
208 | 40 | from nova import log as logging | ||
209 | 39 | from nova import service | 41 | from nova import service |
210 | 40 | from nova import utils | 42 | from nova import utils |
211 | 41 | 43 | ||
212 | 42 | if __name__ == '__main__': | 44 | if __name__ == '__main__': |
213 | 43 | utils.default_flagfile() | 45 | utils.default_flagfile() |
214 | 46 | flags.FLAGS(sys.argv) | ||
215 | 47 | logging.setup() | ||
216 | 44 | service.serve() | 48 | service.serve() |
217 | 45 | service.wait() | 49 | service.wait() |
218 | 46 | 50 | ||
219 | === modified file 'bin/nova-scheduler' | |||
220 | --- bin/nova-scheduler 2010-12-15 19:02:33 +0000 | |||
221 | +++ bin/nova-scheduler 2011-02-22 00:22:48 +0000 | |||
222 | @@ -36,10 +36,14 @@ | |||
223 | 36 | 36 | ||
224 | 37 | gettext.install('nova', unicode=1) | 37 | gettext.install('nova', unicode=1) |
225 | 38 | 38 | ||
226 | 39 | from nova import flags | ||
227 | 40 | from nova import log as logging | ||
228 | 39 | from nova import service | 41 | from nova import service |
229 | 40 | from nova import utils | 42 | from nova import utils |
230 | 41 | 43 | ||
231 | 42 | if __name__ == '__main__': | 44 | if __name__ == '__main__': |
232 | 43 | utils.default_flagfile() | 45 | utils.default_flagfile() |
233 | 46 | flags.FLAGS(sys.argv) | ||
234 | 47 | logging.setup() | ||
235 | 44 | service.serve() | 48 | service.serve() |
236 | 45 | service.wait() | 49 | service.wait() |
237 | 46 | 50 | ||
238 | === modified file 'bin/nova-volume' | |||
239 | --- bin/nova-volume 2010-12-15 19:02:33 +0000 | |||
240 | +++ bin/nova-volume 2011-02-22 00:22:48 +0000 | |||
241 | @@ -36,10 +36,14 @@ | |||
242 | 36 | 36 | ||
243 | 37 | gettext.install('nova', unicode=1) | 37 | gettext.install('nova', unicode=1) |
244 | 38 | 38 | ||
245 | 39 | from nova import flags | ||
246 | 40 | from nova import log as logging | ||
247 | 39 | from nova import service | 41 | from nova import service |
248 | 40 | from nova import utils | 42 | from nova import utils |
249 | 41 | 43 | ||
250 | 42 | if __name__ == '__main__': | 44 | if __name__ == '__main__': |
251 | 43 | utils.default_flagfile() | 45 | utils.default_flagfile() |
252 | 46 | flags.FLAGS(sys.argv) | ||
253 | 47 | logging.setup() | ||
254 | 44 | service.serve() | 48 | service.serve() |
255 | 45 | service.wait() | 49 | service.wait() |
256 | 46 | 50 | ||
257 | === modified file 'nova/api/openstack/auth.py' | |||
258 | --- nova/api/openstack/auth.py 2011-02-18 22:35:12 +0000 | |||
259 | +++ nova/api/openstack/auth.py 2011-02-22 00:22:48 +0000 | |||
260 | @@ -19,7 +19,6 @@ | |||
261 | 19 | import hashlib | 19 | import hashlib |
262 | 20 | import json | 20 | import json |
263 | 21 | import time | 21 | import time |
264 | 22 | import logging | ||
265 | 23 | 22 | ||
266 | 24 | import webob.exc | 23 | import webob.exc |
267 | 25 | import webob.dec | 24 | import webob.dec |
268 | 26 | 25 | ||
269 | === modified file 'nova/api/openstack/backup_schedules.py' | |||
270 | --- nova/api/openstack/backup_schedules.py 2011-01-03 23:46:55 +0000 | |||
271 | +++ nova/api/openstack/backup_schedules.py 2011-02-22 00:22:48 +0000 | |||
272 | @@ -15,7 +15,6 @@ | |||
273 | 15 | # License for the specific language governing permissions and limitations | 15 | # License for the specific language governing permissions and limitations |
274 | 16 | # under the License. | 16 | # under the License. |
275 | 17 | 17 | ||
276 | 18 | import logging | ||
277 | 19 | import time | 18 | import time |
278 | 20 | 19 | ||
279 | 21 | from webob import exc | 20 | from webob import exc |
280 | 22 | 21 | ||
281 | === modified file 'nova/api/openstack/images.py' | |||
282 | --- nova/api/openstack/images.py 2011-01-13 19:48:01 +0000 | |||
283 | +++ nova/api/openstack/images.py 2011-02-22 00:22:48 +0000 | |||
284 | @@ -15,8 +15,6 @@ | |||
285 | 15 | # License for the specific language governing permissions and limitations | 15 | # License for the specific language governing permissions and limitations |
286 | 16 | # under the License. | 16 | # under the License. |
287 | 17 | 17 | ||
288 | 18 | import logging | ||
289 | 19 | |||
290 | 20 | from webob import exc | 18 | from webob import exc |
291 | 21 | 19 | ||
292 | 22 | from nova import compute | 20 | from nova import compute |
293 | 23 | 21 | ||
294 | === modified file 'nova/api/openstack/servers.py' | |||
295 | --- nova/api/openstack/servers.py 2011-02-18 22:36:01 +0000 | |||
296 | +++ nova/api/openstack/servers.py 2011-02-22 00:22:48 +0000 | |||
297 | @@ -33,7 +33,6 @@ | |||
298 | 33 | 33 | ||
299 | 34 | 34 | ||
300 | 35 | LOG = logging.getLogger('server') | 35 | LOG = logging.getLogger('server') |
301 | 36 | LOG.setLevel(logging.DEBUG) | ||
302 | 37 | 36 | ||
303 | 38 | 37 | ||
304 | 39 | FLAGS = flags.FLAGS | 38 | FLAGS = flags.FLAGS |
305 | 40 | 39 | ||
306 | === modified file 'nova/api/openstack/shared_ip_groups.py' | |||
307 | --- nova/api/openstack/shared_ip_groups.py 2011-01-11 07:38:40 +0000 | |||
308 | +++ nova/api/openstack/shared_ip_groups.py 2011-02-22 00:22:48 +0000 | |||
309 | @@ -15,8 +15,6 @@ | |||
310 | 15 | # License for the specific language governing permissions and limitations | 15 | # License for the specific language governing permissions and limitations |
311 | 16 | # under the License. | 16 | # under the License. |
312 | 17 | 17 | ||
313 | 18 | import logging | ||
314 | 19 | |||
315 | 20 | from webob import exc | 18 | from webob import exc |
316 | 21 | 19 | ||
317 | 22 | from nova import wsgi | 20 | from nova import wsgi |
318 | 23 | 21 | ||
319 | === modified file 'nova/api/openstack/zones.py' | |||
320 | --- nova/api/openstack/zones.py 2011-02-15 03:02:26 +0000 | |||
321 | +++ nova/api/openstack/zones.py 2011-02-22 00:22:48 +0000 | |||
322 | @@ -14,7 +14,6 @@ | |||
323 | 14 | # under the License. | 14 | # under the License. |
324 | 15 | 15 | ||
325 | 16 | import common | 16 | import common |
326 | 17 | import logging | ||
327 | 18 | 17 | ||
328 | 19 | from nova import flags | 18 | from nova import flags |
329 | 20 | from nova import wsgi | 19 | from nova import wsgi |
330 | 21 | 20 | ||
331 | === modified file 'nova/console/manager.py' | |||
332 | --- nova/console/manager.py 2011-01-20 17:52:02 +0000 | |||
333 | +++ nova/console/manager.py 2011-02-22 00:22:48 +0000 | |||
334 | @@ -20,11 +20,11 @@ | |||
335 | 20 | """ | 20 | """ |
336 | 21 | 21 | ||
337 | 22 | import functools | 22 | import functools |
338 | 23 | import logging | ||
339 | 24 | import socket | 23 | import socket |
340 | 25 | 24 | ||
341 | 26 | from nova import exception | 25 | from nova import exception |
342 | 27 | from nova import flags | 26 | from nova import flags |
343 | 27 | from nova import log as logging | ||
344 | 28 | from nova import manager | 28 | from nova import manager |
345 | 29 | from nova import rpc | 29 | from nova import rpc |
346 | 30 | from nova import utils | 30 | from nova import utils |
347 | 31 | 31 | ||
348 | === modified file 'nova/console/xvp.py' | |||
349 | --- nova/console/xvp.py 2011-01-20 17:52:02 +0000 | |||
350 | +++ nova/console/xvp.py 2011-02-22 00:22:48 +0000 | |||
351 | @@ -20,7 +20,6 @@ | |||
352 | 20 | """ | 20 | """ |
353 | 21 | 21 | ||
354 | 22 | import fcntl | 22 | import fcntl |
355 | 23 | import logging | ||
356 | 24 | import os | 23 | import os |
357 | 25 | import signal | 24 | import signal |
358 | 26 | import subprocess | 25 | import subprocess |
359 | @@ -31,6 +30,7 @@ | |||
360 | 31 | from nova import db | 30 | from nova import db |
361 | 32 | from nova import exception | 31 | from nova import exception |
362 | 33 | from nova import flags | 32 | from nova import flags |
363 | 33 | from nova import log as logging | ||
364 | 34 | from nova import utils | 34 | from nova import utils |
365 | 35 | 35 | ||
366 | 36 | flags.DEFINE_string('console_xvp_conf_template', | 36 | flags.DEFINE_string('console_xvp_conf_template', |
367 | 37 | 37 | ||
368 | === modified file 'nova/log.py' | |||
369 | --- nova/log.py 2011-02-18 09:24:55 +0000 | |||
370 | +++ nova/log.py 2011-02-22 00:22:48 +0000 | |||
371 | @@ -65,6 +65,7 @@ | |||
372 | 65 | flags.DEFINE_list('default_log_levels', | 65 | flags.DEFINE_list('default_log_levels', |
373 | 66 | ['amqplib=WARN', | 66 | ['amqplib=WARN', |
374 | 67 | 'sqlalchemy=WARN', | 67 | 'sqlalchemy=WARN', |
375 | 68 | 'boto=WARN', | ||
376 | 68 | 'eventlet.wsgi.server=WARN'], | 69 | 'eventlet.wsgi.server=WARN'], |
377 | 69 | 'list of logger=LEVEL pairs') | 70 | 'list of logger=LEVEL pairs') |
378 | 70 | 71 | ||
379 | @@ -117,7 +118,7 @@ | |||
380 | 117 | return os.path.basename(inspect.stack()[-1][1]) | 118 | return os.path.basename(inspect.stack()[-1][1]) |
381 | 118 | 119 | ||
382 | 119 | 120 | ||
384 | 120 | def get_log_file_path(binary=None): | 121 | def _get_log_file_path(binary=None): |
385 | 121 | if FLAGS.logfile: | 122 | if FLAGS.logfile: |
386 | 122 | return FLAGS.logfile | 123 | return FLAGS.logfile |
387 | 123 | if FLAGS.logdir: | 124 | if FLAGS.logdir: |
388 | @@ -125,25 +126,6 @@ | |||
389 | 125 | return '%s.log' % (os.path.join(FLAGS.logdir, binary),) | 126 | return '%s.log' % (os.path.join(FLAGS.logdir, binary),) |
390 | 126 | 127 | ||
391 | 127 | 128 | ||
392 | 128 | def basicConfig(): | ||
393 | 129 | logging.basicConfig() | ||
394 | 130 | for handler in logging.root.handlers: | ||
395 | 131 | handler.setFormatter(_formatter) | ||
396 | 132 | if FLAGS.verbose: | ||
397 | 133 | logging.root.setLevel(logging.DEBUG) | ||
398 | 134 | else: | ||
399 | 135 | logging.root.setLevel(logging.INFO) | ||
400 | 136 | if FLAGS.use_syslog: | ||
401 | 137 | syslog = SysLogHandler(address='/dev/log') | ||
402 | 138 | syslog.setFormatter(_formatter) | ||
403 | 139 | logging.root.addHandler(syslog) | ||
404 | 140 | logpath = get_log_file_path() | ||
405 | 141 | if logpath: | ||
406 | 142 | logfile = WatchedFileHandler(logpath) | ||
407 | 143 | logfile.setFormatter(_formatter) | ||
408 | 144 | logging.root.addHandler(logfile) | ||
409 | 145 | |||
410 | 146 | |||
411 | 147 | class NovaLogger(logging.Logger): | 129 | class NovaLogger(logging.Logger): |
412 | 148 | """ | 130 | """ |
413 | 149 | NovaLogger manages request context and formatting. | 131 | NovaLogger manages request context and formatting. |
414 | @@ -151,23 +133,19 @@ | |||
415 | 151 | This becomes the class that is instanciated by logging.getLogger. | 133 | This becomes the class that is instanciated by logging.getLogger. |
416 | 152 | """ | 134 | """ |
417 | 153 | def __init__(self, name, level=NOTSET): | 135 | def __init__(self, name, level=NOTSET): |
418 | 154 | level_name = self._get_level_from_flags(name, FLAGS) | ||
419 | 155 | level = globals()[level_name] | ||
420 | 156 | logging.Logger.__init__(self, name, level) | 136 | logging.Logger.__init__(self, name, level) |
421 | 137 | self.setup_from_flags() | ||
422 | 157 | 138 | ||
427 | 158 | def _get_level_from_flags(self, name, FLAGS): | 139 | def setup_from_flags(self): |
428 | 159 | # if exactly "nova", or a child logger, honor the verbose flag | 140 | """Setup logger from flags""" |
429 | 160 | if (name == "nova" or name.startswith("nova.")) and FLAGS.verbose: | 141 | level = NOTSET |
426 | 161 | return 'DEBUG' | ||
430 | 162 | for pair in FLAGS.default_log_levels: | 142 | for pair in FLAGS.default_log_levels: |
432 | 163 | logger, _sep, level = pair.partition('=') | 143 | logger, _sep, level_name = pair.partition('=') |
433 | 164 | # NOTE(todd): if we set a.b, we want a.b.c to have the same level | 144 | # NOTE(todd): if we set a.b, we want a.b.c to have the same level |
434 | 165 | # (but not a.bc, so we check the dot) | 145 | # (but not a.bc, so we check the dot) |
440 | 166 | if name == logger: | 146 | if self.name == logger or self.name.startswith("%s." % logger): |
441 | 167 | return level | 147 | level = globals()[level_name] |
442 | 168 | if name.startswith(logger) and name[len(logger)] == '.': | 148 | self.setLevel(level) |
438 | 169 | return level | ||
439 | 170 | return 'INFO' | ||
443 | 171 | 149 | ||
444 | 172 | def _log(self, level, msg, args, exc_info=None, extra=None, context=None): | 150 | def _log(self, level, msg, args, exc_info=None, extra=None, context=None): |
445 | 173 | """Extract context from any log call""" | 151 | """Extract context from any log call""" |
446 | @@ -176,12 +154,12 @@ | |||
447 | 176 | if context: | 154 | if context: |
448 | 177 | extra.update(_dictify_context(context)) | 155 | extra.update(_dictify_context(context)) |
449 | 178 | extra.update({"nova_version": version.version_string_with_vcs()}) | 156 | extra.update({"nova_version": version.version_string_with_vcs()}) |
451 | 179 | logging.Logger._log(self, level, msg, args, exc_info, extra) | 157 | return logging.Logger._log(self, level, msg, args, exc_info, extra) |
452 | 180 | 158 | ||
453 | 181 | def addHandler(self, handler): | 159 | def addHandler(self, handler): |
454 | 182 | """Each handler gets our custom formatter""" | 160 | """Each handler gets our custom formatter""" |
455 | 183 | handler.setFormatter(_formatter) | 161 | handler.setFormatter(_formatter) |
457 | 184 | logging.Logger.addHandler(self, handler) | 162 | return logging.Logger.addHandler(self, handler) |
458 | 185 | 163 | ||
459 | 186 | def audit(self, msg, *args, **kwargs): | 164 | def audit(self, msg, *args, **kwargs): |
460 | 187 | """Shortcut for our AUDIT level""" | 165 | """Shortcut for our AUDIT level""" |
461 | @@ -208,23 +186,6 @@ | |||
462 | 208 | self.error(message, **kwargs) | 186 | self.error(message, **kwargs) |
463 | 209 | 187 | ||
464 | 210 | 188 | ||
465 | 211 | def handle_exception(type, value, tb): | ||
466 | 212 | logging.root.critical(str(value), exc_info=(type, value, tb)) | ||
467 | 213 | |||
468 | 214 | |||
469 | 215 | sys.excepthook = handle_exception | ||
470 | 216 | logging.setLoggerClass(NovaLogger) | ||
471 | 217 | |||
472 | 218 | |||
473 | 219 | class NovaRootLogger(NovaLogger): | ||
474 | 220 | pass | ||
475 | 221 | |||
476 | 222 | if not isinstance(logging.root, NovaRootLogger): | ||
477 | 223 | logging.root = NovaRootLogger("nova.root", WARNING) | ||
478 | 224 | NovaLogger.root = logging.root | ||
479 | 225 | NovaLogger.manager.root = logging.root | ||
480 | 226 | |||
481 | 227 | |||
482 | 228 | class NovaFormatter(logging.Formatter): | 189 | class NovaFormatter(logging.Formatter): |
483 | 229 | """ | 190 | """ |
484 | 230 | A nova.context.RequestContext aware formatter configured through flags. | 191 | A nova.context.RequestContext aware formatter configured through flags. |
485 | @@ -271,8 +232,72 @@ | |||
486 | 271 | _formatter = NovaFormatter() | 232 | _formatter = NovaFormatter() |
487 | 272 | 233 | ||
488 | 273 | 234 | ||
489 | 235 | class NovaRootLogger(NovaLogger): | ||
490 | 236 | def __init__(self, name, level=NOTSET): | ||
491 | 237 | self.logpath = None | ||
492 | 238 | self.filelog = None | ||
493 | 239 | self.syslog = SysLogHandler(address='/dev/log') | ||
494 | 240 | self.streamlog = StreamHandler() | ||
495 | 241 | NovaLogger.__init__(self, name, level) | ||
496 | 242 | |||
497 | 243 | def setup_from_flags(self): | ||
498 | 244 | """Setup logger from flags""" | ||
499 | 245 | global _filelog | ||
500 | 246 | if FLAGS.use_syslog: | ||
501 | 247 | self.addHandler(self.syslog) | ||
502 | 248 | else: | ||
503 | 249 | self.removeHandler(self.syslog) | ||
504 | 250 | logpath = _get_log_file_path() | ||
505 | 251 | if logpath: | ||
506 | 252 | self.removeHandler(self.streamlog) | ||
507 | 253 | if logpath != self.logpath: | ||
508 | 254 | self.removeHandler(self.filelog) | ||
509 | 255 | self.filelog = WatchedFileHandler(logpath) | ||
510 | 256 | self.addHandler(self.filelog) | ||
511 | 257 | self.logpath = logpath | ||
512 | 258 | else: | ||
513 | 259 | self.removeHandler(self.filelog) | ||
514 | 260 | self.addHandler(self.streamlog) | ||
515 | 261 | if FLAGS.verbose: | ||
516 | 262 | self.setLevel(DEBUG) | ||
517 | 263 | else: | ||
518 | 264 | self.setLevel(INFO) | ||
519 | 265 | |||
520 | 266 | |||
521 | 267 | def handle_exception(type, value, tb): | ||
522 | 268 | logging.root.critical(str(value), exc_info=(type, value, tb)) | ||
523 | 269 | |||
524 | 270 | |||
525 | 271 | def reset(): | ||
526 | 272 | """Resets logging handlers. Should be called if FLAGS changes.""" | ||
527 | 273 | for logger in NovaLogger.manager.loggerDict.itervalues(): | ||
528 | 274 | if isinstance(logger, NovaLogger): | ||
529 | 275 | logger.setup_from_flags() | ||
530 | 276 | |||
531 | 277 | |||
532 | 278 | def setup(): | ||
533 | 279 | """Setup nova logging.""" | ||
534 | 280 | if not isinstance(logging.root, NovaRootLogger): | ||
535 | 281 | logging._acquireLock() | ||
536 | 282 | for handler in logging.root.handlers: | ||
537 | 283 | logging.root.removeHandler(handler) | ||
538 | 284 | logging.root = NovaRootLogger("nova") | ||
539 | 285 | NovaLogger.root = logging.root | ||
540 | 286 | NovaLogger.manager.root = logging.root | ||
541 | 287 | for logger in NovaLogger.manager.loggerDict.itervalues(): | ||
542 | 288 | logger.root = logging.root | ||
543 | 289 | if isinstance(logger, logging.Logger): | ||
544 | 290 | NovaLogger.manager._fixupParents(logger) | ||
545 | 291 | NovaLogger.manager.loggerDict["nova"] = logging.root | ||
546 | 292 | logging._releaseLock() | ||
547 | 293 | sys.excepthook = handle_exception | ||
548 | 294 | reset() | ||
549 | 295 | |||
550 | 296 | |||
551 | 297 | root = logging.root | ||
552 | 298 | logging.setLoggerClass(NovaLogger) | ||
553 | 299 | |||
554 | 300 | |||
555 | 274 | def audit(msg, *args, **kwargs): | 301 | def audit(msg, *args, **kwargs): |
556 | 275 | """Shortcut for logging to root log with sevrity 'AUDIT'.""" | 302 | """Shortcut for logging to root log with sevrity 'AUDIT'.""" |
557 | 276 | if len(logging.root.handlers) == 0: | ||
558 | 277 | basicConfig() | ||
559 | 278 | logging.root.log(AUDIT, msg, *args, **kwargs) | 303 | logging.root.log(AUDIT, msg, *args, **kwargs) |
560 | 279 | 304 | ||
561 | === modified file 'nova/service.py' | |||
562 | --- nova/service.py 2011-01-27 19:52:10 +0000 | |||
563 | +++ nova/service.py 2011-02-22 00:22:48 +0000 | |||
564 | @@ -214,9 +214,6 @@ | |||
565 | 214 | 214 | ||
566 | 215 | 215 | ||
567 | 216 | def serve(*services): | 216 | def serve(*services): |
568 | 217 | FLAGS(sys.argv) | ||
569 | 218 | logging.basicConfig() | ||
570 | 219 | |||
571 | 220 | if not services: | 217 | if not services: |
572 | 221 | services = [Service.create()] | 218 | services = [Service.create()] |
573 | 222 | 219 | ||
574 | 223 | 220 | ||
575 | === modified file 'nova/test.py' | |||
576 | --- nova/test.py 2011-01-26 21:58:24 +0000 | |||
577 | +++ nova/test.py 2011-02-22 00:22:48 +0000 | |||
578 | @@ -32,9 +32,9 @@ | |||
579 | 32 | from nova import db | 32 | from nova import db |
580 | 33 | from nova import fakerabbit | 33 | from nova import fakerabbit |
581 | 34 | from nova import flags | 34 | from nova import flags |
582 | 35 | from nova import log as logging | ||
583 | 35 | from nova import rpc | 36 | from nova import rpc |
584 | 36 | from nova.network import manager as network_manager | 37 | from nova.network import manager as network_manager |
585 | 37 | from nova.tests import fake_flags | ||
586 | 38 | 38 | ||
587 | 39 | 39 | ||
588 | 40 | FLAGS = flags.FLAGS | 40 | FLAGS = flags.FLAGS |
589 | 41 | 41 | ||
590 | === modified file 'nova/tests/fake_flags.py' | |||
591 | --- nova/tests/fake_flags.py 2011-01-18 23:39:24 +0000 | |||
592 | +++ nova/tests/fake_flags.py 2011-02-22 00:22:48 +0000 | |||
593 | @@ -41,3 +41,4 @@ | |||
594 | 41 | FLAGS.verbose = True | 41 | FLAGS.verbose = True |
595 | 42 | FLAGS.sql_connection = 'sqlite:///nova.sqlite' | 42 | FLAGS.sql_connection = 'sqlite:///nova.sqlite' |
596 | 43 | FLAGS.use_ipv6 = True | 43 | FLAGS.use_ipv6 = True |
597 | 44 | FLAGS.logfile = 'tests.log' | ||
598 | 44 | 45 | ||
599 | === modified file 'nova/tests/test_auth.py' | |||
600 | --- nova/tests/test_auth.py 2011-01-04 05:23:35 +0000 | |||
601 | +++ nova/tests/test_auth.py 2011-02-22 00:22:48 +0000 | |||
602 | @@ -327,15 +327,6 @@ | |||
603 | 327 | class AuthManagerLdapTestCase(AuthManagerTestCase, test.TestCase): | 327 | class AuthManagerLdapTestCase(AuthManagerTestCase, test.TestCase): |
604 | 328 | auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver' | 328 | auth_driver = 'nova.auth.ldapdriver.FakeLdapDriver' |
605 | 329 | 329 | ||
606 | 330 | def __init__(self, *args, **kwargs): | ||
607 | 331 | AuthManagerTestCase.__init__(self) | ||
608 | 332 | test.TestCase.__init__(self, *args, **kwargs) | ||
609 | 333 | import nova.auth.fakeldap as fakeldap | ||
610 | 334 | if FLAGS.flush_db: | ||
611 | 335 | LOG.info("Flushing datastore") | ||
612 | 336 | r = fakeldap.Store.instance() | ||
613 | 337 | r.flushdb() | ||
614 | 338 | |||
615 | 339 | 330 | ||
616 | 340 | class AuthManagerDbTestCase(AuthManagerTestCase, test.TestCase): | 331 | class AuthManagerDbTestCase(AuthManagerTestCase, test.TestCase): |
617 | 341 | auth_driver = 'nova.auth.dbdriver.DbDriver' | 332 | auth_driver = 'nova.auth.dbdriver.DbDriver' |
618 | 342 | 333 | ||
619 | === modified file 'nova/tests/test_console.py' | |||
620 | --- nova/tests/test_console.py 2011-01-15 01:44:47 +0000 | |||
621 | +++ nova/tests/test_console.py 2011-02-22 00:22:48 +0000 | |||
622 | @@ -21,7 +21,6 @@ | |||
623 | 21 | """ | 21 | """ |
624 | 22 | 22 | ||
625 | 23 | import datetime | 23 | import datetime |
626 | 24 | import logging | ||
627 | 25 | 24 | ||
628 | 26 | from nova import context | 25 | from nova import context |
629 | 27 | from nova import db | 26 | from nova import db |
630 | @@ -38,7 +37,6 @@ | |||
631 | 38 | class ConsoleTestCase(test.TestCase): | 37 | class ConsoleTestCase(test.TestCase): |
632 | 39 | """Test case for console proxy""" | 38 | """Test case for console proxy""" |
633 | 40 | def setUp(self): | 39 | def setUp(self): |
634 | 41 | logging.getLogger().setLevel(logging.DEBUG) | ||
635 | 42 | super(ConsoleTestCase, self).setUp() | 40 | super(ConsoleTestCase, self).setUp() |
636 | 43 | self.flags(console_driver='nova.console.fake.FakeConsoleProxy', | 41 | self.flags(console_driver='nova.console.fake.FakeConsoleProxy', |
637 | 44 | stub_compute=True) | 42 | stub_compute=True) |
638 | 45 | 43 | ||
639 | === modified file 'nova/tests/test_direct.py' | |||
640 | --- nova/tests/test_direct.py 2011-01-08 00:05:06 +0000 | |||
641 | +++ nova/tests/test_direct.py 2011-02-22 00:22:48 +0000 | |||
642 | @@ -19,7 +19,6 @@ | |||
643 | 19 | """Tests for Direct API.""" | 19 | """Tests for Direct API.""" |
644 | 20 | 20 | ||
645 | 21 | import json | 21 | import json |
646 | 22 | import logging | ||
647 | 23 | 22 | ||
648 | 24 | import webob | 23 | import webob |
649 | 25 | 24 | ||
650 | 26 | 25 | ||
651 | === modified file 'nova/tests/test_localization.py' | |||
652 | --- nova/tests/test_localization.py 2011-01-27 22:54:59 +0000 | |||
653 | +++ nova/tests/test_localization.py 2011-02-22 00:22:48 +0000 | |||
654 | @@ -15,7 +15,6 @@ | |||
655 | 15 | # under the License. | 15 | # under the License. |
656 | 16 | 16 | ||
657 | 17 | import glob | 17 | import glob |
658 | 18 | import logging | ||
659 | 19 | import os | 18 | import os |
660 | 20 | import re | 19 | import re |
661 | 21 | import sys | 20 | import sys |
662 | 22 | 21 | ||
663 | === modified file 'nova/tests/test_log.py' | |||
664 | --- nova/tests/test_log.py 2011-02-16 09:02:17 +0000 | |||
665 | +++ nova/tests/test_log.py 2011-02-22 00:22:48 +0000 | |||
666 | @@ -1,9 +1,12 @@ | |||
667 | 1 | import cStringIO | 1 | import cStringIO |
668 | 2 | 2 | ||
669 | 3 | from nova import context | 3 | from nova import context |
670 | 4 | from nova import flags | ||
671 | 4 | from nova import log | 5 | from nova import log |
672 | 5 | from nova import test | 6 | from nova import test |
673 | 6 | 7 | ||
674 | 8 | FLAGS = flags.FLAGS | ||
675 | 9 | |||
676 | 7 | 10 | ||
677 | 8 | def _fake_context(): | 11 | def _fake_context(): |
678 | 9 | return context.RequestContext(1, 1) | 12 | return context.RequestContext(1, 1) |
679 | @@ -14,15 +17,11 @@ | |||
680 | 14 | super(RootLoggerTestCase, self).setUp() | 17 | super(RootLoggerTestCase, self).setUp() |
681 | 15 | self.log = log.logging.root | 18 | self.log = log.logging.root |
682 | 16 | 19 | ||
683 | 17 | def tearDown(self): | ||
684 | 18 | super(RootLoggerTestCase, self).tearDown() | ||
685 | 19 | log.NovaLogger.manager.loggerDict = {} | ||
686 | 20 | |||
687 | 21 | def test_is_nova_instance(self): | 20 | def test_is_nova_instance(self): |
688 | 22 | self.assert_(isinstance(self.log, log.NovaLogger)) | 21 | self.assert_(isinstance(self.log, log.NovaLogger)) |
689 | 23 | 22 | ||
692 | 24 | def test_name_is_nova_root(self): | 23 | def test_name_is_nova(self): |
693 | 25 | self.assertEqual("nova.root", self.log.name) | 24 | self.assertEqual("nova", self.log.name) |
694 | 26 | 25 | ||
695 | 27 | def test_handlers_have_nova_formatter(self): | 26 | def test_handlers_have_nova_formatter(self): |
696 | 28 | formatters = [] | 27 | formatters = [] |
697 | @@ -45,25 +44,36 @@ | |||
698 | 45 | log.audit("foo", context=_fake_context()) | 44 | log.audit("foo", context=_fake_context()) |
699 | 46 | self.assert_(True) # didn't raise exception | 45 | self.assert_(True) # didn't raise exception |
700 | 47 | 46 | ||
701 | 47 | def test_will_be_verbose_if_verbose_flag_set(self): | ||
702 | 48 | self.flags(verbose=True) | ||
703 | 49 | log.reset() | ||
704 | 50 | self.assertEqual(log.DEBUG, self.log.level) | ||
705 | 51 | |||
706 | 52 | def test_will_not_be_verbose_if_verbose_flag_not_set(self): | ||
707 | 53 | self.flags(verbose=False) | ||
708 | 54 | log.reset() | ||
709 | 55 | self.assertEqual(log.INFO, self.log.level) | ||
710 | 56 | |||
711 | 48 | 57 | ||
712 | 49 | class LogHandlerTestCase(test.TestCase): | 58 | class LogHandlerTestCase(test.TestCase): |
713 | 50 | def test_log_path_logdir(self): | 59 | def test_log_path_logdir(self): |
716 | 51 | self.flags(logdir='/some/path') | 60 | self.flags(logdir='/some/path', logfile=None) |
717 | 52 | self.assertEquals(log.get_log_file_path(binary='foo-bar'), | 61 | self.assertEquals(log._get_log_file_path(binary='foo-bar'), |
718 | 53 | '/some/path/foo-bar.log') | 62 | '/some/path/foo-bar.log') |
719 | 54 | 63 | ||
720 | 55 | def test_log_path_logfile(self): | 64 | def test_log_path_logfile(self): |
721 | 56 | self.flags(logfile='/some/path/foo-bar.log') | 65 | self.flags(logfile='/some/path/foo-bar.log') |
723 | 57 | self.assertEquals(log.get_log_file_path(binary='foo-bar'), | 66 | self.assertEquals(log._get_log_file_path(binary='foo-bar'), |
724 | 58 | '/some/path/foo-bar.log') | 67 | '/some/path/foo-bar.log') |
725 | 59 | 68 | ||
726 | 60 | def test_log_path_none(self): | 69 | def test_log_path_none(self): |
728 | 61 | self.assertTrue(log.get_log_file_path(binary='foo-bar') is None) | 70 | self.flags(logdir=None, logfile=None) |
729 | 71 | self.assertTrue(log._get_log_file_path(binary='foo-bar') is None) | ||
730 | 62 | 72 | ||
731 | 63 | def test_log_path_logfile_overrides_logdir(self): | 73 | def test_log_path_logfile_overrides_logdir(self): |
732 | 64 | self.flags(logdir='/some/other/path', | 74 | self.flags(logdir='/some/other/path', |
733 | 65 | logfile='/some/path/foo-bar.log') | 75 | logfile='/some/path/foo-bar.log') |
735 | 66 | self.assertEquals(log.get_log_file_path(binary='foo-bar'), | 76 | self.assertEquals(log._get_log_file_path(binary='foo-bar'), |
736 | 67 | '/some/path/foo-bar.log') | 77 | '/some/path/foo-bar.log') |
737 | 68 | 78 | ||
738 | 69 | 79 | ||
739 | @@ -76,13 +86,15 @@ | |||
740 | 76 | logging_debug_format_suffix="--DBG") | 86 | logging_debug_format_suffix="--DBG") |
741 | 77 | self.log = log.logging.root | 87 | self.log = log.logging.root |
742 | 78 | self.stream = cStringIO.StringIO() | 88 | self.stream = cStringIO.StringIO() |
745 | 79 | handler = log.StreamHandler(self.stream) | 89 | self.handler = log.StreamHandler(self.stream) |
746 | 80 | self.log.addHandler(handler) | 90 | self.log.addHandler(self.handler) |
747 | 91 | self.level = self.log.level | ||
748 | 81 | self.log.setLevel(log.DEBUG) | 92 | self.log.setLevel(log.DEBUG) |
749 | 82 | 93 | ||
750 | 83 | def tearDown(self): | 94 | def tearDown(self): |
751 | 95 | self.log.setLevel(self.level) | ||
752 | 96 | self.log.removeHandler(self.handler) | ||
753 | 84 | super(NovaFormatterTestCase, self).tearDown() | 97 | super(NovaFormatterTestCase, self).tearDown() |
754 | 85 | log.NovaLogger.manager.loggerDict = {} | ||
755 | 86 | 98 | ||
756 | 87 | def test_uncontextualized_log(self): | 99 | def test_uncontextualized_log(self): |
757 | 88 | self.log.info("foo") | 100 | self.log.info("foo") |
758 | @@ -102,30 +114,15 @@ | |||
759 | 102 | class NovaLoggerTestCase(test.TestCase): | 114 | class NovaLoggerTestCase(test.TestCase): |
760 | 103 | def setUp(self): | 115 | def setUp(self): |
761 | 104 | super(NovaLoggerTestCase, self).setUp() | 116 | super(NovaLoggerTestCase, self).setUp() |
763 | 105 | self.flags(default_log_levels=["nova-test=AUDIT"], verbose=False) | 117 | levels = FLAGS.default_log_levels |
764 | 118 | levels.append("nova-test=AUDIT") | ||
765 | 119 | self.flags(default_log_levels=levels, | ||
766 | 120 | verbose=True) | ||
767 | 106 | self.log = log.getLogger('nova-test') | 121 | self.log = log.getLogger('nova-test') |
768 | 107 | 122 | ||
769 | 108 | def tearDown(self): | ||
770 | 109 | super(NovaLoggerTestCase, self).tearDown() | ||
771 | 110 | log.NovaLogger.manager.loggerDict = {} | ||
772 | 111 | |||
773 | 112 | def test_has_level_from_flags(self): | 123 | def test_has_level_from_flags(self): |
774 | 113 | self.assertEqual(log.AUDIT, self.log.level) | 124 | self.assertEqual(log.AUDIT, self.log.level) |
775 | 114 | 125 | ||
776 | 115 | def test_child_log_has_level_of_parent_flag(self): | 126 | def test_child_log_has_level_of_parent_flag(self): |
777 | 116 | l = log.getLogger('nova-test.foo') | 127 | l = log.getLogger('nova-test.foo') |
778 | 117 | self.assertEqual(log.AUDIT, l.level) | 128 | self.assertEqual(log.AUDIT, l.level) |
779 | 118 | |||
780 | 119 | |||
781 | 120 | class VerboseLoggerTestCase(test.TestCase): | ||
782 | 121 | def setUp(self): | ||
783 | 122 | super(VerboseLoggerTestCase, self).setUp() | ||
784 | 123 | self.flags(default_log_levels=["nova.test=AUDIT"], verbose=True) | ||
785 | 124 | self.log = log.getLogger('nova.test') | ||
786 | 125 | |||
787 | 126 | def tearDown(self): | ||
788 | 127 | super(VerboseLoggerTestCase, self).tearDown() | ||
789 | 128 | log.NovaLogger.manager.loggerDict = {} | ||
790 | 129 | |||
791 | 130 | def test_will_be_verbose_if_named_nova_and_verbose_flag_set(self): | ||
792 | 131 | self.assertEqual(log.DEBUG, self.log.level) | ||
793 | 132 | 129 | ||
794 | === modified file 'nova/twistd.py' | |||
795 | --- nova/twistd.py 2011-02-14 22:19:15 +0000 | |||
796 | +++ nova/twistd.py 2011-02-22 00:22:48 +0000 | |||
797 | @@ -148,6 +148,7 @@ | |||
798 | 148 | options.insert(0, '') | 148 | options.insert(0, '') |
799 | 149 | 149 | ||
800 | 150 | args = FLAGS(options) | 150 | args = FLAGS(options) |
801 | 151 | logging.setup() | ||
802 | 151 | argv = args[1:] | 152 | argv = args[1:] |
803 | 152 | # ignore subcommands | 153 | # ignore subcommands |
804 | 153 | 154 | ||
805 | @@ -258,7 +259,6 @@ | |||
806 | 258 | print 'usage: %s [options] [start|stop|restart]' % argv[0] | 259 | print 'usage: %s [options] [start|stop|restart]' % argv[0] |
807 | 259 | sys.exit(1) | 260 | sys.exit(1) |
808 | 260 | 261 | ||
809 | 261 | logging.basicConfig() | ||
810 | 262 | logging.debug(_("Full set of FLAGS:")) | 262 | logging.debug(_("Full set of FLAGS:")) |
811 | 263 | for flag in FLAGS: | 263 | for flag in FLAGS: |
812 | 264 | logging.debug("%s : %s" % (flag, FLAGS.get(flag, None))) | 264 | logging.debug("%s : %s" % (flag, FLAGS.get(flag, None))) |
813 | 265 | 265 | ||
814 | === modified file 'nova/utils.py' | |||
815 | --- nova/utils.py 2011-02-17 22:09:26 +0000 | |||
816 | +++ nova/utils.py 2011-02-22 00:22:48 +0000 | |||
817 | @@ -55,7 +55,7 @@ | |||
818 | 55 | __import__(mod_str) | 55 | __import__(mod_str) |
819 | 56 | return getattr(sys.modules[mod_str], class_str) | 56 | return getattr(sys.modules[mod_str], class_str) |
820 | 57 | except (ImportError, ValueError, AttributeError), exc: | 57 | except (ImportError, ValueError, AttributeError), exc: |
822 | 58 | logging.debug(_('Inner Exception: %s'), exc) | 58 | LOG.debug(_('Inner Exception: %s'), exc) |
823 | 59 | raise exception.NotFound(_('Class %s cannot be found') % class_str) | 59 | raise exception.NotFound(_('Class %s cannot be found') % class_str) |
824 | 60 | 60 | ||
825 | 61 | 61 | ||
826 | 62 | 62 | ||
827 | === modified file 'nova/wsgi.py' | |||
828 | --- nova/wsgi.py 2011-01-21 21:10:26 +0000 | |||
829 | +++ nova/wsgi.py 2011-02-22 00:22:48 +0000 | |||
830 | @@ -59,7 +59,6 @@ | |||
831 | 59 | """Server class to manage multiple WSGI sockets and applications.""" | 59 | """Server class to manage multiple WSGI sockets and applications.""" |
832 | 60 | 60 | ||
833 | 61 | def __init__(self, threads=1000): | 61 | def __init__(self, threads=1000): |
834 | 62 | logging.basicConfig() | ||
835 | 63 | self.pool = eventlet.GreenPool(threads) | 62 | self.pool = eventlet.GreenPool(threads) |
836 | 64 | 63 | ||
837 | 65 | def start(self, application, port, host='0.0.0.0', backlog=128): | 64 | def start(self, application, port, host='0.0.0.0', backlog=128): |
838 | 66 | 65 | ||
839 | === modified file 'run_tests.py' | |||
840 | --- run_tests.py 2011-01-31 05:38:58 +0000 | |||
841 | +++ run_tests.py 2011-02-22 00:22:48 +0000 | |||
842 | @@ -27,6 +27,7 @@ | |||
843 | 27 | from nose import core | 27 | from nose import core |
844 | 28 | 28 | ||
845 | 29 | from nova import log as logging | 29 | from nova import log as logging |
846 | 30 | from nova.tests import fake_flags | ||
847 | 30 | 31 | ||
848 | 31 | 32 | ||
849 | 32 | class NovaTestResult(result.TextTestResult): | 33 | class NovaTestResult(result.TextTestResult): |
850 | @@ -60,7 +61,7 @@ | |||
851 | 60 | 61 | ||
852 | 61 | 62 | ||
853 | 62 | if __name__ == '__main__': | 63 | if __name__ == '__main__': |
855 | 63 | logging.basicConfig() | 64 | logging.setup() |
856 | 64 | c = config.Config(stream=sys.stdout, | 65 | c = config.Config(stream=sys.stdout, |
857 | 65 | env=os.environ, | 66 | env=os.environ, |
858 | 66 | verbosity=3, | 67 | verbosity=3, |
859 | 67 | 68 | ||
860 | === modified file 'run_tests.sh' | |||
861 | --- run_tests.sh 2011-01-31 05:55:32 +0000 | |||
862 | +++ run_tests.sh 2011-02-22 00:22:48 +0000 | |||
863 | @@ -40,7 +40,7 @@ | |||
864 | 40 | function run_tests { | 40 | function run_tests { |
865 | 41 | # Just run the test suites in current environment | 41 | # Just run the test suites in current environment |
866 | 42 | ${wrapper} rm -f nova.sqlite | 42 | ${wrapper} rm -f nova.sqlite |
868 | 43 | ${wrapper} $NOSETESTS 2> run_tests.err.log | 43 | ${wrapper} $NOSETESTS |
869 | 44 | } | 44 | } |
870 | 45 | 45 | ||
871 | 46 | NOSETESTS="python run_tests.py $noseargs" | 46 | NOSETESTS="python run_tests.py $noseargs" |
I will dive into this again in the morning, but what strikes me right away is that it feels unusual for logging to require adding an additional "initialized" attribute to Flags, my instinct is that this is a problem solvable by good practice rather than by force. If you'd like to explain further why it that needs to be done, that'd be swell and will make it easier to review again in the morning.