Improve logging in the Python module unit tests.

This commit is contained in:
Ghislain MARY 2014-08-28 10:44:12 +02:00
parent 13ca8e0e4c
commit bb673bb9f4
3 changed files with 26 additions and 14 deletions

View file

@ -11,19 +11,6 @@ test_password = "secret"
test_route = "sip2.linphone.org"
def log_handler(level, msg):
method = getattr(logging, level)
if not msg.strip().startswith('[PYLINPHONE]'):
msg = '[CORE] ' + msg
method(msg)
def setup_logging(filename):
format = "%(asctime)s.%(msecs)03d %(levelname)s: %(message)s"
datefmt = "%H:%M:%S"
logging.basicConfig(filename=filename, level=logging.INFO, format=format, datefmt=datefmt)
linphone.set_log_handler(log_handler)
def create_address(domain):
addr = linphone.Address.new(None)
assert addr != None
@ -39,6 +26,25 @@ def create_address(domain):
return addr
class Logger(logging.Logger):
def __init__(self, filename):
logging.Logger.__init__(self, filename)
self.setLevel(logging.INFO)
handler = logging.FileHandler(filename)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s.%(msecs)03d %(levelname)s: %(message)s', '%H:%M:%S')
handler.setFormatter(formatter)
self.addHandler(handler)
linphone.set_log_handler(self.log_handler)
def log_handler(self, level, msg):
method = getattr(self, level)
if not msg.strip().startswith('[PYLINPHONE]'):
msg = '[CORE] ' + msg
method(msg)
class CoreManagerStats:
def __init__(self):
self.reset()

View file

@ -78,7 +78,7 @@ class TestRegister:
@classmethod
def setup_class(cls):
base, ext = os.path.splitext(os.path.basename(__file__))
linphonetester.setup_logging(base + '.log')
cls.logger = linphonetester.Logger(base + '.log')
def test_simple_register(self):
cm = RegisterCoreManager()

View file

@ -1,9 +1,15 @@
from nose.tools import assert_equals
import linphone
import linphonetester
import os
class TestSetup:
@classmethod
def setup_class(cls):
base, ext = os.path.splitext(os.path.basename(__file__))
cls.logger = linphonetester.Logger(base + '.log')
def test_address(self):
linphonetester.create_address(None)