Skip to content

Commit

Permalink
Move call logging.basicConfig in only console run (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyline-gleb authored Aug 8, 2017
1 parent 26584fa commit 88b3f4a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
6 changes: 6 additions & 0 deletions stf_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
import logging


def init_console_logging(level):
logging.basicConfig(level=getattr(logging, level.upper()))
15 changes: 3 additions & 12 deletions stf_utils/stf_connect/stf_connect.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
# -*- coding: utf-8 -*-

import os
import argparse
import json
import logging
import signal
import sys
import time

from stf_utils import init_console_logging
from stf_utils.config.config import Config
from stf_utils.stf_connect.client import SmartphoneTestingFarmClient, STFDevicesConnector, STFConnectedDevicesWatcher

LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
logging.basicConfig(level=getattr(logging, LOG_LEVEL))
log = logging.getLogger(__name__)


DEFAULT_CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".stf-utils", "stf-utils.ini")


def set_log_level(_log_level):
if _log_level:
log.debug("Changed log level to {0}".format(_log_level.upper()))
log.setLevel(_log_level.upper())


class STFConnect:
def __init__(self, config, device_spec):
self.client = SmartphoneTestingFarmClient(
Expand Down Expand Up @@ -95,7 +86,7 @@ def parse_args():
"-g", "--groups", help="Device groups defined in spec file to connect"
)
parser.add_argument(
"-l", "--log-level", help="Log level"
"-l", "--log-level", help="Log level (default: INFO)", default="INFO"
)
parser.add_argument(
"-c", "--config", help="Path to config file (default: ~/.stf-utils/stf-utils.ini)", default=DEFAULT_CONFIG_PATH
Expand All @@ -121,7 +112,7 @@ def exit_gracefully(signum, frame):

def run():
args = parse_args()
set_log_level(args.log_level)
init_console_logging(args.log_level)

try:
config = Config(args.config)
Expand Down
14 changes: 6 additions & 8 deletions stf_utils/stf_record/stf_record.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
# -*- coding: utf-8 -*-

import argparse
import asyncio
import json
Expand All @@ -9,12 +10,12 @@

import functools
import os

from stf_utils import init_console_logging
from stf_utils.common.stfapi import SmartphoneTestingFarmAPI
from stf_utils.config.config import initialize_config_file
from stf_utils.stf_record.protocol import STFRecordProtocol

LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
logging.basicConfig(level=getattr(logging, LOG_LEVEL))
log = logging.getLogger(__name__)


Expand Down Expand Up @@ -126,7 +127,7 @@ def get_ws_url(api, args):
"-r", "--resolution", help="Resolution of images"
)
parser.add_argument(
"-l", "--log-level", help="Log level"
"-l", "--log-level", help="Log level (default: INFO)", default="INFO"
)
parser.add_argument(
"-k", "--keep-old-data", help="Do not clean old data from directory", action="store_true", default=False
Expand All @@ -136,13 +137,10 @@ def get_ws_url(api, args):
)

args = vars(parser.parse_args())
init_console_logging(args["log_level"])
config_file = args["config"]
config = initialize_config_file(config_file)

if args["log_level"]:
log.debug("Changed log level to {0}".format(args["log_level"].upper()))
log.setLevel(args["log_level"].upper())

api = SmartphoneTestingFarmAPI(
host=config.main.get("host"),
common_api_path="/api/v1",
Expand Down

0 comments on commit 88b3f4a

Please sign in to comment.