Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter logs #27

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/cumulus/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"mysql": "mysqld"}
DOCKER_COMPOSE_VERSION = '3.6'


def main():
"""Main CLI entrypoint."""
import commands
Expand All @@ -63,8 +62,8 @@ def main():
for command in commands if command[0] != 'Base'][0]
command = command(options)
command.run()
clean_logs()
return

exit(__doc__)


Expand Down
14 changes: 11 additions & 3 deletions src/cumulus/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ def init_container(service, all_services):
"-e", "CUMULUS_SERVICES={}".format(",".join(all_services)),
service, "INIT"
]

subprocess.call(docker_compose_run_command)
subprocess.call([DOCKER_COMPOSE, "rm", "-f", service])
with open(LOGFILE, 'a+') as log_file:
log_time_string = '\n\n{0}\n'.format(datetime.now().strftime('%m-%d-%Y %H:%M:%S'))
log_file.write(log_time_string)
with open(LOGFILE, 'a') as log_file:
print ('Initializing {0}...'.format(service))
return_code1 = subprocess.call(docker_compose_run_command, stdout=log_file, stderr=subprocess.STDOUT)
return_code2 = subprocess.call([DOCKER_COMPOSE, "rm", "-f", service], stdout=log_file, stderr=subprocess.STDOUT)
if not return_code1 and not return_code2:
print ("{0} initialized! \nRun 'cumulus start <service>' to start the container".format(service))
else:
print ("Error initializing {0}. Check docker-compose-log.out for more details.".format(service))

def get_and_set_project(self, doc, clean):
compose_tree = {}
Expand Down
12 changes: 12 additions & 0 deletions src/cumulus/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import yaml
import subprocess
from collections import defaultdict
from datetime import datetime

DOCKER = "docker"

Expand All @@ -13,6 +14,7 @@
SUPPORTED = WEB_APP + DATABASE + OTHER_SUPPORTED
NEED_INIT = WEB_APP + DATABASE
HAS_CUMULUS_IMAGE = ["mysql", "django"]
LOGFILE = "docker-compose-log.out"
SUPPORTED_BUT_NO_CUMULUS_IMAGE = {
"redis": "redis", "elasticsearch": "docker.elastic.co/elasticsearch/elasticsearch:6.3.1", "memcached": "memcached"}

Expand Down Expand Up @@ -133,3 +135,13 @@ def notify_active_port():
', '.join(addresses)))
except yaml.YAMLError as exc:
print(exc)

# Clean garbage (docker ansi color logs) out of log file
def clean_logs():
with open(LOGFILE, 'r+') as log_file:
lines = log_file.readlines()
log_file.seek(0)
for line in lines:
if '\x1b' not in line:
log_file.write(line)
log_file.truncate()