diff options
author | drebs <drebs@leap.se> | 2016-09-22 14:44:46 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2016-09-22 17:57:40 -0300 |
commit | b7340a962bfeae9af28c4b514d0eb077f41dd832 (patch) | |
tree | cd9a31d6b955fdff5eadde452089cf718a299af8 /common/src | |
parent | a7ffb49e1169c93af3b728f5db1a5e16e6231590 (diff) |
[feat] centralize logging and use twisted.logger by default
Diffstat (limited to 'common/src')
-rw-r--r-- | common/src/leap/soledad/common/couch/state.py | 4 | ||||
-rw-r--r-- | common/src/leap/soledad/common/log.py | 45 |
2 files changed, 47 insertions, 2 deletions
diff --git a/common/src/leap/soledad/common/couch/state.py b/common/src/leap/soledad/common/couch/state.py index 9ff9fe55..e3cd1a24 100644 --- a/common/src/leap/soledad/common/couch/state.py +++ b/common/src/leap/soledad/common/couch/state.py @@ -17,12 +17,12 @@ """ Server state using CouchDatabase as backend. """ -import logging import re import time from urlparse import urljoin from hashlib import sha512 +from leap.soledad.common.log import getLogger from leap.soledad.common.couch import CouchDatabase from leap.soledad.common.couch import couch_server from leap.soledad.common.command import exec_validated_cmd @@ -30,7 +30,7 @@ from leap.soledad.common.l2db.remote.server_state import ServerState from leap.soledad.common.l2db.errors import Unauthorized -logger = logging.getLogger(__name__) +logger = getLogger(__name__) def is_db_name_valid(name): diff --git a/common/src/leap/soledad/common/log.py b/common/src/leap/soledad/common/log.py new file mode 100644 index 00000000..3f026045 --- /dev/null +++ b/common/src/leap/soledad/common/log.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# log.py +# Copyright (C) 2016 LEAP +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + +""" +This module centralizes logging facilities and allows for different behaviours, +as using the python logging module instead of twisted logger, and to print logs +to stdout, mainly for development purposes. +""" + + +import os +import sys + +from twisted.logger import Logger +from twisted.logger import textFileLogObserver + + +def getLogger(*args, **kwargs): + + if os.environ.get('SOLEDAD_USE_PYTHON_LOGGING'): + import logging + return logging.getLogger(__name__) + + if os.environ.get('SOLEDAD_LOG_TO_STDOUT'): + kwargs({'observer': textFileLogObserver(sys.stdout)}) + + return Logger(*args, **kwargs) + + +__all__ = ['getLogger'] |