Skip to content

Save save - #77

Open
Sidartha-CT wants to merge 5 commits into
masterfrom
save_save
Open

Save save#77
Sidartha-CT wants to merge 5 commits into
masterfrom
save_save

Conversation

@Sidartha-CT

Copy link
Copy Markdown
Collaborator

No description provided.

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>
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.

1 participant