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

Proposed by Facundo Batista on 2015-09-29
Status: Merged
Approved by: Facundo Batista on 2015-09-29
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 on 2015-09-29
Celso Providelo (community) 2015-09-29 Approve on 2015-09-29
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.
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 on 2015-09-29

Allow to pass level in configure_logging.

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
1=== modified file 'uservice_logging/logging.py'
2--- uservice_logging/logging.py 2015-09-01 23:29:49 +0000
3+++ uservice_logging/logging.py 2015-09-29 12:30:07 +0000
4@@ -54,7 +54,7 @@
5 return dumped.encode('utf8')
6
7
8-def configure_logging(config, service, **kwds):
9+def configure_logging(config, service, level=logging.INFO, **kwds):
10 """Simplified setup for the micro-service logging.
11
12 If present config['logstash'] is used to setup logstash (see
13@@ -85,10 +85,10 @@
14 logstash_config = None
15 if 'logstash' in config:
16 logstash_config = config['logstash']
17- return configure_service_logging(log_path, logstash_config)
18-
19-
20-def configure_service_logging(log_file_path=None, logstash_config=None):
21+ return configure_service_logging(log_path, logstash_config, level)
22+
23+
24+def configure_service_logging(log_file_path=None, logstash_config=None, level=logging.INFO):
25 """Configure python's logging for the micro-service.
26
27 This function sets a standard level of logging for all our services. The
28@@ -103,10 +103,11 @@
29 logging to stderr instead of the file.
30 :param logstash_config: If specified, must be a mapping type that contains
31 the keys 'host', 'port', and 'version'.
32+ :param level: The logger level (default to INFO).
33
34 """
35 root_logger = logging.getLogger()
36- root_logger.setLevel(logging.INFO)
37+ root_logger.setLevel(level)
38
39 # Silence requests logging, which is created by nova, keystone and swift.
40 requests_logger = logging.getLogger('requests')
41
42=== modified file 'uservice_logging/tests/test_logging.py'
43--- uservice_logging/tests/test_logging.py 2015-08-20 16:48:42 +0000
44+++ uservice_logging/tests/test_logging.py 2015-09-29 12:30:07 +0000
45@@ -193,6 +193,40 @@
46 FileContains(matcher=Contains("Hello World"))
47 )
48
49+ def test__configure_service_logging__log_level(self):
50+ with tempfile.TemporaryDirectory() as run_dir:
51+ rc, out, err = self.run_script(
52+ dedent(
53+ """
54+ import logging
55+ from uservice_logging.logging import configure_service_logging
56+
57+ configure_service_logging(level=logging.DEBUG)
58+ logging.debug("Hello World")
59+ """
60+ ),
61+ run_dir
62+ )
63+ self.expectThat(rc, Equals(0))
64+ self.expectThat(err, Contains("Hello World"))
65+
66+ def test__configure_logging__log_level(self):
67+ with tempfile.TemporaryDirectory() as run_dir:
68+ rc, out, err = self.run_script(
69+ dedent(
70+ """
71+ import logging
72+ from uservice_logging.logging import configure_logging
73+
74+ configure_logging(dict(), 'svc', logging.DEBUG)
75+ logging.debug("Hello World")
76+ """
77+ ),
78+ run_dir
79+ )
80+ self.expectThat(rc, Equals(0))
81+ self.expectThat(err, Contains("Hello World"))
82+
83
84 class LoggerClassFixture(Fixture):
85

Subscribers

People subscribed via source and target branches