Merge lp:~brandontschaefer/libertine/add-logger into lp:libertine
- add-logger
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Christopher Townsend |
Approved revision: | 285 |
Merged at revision: | 283 |
Proposed branch: | lp:~brandontschaefer/libertine/add-logger |
Merge into: | lp:libertine |
Diff against target: |
141 lines (+89/-3) 4 files modified
python/libertine/Libertine.py (+5/-3) python/libertine/utils.py (+27/-0) tests/unit/CMakeLists.txt (+8/-0) tests/unit/libertine_logger_tests.py (+49/-0) |
To merge this branch: | bzr merge lp:~brandontschaefer/libertine/add-logger |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Christopher Townsend | Approve | ||
Libertine CI Bot | continuous-integration | Approve | |
Review via email: mp+302485@code.launchpad.net |
Commit message
Add a get_logger function to the libertine utils. This function will get the logger __libertiner_
Description of the change
Add a get_logger function to the libertine utils. This function will get the logger __libertiner_
Also added some tests
Libertine CI Bot (libertine-ci-bot) wrote : | # |
- 284. By Brandon Schaefer
-
* Forgot to add the tests
Libertine CI Bot (libertine-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:284
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trig...
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:284
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Christopher Townsend (townsend) wrote : | # |
get_logger() is not defined in python/
- 285. By Brandon Schaefer
-
* Use the correct namespace
Libertine CI Bot (libertine-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:285
https:/
Executed test runs:
FAILURE: https:/
None: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:285
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Christopher Townsend (townsend) wrote : | # |
Ok, looks good.
I think in the future, we may change the env var to something like LIBERTINE_LOGLEVEL and use levels like "info", "error", "debug", etc. to set the verbosity. And if the env var is not set, then no logging.
Preview Diff
1 | === modified file 'python/libertine/Libertine.py' |
2 | --- python/libertine/Libertine.py 2016-08-09 18:18:14 +0000 |
3 | +++ python/libertine/Libertine.py 2016-08-10 15:33:26 +0000 |
4 | @@ -593,9 +593,10 @@ |
5 | try: |
6 | raw_sockets = list(map(lambda x : x.socket, self.descriptors)) |
7 | rlist, wlist, elist = select.select(raw_sockets, [], []) |
8 | - except InterruptedError: |
9 | + except InterruptedError as e: |
10 | continue |
11 | - except: |
12 | + except Exception as e: |
13 | + libertine.utils.get_logger().exception(e) |
14 | break |
15 | |
16 | for sock in rlist: |
17 | @@ -608,7 +609,8 @@ |
18 | else: |
19 | try: |
20 | data = sock.recv(4096) |
21 | - except: |
22 | + except Exception as e: |
23 | + libertine.utils.get_logger().exception(e) |
24 | self.close_connections(sock) |
25 | continue |
26 | else: |
27 | |
28 | === modified file 'python/libertine/utils.py' |
29 | --- python/libertine/utils.py 2016-06-28 14:30:01 +0000 |
30 | +++ python/libertine/utils.py 2016-08-10 15:33:26 +0000 |
31 | @@ -16,6 +16,7 @@ |
32 | # You should have received a copy of the GNU General Public License |
33 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
34 | |
35 | +import logging |
36 | import os |
37 | import shlex |
38 | import subprocess |
39 | @@ -25,6 +26,32 @@ |
40 | require_version('Libertine', '1') |
41 | from gi.repository import Libertine |
42 | |
43 | +def get_logger(): |
44 | + logger = logging.getLogger('__libertine_logger__') |
45 | + |
46 | + # If someone else sets a handler before this, we wont run this! |
47 | + if not logger.hasHandlers(): |
48 | + logger.setLevel(logging.DEBUG) |
49 | + logger.disabled = True |
50 | + |
51 | + stream_handler = logging.StreamHandler() |
52 | + stream_handler.setLevel(logging.DEBUG) |
53 | + |
54 | + formatter = logging.Formatter('%(filename)s:' |
55 | + '%(lineno)d: ' |
56 | + '%(levelname)s: ' |
57 | + '%(funcName)s():\t' |
58 | + '%(message)s') |
59 | + |
60 | + stream_handler.setFormatter(formatter) |
61 | + logger.addHandler(stream_handler) |
62 | + |
63 | + # Only enable the logger if we set this |
64 | + if os.getenv('LIBERTINE_DEBUG') is '1': |
65 | + logger.disabled = False |
66 | + |
67 | + return logger |
68 | + |
69 | |
70 | def get_libertine_container_rootfs_path(container_id): |
71 | path = Libertine.container_path(container_id) |
72 | |
73 | === modified file 'tests/unit/CMakeLists.txt' |
74 | --- tests/unit/CMakeLists.txt 2016-07-19 20:25:02 +0000 |
75 | +++ tests/unit/CMakeLists.txt 2016-08-10 15:33:26 +0000 |
76 | @@ -67,3 +67,11 @@ |
77 | PROPERTIES |
78 | ENVIRONMENT |
79 | "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") |
80 | + |
81 | +add_test(test_logger |
82 | + "/usr/bin/python3" "-m" "testtools.run" "libertine_logger_tests" |
83 | +) |
84 | +set_tests_properties(test_logger |
85 | + PROPERTIES |
86 | + ENVIRONMENT |
87 | + "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}") |
88 | |
89 | === added file 'tests/unit/libertine_logger_tests.py' |
90 | --- tests/unit/libertine_logger_tests.py 1970-01-01 00:00:00 +0000 |
91 | +++ tests/unit/libertine_logger_tests.py 2016-08-10 15:33:26 +0000 |
92 | @@ -0,0 +1,49 @@ |
93 | +# Copyright 2016 Canonical Ltd. |
94 | +# |
95 | +# This program is free software: you can redistribute it and/or modify it |
96 | +# under the terms of the GNU General Public License version 3, as published |
97 | +# by the Free Software Foundation. |
98 | +# |
99 | +# This program is distributed in the hope that it will be useful, but |
100 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
101 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
102 | +# PURPOSE. See the GNU General Public License for more details. |
103 | +# |
104 | +# You should have received a copy of the GNU General Public License along |
105 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
106 | + |
107 | +import os |
108 | +import shutil |
109 | + |
110 | +import libertine.utils |
111 | + |
112 | +from testtools import TestCase |
113 | +from testtools.matchers import Equals, NotEquals |
114 | + |
115 | +class TestLogger(TestCase): |
116 | + def setUp(self): |
117 | + super(TestLogger, self).setUp() |
118 | + os.environ['LIBERTINE_DEBUG'] = '1' |
119 | + self.addCleanup(self.cleanup) |
120 | + |
121 | + def cleanup(self): |
122 | + if os.getenv('LIBERTINE_DEBUG', None) is not None: |
123 | + del os.environ['LIBERTINE_DEBUG'] |
124 | + |
125 | + def test_logger_off_by_default(self): |
126 | + # Need to turn off for this test only! |
127 | + self.cleanup() |
128 | + os.unsetenv('LIBERTINE_DEBUG') |
129 | + l = libertine.utils.get_logger() |
130 | + self.assertTrue(l.disabled) |
131 | + |
132 | + def test_logger_on_with_env_var(self): |
133 | + l = libertine.utils.get_logger() |
134 | + self.assertFalse(l.disabled) |
135 | + |
136 | + def test_logger_only_inits_once(self): |
137 | + l1 = libertine.utils.get_logger() |
138 | + l2 = libertine.utils.get_logger() |
139 | + l3 = libertine.utils.get_logger() |
140 | + self.assertThat(len(l3.handlers), Equals(1)) |
141 | + |
FAILED: Continuous integration, rev:283 /code.launchpad .net/~brandonts chaefer/ libertine/ add-logger/ +merge/ 302485/ +edit-commit- message
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
https:/ /jenkins. canonical. com/libertine/ job/lp- libertine- ci/86/ /jenkins. canonical. com/libertine/ job/build/ 265/console /jenkins. canonical. com/libertine/ job/lp- generic- update- mp/201/ console /jenkins. canonical. com/libertine/ job/build- 0-fetch/ 268 /jenkins. canonical. com/libertine/ job/build- 1-sourcepkg/ release= vivid+overlay/ 253 /jenkins. canonical. com/libertine/ job/build- 1-sourcepkg/ release= xenial+ overlay/ 253 /jenkins. canonical. com/libertine/ job/build- 1-sourcepkg/ release= yakkety/ 253 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= vivid+overlay/ 246/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= xenial+ overlay/ 246/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= yakkety/ 246/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= vivid+overlay/ 246/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= xenial+ overlay/ 246/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= yakkety/ 246/console
Executed test runs:
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/libertine/ job/lp- libertine- ci/86/rebuild
https:/