From 9035a56fc446ce92d2f17afde330fdff71a5010a Mon Sep 17 00:00:00 2001 From: shengxiang Date: Thu, 10 Mar 2016 22:36:05 +0800 Subject: [PATCH] remove log from base.py --- atx/base.py | 34 ---------------------------------- atx/device.py | 6 ++++-- atx/logutils.py | 28 ++++++++++++++++++++++++++++ atx/patch.py | 4 ++-- 4 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 atx/logutils.py diff --git a/atx/base.py b/atx/base.py index 650c6e8..9e52651 100644 --- a/atx/base.py +++ b/atx/base.py @@ -10,21 +10,6 @@ import logging import threading - -random.seed(time.time()) -logging.basicConfig(format='%(asctime)s - %(levelname)s: %(message)s', level=logging.DEBUG) - -def getLogger(name='root'): - return logging.getLogger(name) - -log = getLogger('base') - -def makedirs(dirname): - try: - os.makedirs(dirname) - except: - pass - def dirname(name): if os.path.isabs(name): return os.path.dirname(name) @@ -67,10 +52,6 @@ def exec_cmd(*cmds, **kwargs): return r.wait() return 0 -def check_output(cmd): - #log.debug('CHECK_OUTPUT, cmd: %s' %(cmd)) - return subprocess.check_output(cmd, shell=True) - def random_name(name): out = [] for c in name: @@ -79,18 +60,3 @@ def random_name(name): out.append(c) return ''.join(out) - -def wait_until(fn, interval=0.5, max_retry=10, args=(), kwargs={}): - ''' - @return True(when found), False(when not found) - ''' - log.debug('start wait func: %s', fn.__name__) - retry = 0 - while retry < max_retry: - retry += 1 - ret = fn(*args, **kwargs) - if ret: - return ret - log.debug('wait until: %s, sleep: %s', fn.__name__, interval) - time.sleep(interval) - return None diff --git a/atx/device.py b/atx/device.py index 4aa1b1d..a70cf22 100644 --- a/atx/device.py +++ b/atx/device.py @@ -13,6 +13,7 @@ import time import threading import warnings +import logging import cv2 import numpy as np @@ -21,14 +22,15 @@ from uiautomator import Device as UiaDevice from PIL import Image -from atx import base from atx import consts from atx import errors from atx import patch +from atx import logutils +log = logutils.getLogger(__name__) # base.getLogger('devsuit') +log.setLevel(logging.DEBUG) FindPoint = collections.namedtuple('FindPoint', ['pos', 'confidence', 'method']) -log = base.getLogger('devsuit') __dir__ = os.path.dirname(os.path.abspath(__file__)) __tmp__ = os.path.join(__dir__, '__cache__') diff --git a/atx/logutils.py b/atx/logutils.py new file mode 100644 index 0000000..aa95745 --- /dev/null +++ b/atx/logutils.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# coding: utf-8 + +import logging + + +_inited = {} + +def getLogger(name): + logger = logging.getLogger(name) + if not _inited.get(name): + ch = logging.StreamHandler() + _inited[name] = ch + fmt = "%(asctime)s %(levelname)-8.8s [%(name)s:%(lineno)4s] %(message)s" + formatter = logging.Formatter(fmt) + ch.setFormatter(formatter) + logger.addHandler(ch) + return logger + + +if __name__ == '__main__': + log = getLogger('test') + log.setLevel(logging.DEBUG) + log.info("Hello") + log.debug("dd Hello") + log = getLogger('test') + log.warn("dd Hello") + diff --git a/atx/patch.py b/atx/patch.py index 553fcda..ba054f0 100644 --- a/atx/patch.py +++ b/atx/patch.py @@ -5,10 +5,10 @@ import threading from functools import partial -from atx import base +from atx import logutils -log = base.getLogger('patch') +log = logutils.getLogger(__name__) #base.getLogger('patch') def thread_safe(f): '''