Save save - #77
Open
Sidartha-CT wants to merge 5 commits into
Open
Conversation
Registers 4 custom log levels, one per REST verb, the same way logging registers DEBUG/INFO/WARNING/etc, so callers do logger.log(GET, ...) / log(POST, ...) / etc and %(levelname)s in a format string already reads GET/POST/PUT/DELETE. Deliberately does not monkey-patch logging.Logger with .get()/.post()/.put()/.delete() convenience methods -- that would mutate stdlib behavior for every logger in the process just from importing this module, and is unnecessary when logger.log(level, message) does the same thing explicitly. Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
…calls LFCliBase accepts _save_api and _api_log_file_name. When enabled, __init__ eagerly calls the new module-level _get_api_logger(), which sets up a dedicated, non-propagating logger + plain FileHandler for api_log_filename (truncating it), cached via the standard logging name registry so multiple LFCliBase/Realm instances pointed at the same file share one handler instead of duplicating every line. json_get/json_post/json_put/json_delete each then call _log_api_call, which logs one line per call via logger.log(level, message) at the matching GET/POST/PUT/DELETE level from lf_logger_config (looked up through the new _API_LOG_LEVELS map), including the HTTP response code and, on error, a one-line diagnostics summary. This base implementation logs plain text; realm.Realm overrides it to format the line as CSV. LFRequest gains last_response_code/last_diagnostics, populated from the urlopen response or from the caught HTTPError/URLError, and print_diagnostics now returns the one-line summary it already builds for its own error output instead of discarding it. Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Overrides LFCliBase._log_api_call so Realm (and everything built on it, e.g. lf_webpage.py's HttpDownload) writes proper CSV -- url,payload,response_code,diagnostics -- via csv.writer for correct comma/quote escaping around JSON payloads, instead of the base class's plain-text line, logged via logger.log(level, message) at the matching GET/POST/PUT/DELETE level. timestamp/method still come for free from the api logger's own formatting. Also writes the CSV header once per file (guarded by stream position rather than a separate flag, so a second Realm/LFCliBase sharing the same cached logger doesn't duplicate it). Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Adds the CLI args, threads them through HttpDownload into the Realm it constructs, and copies the resulting CSV log into the report folder when --save_api is set. Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
Signed-off-by: Sidartha-CT <neelapu.sidartha@candelatech.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.