-
Notifications
You must be signed in to change notification settings - Fork 0
ioana.circu - logging #4
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
Changes from 4 commits
bf4dd9d
2bfc093
b6bdc8a
ce0d1e2
777576e
5e9f851
6057ab9
623b29b
4550a2b
3c826d9
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,4 +1,6 @@ | ||
| # Directory containing new flights to be pushed to Elasticsearch | ||
| /home/badc/software/datasets/flight-finder/add_records/ | ||
| /home/users/icircu/flight-pipeline/add/ | ||
| # Directory for moving written flights - write DELETE to remove pushed flight records from the local system after pushing. | ||
| /home/badc/software/datasets/flight-finder/stac-flightfinder-items/ | ||
| /home/users/icircu/test-flights/ | ||
| # Logging File | ||
| /home/users/icircu/test-flights/logging |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import logging | ||
|
|
||
| def setup_logging(enable_logging=True, console_logging=True): | ||
|
Collaborator
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. Adding this comment here but it can apply in many places. Consider using type hints for the parameters of functions. In this case If multiple variable types are acceptable, you can use the following: |
||
| """ | ||
| Sets up logging configuration. If `enable_logging` is False, no logging will occur. | ||
| :param enable_logging: Flag to enable/disable logging. | ||
| """ | ||
|
|
||
| f = open('dirconfig','r') | ||
|
||
| content = f.readlines() | ||
| f.close() | ||
|
|
||
| log_file = content[5].replace('\n','') | ||
|
|
||
| if log_file == '': | ||
| print("Error: Please fill in the third directory in dirconfig file") | ||
|
|
||
| handlers = [ | ||
| logging.FileHandler(log_file), # Write output to file | ||
| ] | ||
|
|
||
| if console_logging: | ||
| handlers.append(logging.StreamHandler()) # Logs to the console if enabled | ||
|
|
||
|
|
||
| if enable_logging: | ||
| logging.basicConfig( | ||
| level=logging.DEBUG, # Capture all levels | ||
| format='%(asctime)s - %(levelname)s - %(message)s', | ||
| handlers=handlers | ||
| ) | ||
| else: | ||
| # Disable logging by setting a null handler | ||
| logging.basicConfig(level=logging.CRITICAL) | ||
| #NOTSET for no alerts at all | ||
|
|
||
|
|
||
| enable_logging = True | ||
|
|
||
| # Set up logging with a flag (True to enable logging, False to disable logging) | ||
| setup_logging(enable_logging) # Change to False to disable logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
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.
Don't need the
Debug:part of the string if your log message already adds this.