Skip to content

Commit

Permalink
Leave logger configuration to library user
Browse files Browse the repository at this point in the history
It is bad practice to change logging framework defaults, it is the responsability
of the caller to set things up as caller wants it.

Use a LoggerAdapter to allow tracing session in LogRecord if so desired.
  • Loading branch information
EvaSDK committed Mar 24, 2017
1 parent 4ab02d2 commit 8d3c1e3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 72 deletions.
31 changes: 8 additions & 23 deletions ghost/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
except ImportError:
from http.cookiejar import Cookie, LWPCookieJar
from contextlib import contextmanager
from .logger import configure
from .bindings import (
binding,
QtCore,
Expand Down Expand Up @@ -52,10 +51,12 @@
long = int
basestring = str


default_user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 " +\
"(KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"

logger = logging.getLogger('ghost')
logger.addHandler(logging.NullHandler())


class Error(Exception):
"""Base class for Ghost exceptions."""
Expand Down Expand Up @@ -262,20 +263,13 @@ class Ghost(object):

def __init__(
self,
log_level=logging.WARNING,
log_handler=logging.StreamHandler(sys.stderr),
plugin_path=['/usr/lib/mozilla/plugins', ],
defaults=None,
):
if not binding:
raise Exception("Ghost.py requires PySide or PyQt4")

self.logger = configure(
'ghost',
"Ghost",
log_level,
log_handler,
)
self.logger = logger.getChild('application')

if (
sys.platform.startswith('linux') and
Expand All @@ -297,14 +291,7 @@ def __init__(
self.logger.info('Initializing QT application')
Ghost._app = QApplication.instance() or QApplication(['ghost'])

qInstallMsgHandler(QTMessageProxy(
configure(
'qt',
'QT',
log_level,
log_handler,
)
))
qInstallMsgHandler(QTMessageProxy(logging.getLogger('qt')))
if plugin_path:
for p in plugin_path:
Ghost._app.addLibraryPath(p)
Expand Down Expand Up @@ -375,12 +362,10 @@ def __init__(

self.id = str(uuid.uuid4())

self.logger = configure(
'ghost.%s' % self.id,
"Ghost<%s>" % self.id,
ghost.logger.level,
self.logger = logging.LoggerAdapter(
logger.getChild('session'),
{'session': self.id},
)

self.logger.info("Starting new session")

self.http_resources = []
Expand Down
46 changes: 0 additions & 46 deletions ghost/logger.py

This file was deleted.

2 changes: 0 additions & 2 deletions ghost/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,11 @@ class BaseGhostTestCase(TestCase):
display = False
wait_timeout = 5
viewport_size = (800, 600)
log_level = logging.DEBUG

def __new__(cls, *args, **kwargs):
"""Creates Ghost instance."""
if not hasattr(cls, 'ghost'):
cls.ghost = Ghost(
log_level=cls.log_level,
defaults=dict(
display=cls.display,
viewport_size=cls.viewport_size,
Expand Down
1 change: 0 additions & 1 deletion tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
class GhostTest(GhostTestCase):
port = PORT
display = False
log_level = logging.INFO

@classmethod
def create_app(cls):
Expand Down

0 comments on commit 8d3c1e3

Please sign in to comment.