Skip to content

Commit f4ea206

Browse files
committed
logging of initialization
1 parent 83dc753 commit f4ea206

7 files changed

Lines changed: 16 additions & 25 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.venv
2+
nosetests.xml
23
__pycache__

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ install-venv:
1818
test ! -e requirements.txt || ($(VENV_RUN); $(PIP_CMD) -q install -r requirements.txt)
1919

2020
test:
21-
($(VENV_RUN); DEBUG=$(DEBUG) PYTHONPATH=`pwd` nosetests $(NOSE_ARGS) --with-timer --with-coverage --logging-level=$(NOSE_LOG_LEVEL) --nocapture --no-skip --exe --cover-erase --cover-tests --cover-inclusive --cover-package=localstack --with-xunit --exclude='$(VENV_DIR).*' --ignore-files='lambda_python3.py' $(TEST_PATH))
21+
($(VENV_RUN); DEBUG=$(DEBUG) PYTHONPATH=`pwd` nosetests $(NOSE_ARGS) --with-timer --logging-level=$(NOSE_LOG_LEVEL) --nocapture --no-skip --exe --cover-erase --cover-tests --cover-inclusive --cover-package=localstack --with-xunit --exclude='$(VENV_DIR).*' --ignore-files='lambda_python3.py' $(TEST_PATH))

common_utils.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

localstack.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
# DEFAULT_PORT_PATTERN = re.compile("'(\\w+)'\\Q: '{proto}://{host}:\\E(\\d+)'")
1717

1818
localstack_instance = None
19-
LOG = logging.getLogger(__name__);
20-
19+
logging.basicConfig(level=logging.INFO, format='%(message)s')
2120

2221
class Localstack:
2322

@@ -61,21 +60,17 @@ def startup(self, docker_configuration) :
6160
raise "Unable to start docker"
6261

6362
except:
64-
error = sys.exc_info()
65-
print(error)
63+
raise sys.exc_info()
64+
6665

6766
def stop(self):
68-
try:
69-
self.localstack_container.stop()
70-
except:
71-
error = sys.exc_info()
72-
print(error)
67+
self.localstack_container.stop()
68+
7369

7470
def setup_logger(self):
7571
localstack_logger = LocalstackLogger(self.localstack_container)
7672
localstack_logger.start()
7773

78-
# @param services
7974
def startup_localstack(port=4566, services=[], ignore_docker_errors = False):
8075
global localstack_instance
8176
localstack_instance = Localstack.INSTANCE()
@@ -85,7 +80,6 @@ def startup_localstack(port=4566, services=[], ignore_docker_errors = False):
8580
config.envirement_variables.update({'SERVICES': ','.join(services)})
8681
if port != 4566:
8782
config.port_edge = str(port)
88-
8983
config.ignore_docker_runerrors = ignore_docker_errors
9084

9185
localstack_instance.startup(config)

localstack_docker/container.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
DEFAULT_CONTAINER_ID = "localstack_main"
2121

2222
DOCKER_CLIENT = docker.from_env()
23-
LOG = logging.getLogger(__name__);
2423

2524
class Container:
2625

@@ -36,7 +35,7 @@ def create_localstack_container(external_hostname, pull_new_image, randomize_por
3635
fullPortEdge = {(LOCALSTACK_PORT_EDGE if port_edge == None else port_edge) : (LOCALSTACK_PORT_EDGE)}
3736

3837
if pull_new_image or not image_exists:
39-
LOG.info("Pulling latest image")
38+
logging.info("Pulling latest image")
4039
DOCKER_CLIENT.images.pull(image_name_or_default, image_tag)
4140

4241
return DOCKER_CLIENT.containers.run(image_name_or_default, ports=fullPortEdge, environment=environment_variables, detach=True)
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import threading
22
import logging
33

4-
LOG = logging.getLogger(__name__);
5-
64
class LocalstackLogger():
75
stream = None
6+
log_thread = None
87
def __init__(self, localsack_container) -> None:
9-
stream = localsack_container.logs(stream=True, follow=True)
10-
8+
self.stream = localsack_container.logs(stream=True, follow=True)
119

1210
def start(self):
13-
log_thread = threading.Thread(target=log_stream,args=[self.stream])
11+
self.log_thread = threading.Thread(target=log_stream,args=[self.stream]).start()
1412

1513
def log_stream(stream):
1614
try:
17-
print("starting logs")
1815
while True:
19-
line = next(stream).decode("utf-8")
20-
LOG.warning(line)
16+
line = next(stream).decode("utf-8").replace("\n",'')
17+
logging.info(line)
2118
except StopIteration:
22-
print("LOGS ENDED")
19+
pass

tests/kinesis_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import boto3
33
import unittest
44
from localstack import startup_localstack, stop_localstack
5+
56
class kinesis_test(unittest.TestCase):
67
def setUp(self):
78
startup_localstack()
@@ -19,7 +20,7 @@ def test_create_stream(self):
1920
endpoint_url='http://localhost:4566')
2021

2122
kinesis.create_stream(StreamName='test', ShardCount=1)
22-
time.sleep(10)
23+
time.sleep(5)
2324

2425
response = kinesis.list_streams()
2526
self.assertGreater(len(response.get('StreamNames', [])),0)

0 commit comments

Comments
 (0)