-
Notifications
You must be signed in to change notification settings - Fork 39
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
Added multiprocessing logging module #169
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0547be
created custom logging module
TongguangZhang 9725d9e
renamed to avoid conflict with python logging module
TongguangZhang 89dce04
frame info extracting helper function
TongguangZhang ef430c1
logging helper functions
TongguangZhang b8a9b9a
added logging process and queue in main
TongguangZhang 63d49f9
merge conflict in video input
TongguangZhang 864410c
resolve merge conflict in video input
TongguangZhang 577add4
black formatting changes
TongguangZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule common
updated
46 files
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import inspect | ||
import logging | ||
|
||
DEBUG = logging.DEBUG | ||
INFO = logging.INFO | ||
WARNING = logging.WARNING | ||
ERROR = logging.ERROR | ||
CRITICAL = logging.CRITICAL | ||
|
||
|
||
def message_and_metadata(message, frame): | ||
function_name = frame.f_code.co_name | ||
filename = frame.f_code.co_filename | ||
line_number = inspect.getframeinfo(frame).lineno | ||
|
||
return f"[{filename} | {function_name} | {line_number}] {message}" | ||
|
||
|
||
def log_message(message, level, frame, queue): | ||
queue.queue.put((message_and_metadata(message, frame), level), block=False) |
49 changes: 49 additions & 0 deletions
49
modules/multiprocess_logging/multiprocess_logging_worker.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import datetime | ||
import logging | ||
import queue | ||
|
||
from utilities.workers import queue_proxy_wrapper | ||
from utilities.workers import worker_controller | ||
|
||
|
||
def multiprocess_logging_worker( | ||
input_queue: queue_proxy_wrapper.QueueProxyWrapper, | ||
controller: worker_controller.WorkerController, | ||
): | ||
logger = logging.getLogger("airside_logger") | ||
|
||
filename = f"logs/{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}.log" | ||
file_handler = logging.FileHandler(filename=filename, mode="w") # Handles logging to file | ||
stream_handler = logging.StreamHandler() # Handles logging to terminal | ||
|
||
formatter = logging.Formatter( | ||
fmt="%(asctime)s: [%(levelname)s] %(message)s", | ||
datefmt="%I:%M:%S", | ||
) | ||
|
||
file_handler.setFormatter(formatter) | ||
stream_handler.setFormatter(formatter) | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.DEBUG) | ||
logger.addHandler(file_handler) | ||
logger.addHandler(stream_handler) | ||
|
||
while not controller.is_exit_requested(): | ||
controller.check_pause() | ||
|
||
logging_message, level = input_queue.queue.get() | ||
|
||
if logging_message is None: | ||
break | ||
|
||
if level == logging.DEBUG: | ||
logger.debug(f"{logging_message}") | ||
elif level == logging.INFO: | ||
logger.info(f"{logging_message}") | ||
elif level == logging.WARNING: | ||
logger.warning(f"{logging_message}") | ||
elif level == logging.ERROR: | ||
logger.error(f"{logging_message}") | ||
elif level == logging.CRITICAL: | ||
logger.critical(f"{logging_message}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this so so that modules trying to log don't have to import the logging module just for the logging levels
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.
Nit: Can we create a separate file and store these values as an enum?