-
Notifications
You must be signed in to change notification settings - Fork 58
Handle bad log names and reduce logging #794
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
base: prerelease
Are you sure you want to change the base?
Handle bad log names and reduce logging #794
Conversation
markmac99
left a comment
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.
A couple of comments:
the logger name shold be 'rmslogger' to be consistent and avoid clashes with generic loggers and 3rd party loggers. Also i think extractDateFromLogName can be simplified and made a bit more pythonic.
Utils/LogArchiver.py
Outdated
| LATEST_LOG_UPLOADS_FILE_NAME = ".latestloguploads.json" | ||
| ISO_DATE_2000 = datetime.datetime(int(2000), int(1), int(1), int(0), int(0), int(0)).isoformat() | ||
|
|
||
| log = getLogger("logger") |
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.
Use the RMS logger name here, to avoid clashes with generic loggers. See most other modules for an example.
# Get the logger from the main module
log = getLogger("rmslogger")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.
Thanks for the tip. I've made this error in other places, so I'll find and fix them all.
| log.info(f" : {log_type}") | ||
|
|
||
| # Form the set of log names where ISO_DATE_2000 is not returned | ||
| log_file_set = {f for f in os.listdir(log_dir) if extractDateFromLogName(config, f) != ISO_DATE_2000} |
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.
extractDateFromLogName is perhaps overcomplex.
i think for RMS logs we can assume the log is of the form
{purpose}_{stationid}_{ymd}_{hms}_{extras}.log
so it should be possible to ignore the 1st element, check the 2nd is a stationid, and treat the next two as a datetime in the format %Y%m%d_%H%M%S, with an exception handler to manage non-dates and malformed dates: something like
log_name_fields = log_name.split("_")
try:
if len(log_name_fields) > 3 and config.stationID.upper() == log_name_fields[1].upper():
dtstr = f'{log_name_fields[2]}_{log_name_fields[3]}'
return datetime.datetime.strptime(dtstr, '%Y%m%d_%H%M%S').isoformat()
except Exception: # handle malformed dates and non-dates
pass
return datetime.datetime(2000,1,1,0,0,0).isoformat()
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 started with code like this, but, alas, not as elegant. I did find some logs with an underscore in the {purpose} field, which broke my first attempt. However, losing those logs to gain simplicity is a good trade.
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.
How does this look?
log_name_fields = log_name.upper().split("_")
stationID_upper = config.stationID.upper()
if stationID_upper in log_name_fields:
index_date = log_name_fields.index(stationID_upper) + 1
index_time = index_date + 1
try:
if len(log_name_fields) > index_time:
dtstr = f'{log_name_fields[index_date][0:8]}_{log_name_fields[index_time][0:6]}'
return datetime.datetime.strptime(dtstr, '%Y%m%d_%H%M%S').isoformat()
except Exception:
pass
return ISO_DATE_2000
|
Putting back to draft while testing changes |
|
On test on au001b |
This is a fix for issue #793.
When a badly formed log name appears in ~/RMS_data/logs/ this causes LogArchiver to fail.
This PR removes any badly formed log names, and slightly reduces logging.
However, with this PR