diff options
author | Bruno Wagner <bwgpro@gmail.com> | 2015-06-02 18:15:08 -0300 |
---|---|---|
committer | Bruno Wagner <bwgpro@gmail.com> | 2015-06-02 18:15:08 -0300 |
commit | 1db9c6fafb07bc7ee3b086c49135cc667e4bd4a1 (patch) | |
tree | 3d1cbd042d7947b40beca8edaf5180eb2306dd76 | |
parent | acf1866d6253105e1ace6812394b8bda6c064160 (diff) |
Remove unused methods from logger and made twisted use the python standard logger
-rw-r--r-- | service/pixelated/config/logging_setup.py | 48 |
1 files changed, 9 insertions, 39 deletions
diff --git a/service/pixelated/config/logging_setup.py b/service/pixelated/config/logging_setup.py index a15413a0..023d9a9b 100644 --- a/service/pixelated/config/logging_setup.py +++ b/service/pixelated/config/logging_setup.py @@ -15,51 +15,21 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import logging -import socket -import sys import os from twisted.python import log -from twisted.python import util def init_logging(args): debug_enabled = args.debug or os.environ.get('DEBUG', False) - - logging.basicConfig(level=logging.DEBUG if debug_enabled else logging.WARNING, - format='[%(asctime)s] ' + socket.gethostname() + ' %(name)-12s %(levelname)-8s %(message)s', - datefmt='%m-%d %H:%M:%S', - filemode='a') - - if debug_enabled: - init_debugger() - - log.startLogging(sys.stdout) - - -def init_debugger(): - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') - console = logging.StreamHandler() - console.setLevel(logging.DEBUG) - console.setFormatter(formatter) - logging.getLogger('').addHandler(console) + logging_level = logging.DEBUG if debug_enabled else logging.INFO + log_format = "%(asctime)s [%(name)s] %(levelname)s %(message)s" + date_format = '%Y-%m-%d %H:%M:%S' -class PixelatedLogObserver(log.FileLogObserver): - - """ FileLogObserver with a customized format """ - def emit(self, event): - text = log.textFromEventDict(event) - - if text is None: - return - - self.timeFormat = '[%Y-%m-%d %H:%M:%S]' - time_str = self.formatTime(event['time']) - - fmt_dict = {'text': text.replace('\n', '\n\t')} - msg_str = log._safeFormat('%(text)s\n', fmt_dict) - - logging.debug(str(event)) + logging.basicConfig(level=logging_level, + format=log_format, + datefmt=date_format, + filemode='a') - util.untilConcludes(self.write, time_str + ' ' + socket.gethostname() + ' ' + msg_str) - util.untilConcludes(self.flush) + observer = log.PythonLoggingObserver() + observer.start() |