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

Eliminate missing_file usage in logging code #1212

Merged
merged 2 commits into from
Jul 4, 2023
Merged
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
1 change: 0 additions & 1 deletion syscore/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def __repr__(self):
return self._name


missing_file = named_object("missing file")
market_closed = named_object("market closed")
fill_exceeds_trade = named_object("fill too big for trade")
arg_not_supplied = named_object("arg not supplied")
Expand Down
13 changes: 7 additions & 6 deletions syslogdiag/log_to_file.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from os.path import join as join_file_and_path

from syscore.constants import missing_file
from syscore.fileutils import get_resolved_pathname, does_resolved_filename_exist

from sysdata.config.production_config import get_production_config
Expand Down Expand Up @@ -91,20 +90,22 @@ def email_user(self, log_entry: logEntry):
)

def close_log_file(self):
file_handle = getattr(self, "_file_handle", None)
if file_handle is None:
try:
file_handle = getattr(self, "_file_handle")
except AttributeError:
## no file, logging won't work
print("No log file open to close")
else:
file_handle.close()

## force reopen on new log
self._file_handle = missing_file
delattr(self, "_file_handle")

@property
def log_file_handle(self):
file_handle = getattr(self, "_file_handle", missing_file)
if file_handle is missing_file:
try:
file_handle = getattr(self, "_file_handle")
except AttributeError:
filename = self.log_filename_with_path
file_handle = open(filename, "a", 5)

Expand Down