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

Adding detailed logs and enabling the debug level to watch every step in prod #39

Merged
merged 9 commits into from
Nov 22, 2024

Conversation

vlerkin
Copy link
Collaborator

@vlerkin vlerkin commented Nov 20, 2024

remove limited reconnection attempts; cap backoff time with 15 min; configure logs in a separate file logging_config.py that is imported to the main.py to trigger logs configuration before other modules inheret it; add debug logs to the watcher to better monitor each step

…onfigure logs in a separate file logging_config.py that is imported to the __main__.py to trigger logs configuration before other modules inheret it; add debug logs to the watcher to better monitor each step
@vlerkin vlerkin requested a review from wvengen November 20, 2024 10:45
…e modules; implement logging to be configured globally but keep separate logger for each module; add level for logging to be configurable in the config file
@wvengen
Copy link
Member

wvengen commented Nov 20, 2024

I thought this would be an easy change, but I need to dive more into this, to see the bigger picture. Hence I think this shouldn't be rushed too much then. I will try to come back to this on Thu or Fri. Thanks for your quick PR in any case!

@wvengen
Copy link
Member

wvengen commented Nov 21, 2024

Regarding where to configure logging. It must be done before the repository and launcher classes are created, because stuff happens when they are created. Maybe that is not such a good idea, perhaps these classes should only start to actually do something at a later time. But that is how it is now, and I think fine for now.

The global variables are all (or perhaps most) in api.py. Can we put the logging configuration there? e.g.

app = Flask(__name__)
config = Config()
setup_logging(level=config.scrapyd().log_level)
repository = ...

This still sets up logging when this file is loaded, but a lot happens already here when the file is loaded, that would need refactoring. If we can keep these 'side-effects' at this place, then it is already more readable / understandable.

@vlerkin
Copy link
Collaborator Author

vlerkin commented Nov 22, 2024

Yes, we can put logging to the entry point of the app, no problem, but I would also create a ticket (not urgent) to refactor this to adhere to better practices so we can discuss it as a team and maybe make it cleaner. But since we are hot fixing stuff, I can put everything together for now, no problem. Working on it.

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change, appreciated.

Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!

@@ -3,8 +3,8 @@
from .config import Config
config = Config()
from .logging_config import setup_logging
logging_level = config.scrapyd().get('logging_level', 'INFO')
setup_logging(logging_level)
log_level = config.scrapyd().get('logging_level', 'INFO')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm, and also the config option, primarily!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean exactly? I don't understand the comment, sorry.

numeric_level = logging.getLevelName(level_name)
if not isinstance(numeric_level, int):
raise ValueError(
f"Invalid logging level '{logging_level}'."
f"Invalid logging level '{log_level}'."
)
logging.basicConfig(
level=numeric_level,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need a numeric level here?
logging.setLevel accepts both number and string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numeric level is what returned by the getLevelName and yes we do need it because we validate user input. This is a normal way when we validate the input and then use the value returned by validation to move further with the code.

@wvengen wvengen merged commit d5a72a7 into q-m:main Nov 22, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants