Add verbosity control with -v/-q flags and logging integration#122
Conversation
- Added -v (verbose) and -q (quiet) flags that count - Set up logging configuration based on net verbosity (v_count - q_count) - Replaced err() and warn() functions to use logging module - Replaced diagnostic print statements in report.nw with logging calls - Added logging import to cli.nw and report.nw - Logging levels: CRITICAL (-qq), ERROR (-q), WARNING (default), INFO (-v), DEBUG (-vv) Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
- Added DEBUG logging for session restoration and credential loading - Added INFO logging for session creation and successful operations - Removed local -v flag from report command (conflicts with global -v) - Now use global verbosity levels consistently across all commands - Added logging for cache operations and credential source detection Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
- Remove unused logger variable in cli.nw (use module-level logging directly) - Improve debug message clarity in report.nw (more descriptive language) - Better readability for log messages Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
- Clarify documentation about -v flag being repeatable - Update CRITICAL level description to be more precise - Add check to prevent reconfiguring logging if already configured - Improves robustness when used as a library Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
…sses - Added logging import to ladok3.nw - Created LoggingSessionWrapper class to wrap session and log all HTTP requests - Added DEBUG level logging for all API calls (method, URL, status code) - Added INFO level logging for cache hits and misses in: - get_grade_scales - get_student - search_course_rounds - Wrapped session after retry policy configuration Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
Added logging for API calls and cache performance (commit ee33036): DEBUG level:
INFO level:
Example output with |
- Fixed chunk definition to actually apply the wrapper to self.__session - Now all HTTP requests through the session are logged at DEBUG level - Wrapper is applied after retry policy configuration Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
| We add INFO level logging to indicate cache hits and misses for better | ||
| observability of the caching behavior. | ||
| <<LadokSession data methods>>= | ||
| @cachetools.cachedmethod( | ||
| operator.attrgetter("cache"), | ||
| key=functools.partial(cachetools.keys.hashkey, "grade_scale")) | ||
| def get_grade_scales(self, /, **kwargs): | ||
| """Return a list of (un)filtered grade scales""" | ||
| if len(kwargs) == 0: | ||
| cache_key = "grade_scale" | ||
| if cache_key in self.cache: | ||
| logging.info(f"Cache hit for grade scales") | ||
| else: | ||
| logging.info(f"Cache miss for grade scales, fetching from LADOK") | ||
| return [GradeScale(**scale_data) | ||
| for scale_data in self.grade_scales_JSON()] |
There was a problem hiding this comment.
@copilot this will not work. Only misses can be logged like this. Since the method will not run for a cache hit. But that is fine, can't do better anyways.
There was a problem hiding this comment.
Fixed in commit 3c0f9ee. Removed the cache hit check and updated documentation to clarify that only cache misses can be logged (since the decorator returns cached values before the method body executes).
| cache_key = cachetools.keys.hashkey("get_student", id) | ||
| if cache_key in self.cache: | ||
| logging.info(f"Cache hit for student {id}") | ||
| else: | ||
| logging.info(f"Cache miss for student {id}, fetching from LADOK") |
There was a problem hiding this comment.
@copilot same here. Only useful for logging cache misses. Cachetools takes all the hits.
There was a problem hiding this comment.
Fixed in commit 3c0f9ee. Removed the cache hit check and added a comment explaining only misses are logged.
| if cache_key in self.cache: | ||
| logging.info(f"Cache hit for search_course_rounds({kwargs})") | ||
| else: | ||
| logging.info(f"Cache miss for search_course_rounds({kwargs}), fetching from LADOK") |
There was a problem hiding this comment.
Fixed in commit 3c0f9ee. Removed the cache hit check and added a comment explaining the limitation.
- Removed incorrect cache hit logging (decorator handles hits before method executes) - Updated documentation to explain only cache misses can be logged - Simplified code by removing unnecessary cache key checks - Applies to get_grade_scales, get_student, and search_course_rounds Co-authored-by: dbosk <237222+dbosk@users.noreply.github.com>
All inline comments have been addressed in commit 3c0f9ee. Cache logging now only logs misses, and documentation has been updated to explain why cache hits cannot be logged from within the cached methods. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Plan: Add verbosity options and logging support ✅ COMPLETE
-v(verbose) and-q(quiet) flags to CLI that count and subtract (net verbosity = v_count - q_count)Summary
Successfully implemented comprehensive verbosity control and API logging for the LADOK CLI:
-v/-qflags control diagnostic output across all commandsCache Logging Behavior
Note: Cache hits cannot be logged from within cached methods because the
@cachetools.cachedmethoddecorator returns cached values before the method body executes. Only cache misses are logged when the method actually runs and fetches from LADOK.Implementation Complete ✅
All requirements from the issue and PR comments have been met.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.