-
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
Conversation
@PanSzczerba why do I see my commits in the list https://github.com/DataMedSci/mcpartools/pull/85/commits ? Is your fork and your master branch up-to-date with https://github.com/DataMedSci/mcpartools ? |
Fix PEP8 issues https://travis-ci.org/DataMedSci/mcpartools/jobs/268642089 |
Codecov Report
@@ Coverage Diff @@
## master #85 +/- ##
==========================================
+ Coverage 63.98% 64.32% +0.34%
==========================================
Files 12 12
Lines 844 855 +11
==========================================
+ Hits 540 550 +10
- Misses 304 305 +1
Continue to review full report at Codecov.
|
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.
Before continuing, please ensure that you did the PR correctly. First two commits in this PR shouldn't be here.
mcpartools/generator.py
Outdated
@@ -111,6 +114,9 @@ def run(self): | |||
# make symlinks to external files found | |||
self.symlink_external_files() | |||
|
|||
# store information about command line arguments, date, time, user and hostname into generatemc.log | |||
self.log() | |||
|
|||
# save logs | |||
self.save_logs() |
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.
I do not see the point of having self.log
followed by self.save_logs
. If both aim at doing the same then why not merging them ? If they do sth else, then write better comments.
Do not hesitate to question existing architecture because then you fall in trap like "I did it in log
cause I didn't know what save_log
was meant to do"
mcpartools/generator.py
Outdated
@@ -190,3 +196,13 @@ def symlink_external_files(self): | |||
|
|||
def save_logs(self): | |||
pass | |||
|
|||
def log(self): | |||
with open(os.path.join(self.main_dir, "generatemc.log"), 'a') as LOG_FILE: |
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.
Why LOG_FILE is capitalized ?
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.
Ok so should I create a new pull request without them?
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.
It depends on your git knowledge. Your branch history is broken, see:
https://github.com/PanSzczerba/mcpartools/commits/feature/logging
Why commits b8c0b28 and f480569 are there under 26 of August ?
You can edit your commits history and do push --force
or do new branch and new PR.
7e25a1b
to
75ae913
Compare
…mand line arguments, date, time, user and hostname in generatemc.log
75ae913
to
53c15d4
Compare
Ok, so I think it should be fine right now. I have fixed commit history and did some minor changes You asked |
mcpartools/generator.py
Outdated
log_file.write("\n") | ||
log_file.write(time.strftime("%Y-%m-%d %H:%M:%S\n")) | ||
log_file.write(getpass.getuser() + '@' + socket.gethostname() + "\n") | ||
log_file.write(os.getcwd() + "\n") |
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.
Add some description what is being logged, like:
Command executed:
Date & time:
User@hostname:
Current directory:
mcpartools/generator.py
Outdated
@@ -225,4 +228,10 @@ 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 | |||
with open(os.path.join(self.main_dir, "generatemc.log"), 'a') as log_file: |
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.
filename "generatemc.log" occurs now twice, see also here:
mcpartools/mcpartools/scheduler/common.py
Line 19 in 35d92ad
with open(os.path.join(log_location, "generatemc.log"), 'w+') as LOG_FILE: |
with open(os.path.join(log_location, "generatemc.log"), 'w+') as LOG_FILE:
try:
What about unifying this ?
Can it be done in some generic way ?
Would it be possible to use python logging to write to such a file in some standarized way ?
See logging handlers https://docs.python.org/3.5/library/logging.html
Ok so I tried using logging module. But I had to create another logger with it's own handler and I don't know if that's a good idea. |
Maybe this could help: |
mcpartools/generator.py
Outdated
@@ -159,6 +166,8 @@ def generate_main_dir(self): | |||
os.mkdir(dir_path) | |||
self.main_dir = dir_path | |||
|
|||
generatemc_logger.addHandler(logging.FileHandler(os.path.join(dir_path, "generatemc.log"), mode='w+')) |
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.
why "generatemc.log" occurs here and also in 'getLogger' method ?
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.
I wanted to add FileHandler directly after the main_dir path is assigned so it could log information about batch system in scheduler/common.py. And also I wanted to name this logger to be unique and so I could acces it in scheduler/common.py but I couldn't come up with a better idea how to name it.
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.
Well, it could be named file_logger
(the variable) and the logger name also file_logger
mcpartools/generator.py
Outdated
@@ -2,12 +2,19 @@ | |||
import logging | |||
import shutil | |||
import time | |||
import sys | |||
import getpass | |||
import socket |
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
Within each grouping, imports should be sorted lexicographically, ignoring case, according to each module's full package path.
…rtools into feature/logging Conflicts: mcpartools/scheduler/common.py
mcpartools/scheduler/common.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
If I am correct check_output returns output of the command.
Please assign it first to the some variable, i.e. and log it with some description:
srun_output = check_output(...)
file_logger.info("srun info {:s}".format(...))
``
mcpartools/scheduler/common.py
Outdated
@@ -17,13 +17,15 @@ def __init__(self): | |||
def get_scheduler(cls, scheduler_options, log_location): | |||
file_logger = logging.getLogger('file_logger') | |||
try: | |||
file_logger.info(check_output(['srun --version'], shell=True)) | |||
srun_output = check_output(['srun --version'], shell=True) | |||
file_logger.info("srun output: {}".format(srun_output[:-1])) | |||
logger.debug("Discovered job scheduler SLURM") |
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.
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 comment
The 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:
# plgkongruencj at p1728 in /net/scratch/people/plgkongruencj/mcpartools on git:feature/logging ✖︎ [11:44:29]
→ cat aa/run_20170829_114429/generatemc.log
srun output: slurm 17.02.7
Executed command: mcpartools/generatemc.py -j 10 -p 100 tests/res/shieldhit -w aa -vvv
Date and time: 2017-08-29 11:44:29
username@hostname: plgkongruencj@p1728
Current working directory: /net/scratch/people/plgkongruencj/mcpartools
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.
I approve this PR as it is
The issue is however not closed, there are more tasks to be done, which I will define on issue level.
Added new log method in generator.py implementing features from "better logging" issue