-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature/logging #85
Feature/logging #85
Changes from 10 commits
c01055b
0bbb959
53c15d4
f2a2fe4
0d5b989
cc7b83c
7706566
d9fb0ab
dc2ead7
11c3a80
38ff22e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import os | ||
import getpass | ||
import logging | ||
import os | ||
import shutil | ||
import socket | ||
import sys | ||
import time | ||
|
||
from mcpartools.mcengine.common import EngineDiscover | ||
from mcpartools.scheduler.common import SchedulerDiscover | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
file_logger = logging.getLogger('file_logger') | ||
file_logger.setLevel(logging.INFO) | ||
file_logger.propagate = False | ||
|
||
|
||
class Options: | ||
|
||
|
@@ -139,7 +146,7 @@ def run(self): | |
# make symlinks to external files found | ||
self.symlink_external_files() | ||
|
||
# save logs | ||
# store information about command line arguments, date, time, user and hostname into generatemc.log | ||
self.save_logs() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see the point of having Do not hesitate to question existing architecture because then you fall in trap like "I did it in |
||
|
||
return 0 | ||
|
@@ -159,6 +166,8 @@ def generate_main_dir(self): | |
os.mkdir(dir_path) | ||
self.main_dir = dir_path | ||
|
||
file_logger.addHandler(logging.FileHandler(os.path.join(dir_path, "generatemc.log"), mode='w+')) | ||
|
||
def generate_workspace(self): | ||
wspdir_name = 'workspace' | ||
wspdir_path = os.path.join(self.main_dir, wspdir_name) | ||
|
@@ -225,4 +234,7 @@ def symlink_external_files(self): | |
os.symlink(abs_path, os.path.join(jobdir_path, os.path.split(abs_path)[-1])) | ||
|
||
def save_logs(self): | ||
pass | ||
file_logger.info('Executed command: ' + ' '.join(sys.argv)) | ||
file_logger.info('Date and time: ' + time.strftime("%Y-%m-%d %H:%M:%S")) | ||
file_logger.info('username@hostname: ' + getpass.getuser() + '@' + socket.gethostname()) | ||
file_logger.info('Current working directory: ' + os.getcwd()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import logging | ||
import os | ||
from subprocess import check_call, CalledProcessError | ||
from subprocess import check_output, CalledProcessError | ||
|
||
from mcpartools.scheduler.slurm import Slurm | ||
from mcpartools.scheduler.torque import Torque | ||
|
@@ -16,17 +15,17 @@ def __init__(self): | |
|
||
@classmethod | ||
def get_scheduler(cls, scheduler_options, log_location): | ||
with open(os.path.join(log_location, "generatemc.log"), 'w+') as LOG_FILE: | ||
try: | ||
check_call(['srun --version'], stdout=LOG_FILE, stderr=LOG_FILE, shell=True) | ||
logger.debug("Discovered job scheduler SLURM") | ||
return Slurm(scheduler_options) | ||
except CalledProcessError as e: | ||
logger.debug("Slurm not found: %s", e) | ||
try: | ||
check_call(['qsub --version'], stdout=LOG_FILE, stderr=LOG_FILE, shell=True) | ||
logger.debug("Discovered job scheduler Torque") | ||
return Torque(scheduler_options) | ||
except CalledProcessError as e: | ||
logger.debug("Torque not found: %s", e) | ||
file_logger = logging.getLogger('file_logger') | ||
try: | ||
file_logger.info(check_output(['srun --version'], shell=True)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am correct check_output returns output of the command.
|
||
logger.debug("Discovered job scheduler SLURM") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's debug logging level - I would add slurm/torque version to this log too. Same in line 29. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is already saved to the file (but not printed on screen), even on debug level:
|
||
return Slurm(scheduler_options) | ||
except CalledProcessError as e: | ||
logger.debug("Slurm not found: %s", e) | ||
try: | ||
file_logger.info(check_output(['qsub --version'], shell=True)) | ||
logger.debug("Discovered job scheduler Torque") | ||
return Torque(scheduler_options) | ||
except CalledProcessError as e: | ||
logger.debug("Torque not found: %s", e) | ||
raise SystemError("No known batch system found!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please sort imports.
https://google.github.io/styleguide/pyguide.html#Imports_formatting