-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add logging_util and rotating log archive for uiserver logs #376
Conversation
Codecov Report
@@ Coverage Diff @@
## master #376 +/- ##
==========================================
+ Coverage 79.15% 79.72% +0.56%
==========================================
Files 11 12 +1
Lines 1118 1159 +41
Branches 215 219 +4
==========================================
+ Hits 885 924 +39
- Misses 195 197 +2
Partials 38 38
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Tested, works well.
Nice, tested with single & multi user modes, rollover worked for both even when interleaved. |
cylc/uiserver/logging_util.py
Outdated
"""Increment the log number by one for each log""" | ||
# increments each log number, done in descending order to avoid | ||
# filename conflicts |
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.
style suggestion
"""Increment the log number by one for each log""" | |
# increments each log number, done in descending order to avoid | |
# filename conflicts | |
"""Increment the log number by one for each log. | |
Increments each log number, done in descending order to avoid | |
filename conflicts. | |
""" |
self.file_path, f"*{self.LOG_NAME_EXTENSION}")), reverse=True) | ||
for file in log_files: | ||
log_num = int(Path(file).name.partition('-')[0]) + 1 | ||
new_file_name = Path( |
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 can't you just
if log_num > 5:
file.unlink()
And never create the older archive members?
cylc/uiserver/scripts/hub.py
Outdated
@@ -24,7 +24,7 @@ | |||
|
|||
from cylc.uiserver import ( | |||
__version__, | |||
__file__ as uis_pkg | |||
__file__ as uis_pkg, |
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.
Any particular reason?
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.
No, I initially added init_log to this import. I'll remove.
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.
FYI: trailing commas [perfectly valid] are a signal to black
to leave room for further additions so can be considered functional. Although we don't use black I use trailing commas as a matter of course.
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.
So do I; it was more that I was curious that this had been changed at all for this PR.
for file in [ | ||
'03-uiserver.log', | ||
'01-uiserver.log', | ||
'04-uiserver.log', | ||
'02-uiserver.log', | ||
'05-uiserver.log', | ||
'07-uiserver.log', | ||
'06-uiserver.log' | ||
]: |
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.
You could make these tests a bit smaller if you wished to:
for file in [ | |
'03-uiserver.log', | |
'01-uiserver.log', | |
'04-uiserver.log', | |
'02-uiserver.log', | |
'05-uiserver.log', | |
'07-uiserver.log', | |
'06-uiserver.log' | |
]: | |
for file in [f'{i:d02}-uiserver.log' for i in range(1,7)] |
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 was making them intentionally out of numerical order.
]: | ||
log_file = LOG.file_path.joinpath(file) | ||
log_file.touch() | ||
log_file.write_text(f"File: {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.
I find this easier to understand?
log_file.write_text(f"File: {file}") | |
log_file.write_text(f"This file started as: {file}") |
f'{LOG.file_path}/03-uiserver.log', | ||
f'{LOG.file_path}/02-uiserver.log'] | ||
assert sorted(log_files) == sorted(expected_files) | ||
actual_output = Path(LOG.file_path/'03-uiserver.log').read_text() # LOG.file_path/{03-uiserver.log} |
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.
What's the comment for?
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'll remove.
log_files = sorted(glob(os.path.join( | ||
self.file_path, f"*{self.LOG_NAME_EXTENSION}")), reverse=True) | ||
for file in log_files: | ||
log_num = int(Path(file).name.partition('-')[0]) + 1 |
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.
You might want to consider using a try/except loop around this, or making the glob a bit more careful ([0-9]*{self.LOG_NAME_EXTENSION}
).
Otherwise I can break this thus:
touch ~/.cylc/uiserver/log/iduhafiuhbjvfaiehr-uiserver.log
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.
Good spot, unlikely but worth fixing.
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 looks like it's working, apart from my destructive testing where I added fkjaiuj-uiserver.log
to the log directory.
I've made a few suggestions of the mild/moderate sort.
@wxtim I've done a small refactor to address your comments. |
Logs for the uiserver can now be found in
~/.cylc/uiserver/log
These changes close #352
When a new instance is started, the previous log is archived. The archive will retain the last 5 logs.
For convenience, and to keep functionality similar to cylc flow, a log symlink, linking to the latest log has been added.
Requirements check-list
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
.