-
Notifications
You must be signed in to change notification settings - Fork 6
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
Date filter, logging and types #26
Merged
jtaleric
merged 6 commits into
cloud-bulldozer:main
from
shashank-boyapally:data-filter
Jul 10, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d315a8a
added logging, date filter and types
shashank-boyapally 9d805f0
added types for constructor
shashank-boyapally 4836266
add pull request to workflows, add new unit test
shashank-boyapally d2fa1c0
pylint error
shashank-boyapally c1f7f68
bumped version
shashank-boyapally 24a9497
updated utility for functional testing
shashank-boyapally 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
name: Run pytest on Pull Request | ||
|
||
on: [push] | ||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
|
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 @@ | ||
""" | ||
Logger as a common package | ||
""" | ||
|
||
import logging | ||
import sys | ||
|
||
|
||
class SingletonLogger: | ||
"""Singleton logger to set logging at one single place | ||
|
||
Returns: | ||
_type_: _description_ | ||
""" | ||
|
||
instance = {} | ||
|
||
def __new__(cls, debug: int, name: str): | ||
if (not cls.instance) or name not in cls.instance: | ||
cls.instance[name] = cls._initialize_logger(debug,name) | ||
return cls.instance[name] | ||
|
||
@staticmethod | ||
def _initialize_logger(debug: int, name: str) -> logging.Logger: | ||
level = debug # if debug else logging.INFO | ||
logger = logging.getLogger(name) | ||
logger.propagate=False | ||
if not logger.hasHandlers(): | ||
logger.setLevel(level) | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setLevel(level) | ||
formatter = logging.Formatter( | ||
"%(asctime)s - %(name)-10s - %(levelname)s - file: %(filename)s - line: %(lineno)d - %(message)s" # pylint: disable = line-too-long | ||
) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
return logger | ||
|
||
@classmethod | ||
def getLogger(cls, name:str) -> logging.Logger: | ||
"""Return logger in instance | ||
|
||
Args: | ||
name (str): name of the logger | ||
|
||
Returns: | ||
logging.Logger: logger | ||
""" | ||
return cls.instance.get(name, None) |
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
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.
I don't think we need a singleton class here. It just as simple as updating a config.
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.
Thank you for the suggestion. The thought behind this was as follows: having a logger setup in Matcher class created duplicate logs of the same log-output, especially in daemon mode where multiple Matcher objects would be created as when the request would come in and multiple formatters were being attached to the logger which led to duplicate logs. To mitigate this a temporary solution was to check if the logger existed previously. I transferred this logic to a class so that it can be used in Orion as well. The SingletonLogger here also updates the config using methods and also keeps track of only having a single 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.
logging is singleton by default. All I am saying is, I think we need not write a custom logging class instead of just using the existing ones.