Merge lp:~brandontschaefer/libertine/add-logger into lp:libertine

Proposed by Brandon Schaefer
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
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_logger__ which will only be setup once, with one handler. In the future if we need more handlers we will have to adjust how we check we have setup or not!

Description of the change

Add a get_logger function to the libertine utils. This function will get the logger __libertiner_logger__ which will only be setup once, with one handler. In the future if we need more handlers we will have to adjust how we check we have setup or not!

Also added some tests

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

FAILED: Continuous integration, rev:283
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://code.launchpad.net/~brandontschaefer/libertine/add-logger/+merge/302485/+edit-commit-message

https://jenkins.canonical.com/libertine/job/lp-libertine-ci/86/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/libertine/job/build/265/console
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/201/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/268
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/253
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/253
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/253
    FAILURE: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/246/console
    FAILURE: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/246/console
    FAILURE: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/246/console
    FAILURE: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/246/console
    FAILURE: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/246/console
    FAILURE: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/246/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/86/rebuild

review: Needs Fixing (continuous-integration)
284. By Brandon Schaefer

* Forgot to add the tests

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
Download full text (3.2 KiB)

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://code.launchpad.net/~brandontschaefer/libertine/add-logger/+merge/302485/+edit-commit-message

https://jenkins.canonical.com/libertine/job/lp-libertine-ci/87/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/266
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/219
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/219
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/219
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/219
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/219
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/219
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/202/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/269
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/254
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/254
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/254
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/247
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/247/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/247
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/247/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/247
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/247/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/247
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/247/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/247
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/247/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/247
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/247/artifact/output/*zip*/output.zip

Click here to trig...

Read more...

review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:284
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/88/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/267
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/220
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/220
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/220
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/220
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/220
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/220
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/203/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/270
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/255
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/255
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/255
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/248
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/248/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/248
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/248/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/248
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/248/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/248
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/248/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/248
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/248/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/248
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/248/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/88/rebuild

review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

get_logger() is not defined in python/libertine/Libertine.py. You need to use libertine.utils.get_logger()

review: Needs Fixing
285. By Brandon Schaefer

* Use the correct namespace

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:285
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/94/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/273
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/224
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/224
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/224
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/224
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/224
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/224
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/209/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/275
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/259
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/259
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/259
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/252
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/252/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/252
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/252/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/252
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/252/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/252
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/252/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/252
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/252/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/252
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/252/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/94/rebuild

review: Approve (continuous-integration)
Revision history for this message
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.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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+

Subscribers

People subscribed via source and target branches