Merge lp:~facundo/uservice-logging/log-level into lp:uservice-logging

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 29
Merged at revision: 28
Proposed branch: lp:~facundo/uservice-logging/log-level
Merge into: lp:uservice-logging
Diff against target: 84 lines (+41/-6)
2 files modified
uservice_logging/logging.py (+7/-6)
uservice_logging/tests/test_logging.py (+34/-0)
To merge this branch: bzr merge lp:~facundo/uservice-logging/log-level
Reviewer Review Type Date Requested Status
Facundo Batista (community) Approve
Celso Providelo (community) Approve
Review via email: mp+272734@code.launchpad.net

Commit message

Allow to pass the logging level.

Description of the change

Allow to pass the logging level.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Facundo,

Looks good, but I confess I do not remember (not is it mentioned on the card) what is the use case for setting specific log levels.

That would determine the services/application needing a new release of uservice-logging.

review: Approve
29. By Facundo Batista

Allow to pass level in configure_logging.

Revision history for this message
Facundo Batista (facundo) wrote :

Added possibility of passing the log level in other entry point.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'uservice_logging/logging.py'
--- uservice_logging/logging.py 2015-09-01 23:29:49 +0000
+++ uservice_logging/logging.py 2015-09-29 12:30:07 +0000
@@ -54,7 +54,7 @@
54 return dumped.encode('utf8')54 return dumped.encode('utf8')
5555
5656
57def configure_logging(config, service, **kwds):57def configure_logging(config, service, level=logging.INFO, **kwds):
58 """Simplified setup for the micro-service logging.58 """Simplified setup for the micro-service logging.
5959
60 If present config['logstash'] is used to setup logstash (see60 If present config['logstash'] is used to setup logstash (see
@@ -85,10 +85,10 @@
85 logstash_config = None85 logstash_config = None
86 if 'logstash' in config:86 if 'logstash' in config:
87 logstash_config = config['logstash']87 logstash_config = config['logstash']
88 return configure_service_logging(log_path, logstash_config)88 return configure_service_logging(log_path, logstash_config, level)
8989
9090
91def configure_service_logging(log_file_path=None, logstash_config=None):91def configure_service_logging(log_file_path=None, logstash_config=None, level=logging.INFO):
92 """Configure python's logging for the micro-service.92 """Configure python's logging for the micro-service.
9393
94 This function sets a standard level of logging for all our services. The94 This function sets a standard level of logging for all our services. The
@@ -103,10 +103,11 @@
103 logging to stderr instead of the file.103 logging to stderr instead of the file.
104 :param logstash_config: If specified, must be a mapping type that contains104 :param logstash_config: If specified, must be a mapping type that contains
105 the keys 'host', 'port', and 'version'.105 the keys 'host', 'port', and 'version'.
106 :param level: The logger level (default to INFO).
106107
107 """108 """
108 root_logger = logging.getLogger()109 root_logger = logging.getLogger()
109 root_logger.setLevel(logging.INFO)110 root_logger.setLevel(level)
110111
111 # Silence requests logging, which is created by nova, keystone and swift.112 # Silence requests logging, which is created by nova, keystone and swift.
112 requests_logger = logging.getLogger('requests')113 requests_logger = logging.getLogger('requests')
113114
=== modified file 'uservice_logging/tests/test_logging.py'
--- uservice_logging/tests/test_logging.py 2015-08-20 16:48:42 +0000
+++ uservice_logging/tests/test_logging.py 2015-09-29 12:30:07 +0000
@@ -193,6 +193,40 @@
193 FileContains(matcher=Contains("Hello World"))193 FileContains(matcher=Contains("Hello World"))
194 )194 )
195195
196 def test__configure_service_logging__log_level(self):
197 with tempfile.TemporaryDirectory() as run_dir:
198 rc, out, err = self.run_script(
199 dedent(
200 """
201 import logging
202 from uservice_logging.logging import configure_service_logging
203
204 configure_service_logging(level=logging.DEBUG)
205 logging.debug("Hello World")
206 """
207 ),
208 run_dir
209 )
210 self.expectThat(rc, Equals(0))
211 self.expectThat(err, Contains("Hello World"))
212
213 def test__configure_logging__log_level(self):
214 with tempfile.TemporaryDirectory() as run_dir:
215 rc, out, err = self.run_script(
216 dedent(
217 """
218 import logging
219 from uservice_logging.logging import configure_logging
220
221 configure_logging(dict(), 'svc', logging.DEBUG)
222 logging.debug("Hello World")
223 """
224 ),
225 run_dir
226 )
227 self.expectThat(rc, Equals(0))
228 self.expectThat(err, Contains("Hello World"))
229
196230
197class LoggerClassFixture(Fixture):231class LoggerClassFixture(Fixture):
198232

Subscribers

People subscribed via source and target branches