From cdb4df0885ae81529df1491ec3e825b3c019fafe Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Thu, 9 Mar 2017 21:12:07 +0100 Subject: [PATCH] --log-json: time property on most progress/log objects, remove is_prompt --- docs/internals/frontends.rst | 24 ++++++++++++++---------- src/borg/archive.py | 1 + src/borg/helpers.py | 4 ++-- src/borg/logger.py | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/docs/internals/frontends.rst b/docs/internals/frontends.rst index ef7731f56..da6245a2f 100644 --- a/docs/internals/frontends.rst +++ b/docs/internals/frontends.rst @@ -39,6 +39,8 @@ archive_progress Number of (regular) files processed so far path Current path + time + Unix timestamp (float) progress_message A message-based progress information with no concrete progress information, just a message @@ -53,6 +55,8 @@ progress_message can have this property set to *true*. message current progress message (may be empty/absent) + time + Unix timestamp (float) progress_percent Absolute progress information with defined end/total and current value. @@ -72,6 +76,8 @@ progress_percent Array that describes the current item, may be *null*, contents depend on *msgid* total Total value + time + Unix timestamp (float) file_status This is only output by :ref:`borg_create` and :ref:`borg_recreate` if ``--list`` is specified. The usual @@ -85,7 +91,7 @@ file_status log_message Any regular log output invokes this type. Regular log options and filtering applies to these as well. - created + time Unix timestamp (float) levelname Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL @@ -138,23 +144,21 @@ Prompts assume a JSON form as well when the ``--log-json`` option is specified. are still read verbatim from *stdin*, while prompts are JSON messages printed to *stderr*, just like log messages. -Prompts use the *question_prompt*, *question_prompt_retry*, *question_invalid_answer*, -*question_accepted_default*, *question_accepted_true*, *question_accepted_false* and -*question_env_answer* types. +Prompts use the *question_prompt* and *question_prompt_retry* types for the prompt itself, +and *question_invalid_answer*, *question_accepted_default*, *question_accepted_true*, +*question_accepted_false* and *question_env_answer* types for information about +prompt processing. The *message* property contains the same string displayed regularly in the same situation, while the *msgid* property may contain a msgid_, typically the name of the environment variable that can be used to override the prompt. It is the same for all JSON messages pertaining to the same prompt. -The *is_prompt* boolean property distinguishes informational messages from prompts, it -is true for *question_prompt* and *question_prompt_retry* types, otherwise it is false. - .. rubric:: Examples (reformatted, each object would be on exactly one line) Providing an invalid answer:: - {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "is_prompt": true, + {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "message": "... Type 'YES' if you understand this and want to continue: "} incorrect answer # input on stdin {"type": "question_invalid_answer", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "is_prompt": false, @@ -162,7 +166,7 @@ Providing an invalid answer:: Providing a false (negative) answer:: - {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "is_prompt": true, + {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "message": "... Type 'YES' if you understand this and want to continue: "} NO # input on stdin {"type": "question_accepted_false", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", @@ -170,7 +174,7 @@ Providing a false (negative) answer:: Providing a true (affirmative) answer:: - {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "is_prompt": true, + {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "message": "... Type 'YES' if you understand this and want to continue: "} YES # input on stdin # no further output, just like the prompt without --log-json diff --git a/src/borg/archive.py b/src/borg/archive.py index 0756730bf..7752f5164 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -97,6 +97,7 @@ class Statistics: if self.output_json: data = self.as_dict() data.update({ + 'time': time.time(), 'type': 'archive_progress', 'path': remove_surrogates(item.path if item else ''), }) diff --git a/src/borg/helpers.py b/src/borg/helpers.py index 6a9242205..e147767b4 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -1345,7 +1345,6 @@ def yes(msg=None, false_msg=None, true_msg=None, default_msg=None, type='question_%s' % msg_type, msgid=msgid, message=msg, - is_prompt=is_prompt, )) print(json.dumps(kwargs), file=sys.stderr) else: @@ -1474,7 +1473,8 @@ class ProgressIndicatorBase: operation=self.id, msgid=self.msgid, type=self.JSON_TYPE, - finished=finished + finished=finished, + time=time.time(), )) print(json.dumps(kwargs), file=sys.stderr) diff --git a/src/borg/logger.py b/src/borg/logger.py index 672c1e897..6300776d7 100644 --- a/src/borg/logger.py +++ b/src/borg/logger.py @@ -204,7 +204,6 @@ def create_logger(name=None): class JsonFormatter(logging.Formatter): RECORD_ATTRIBUTES = ( - 'created', 'levelname', 'name', 'message', @@ -224,6 +223,7 @@ class JsonFormatter(logging.Formatter): super().format(record) data = { 'type': 'log_message', + 'time': record.created, } for attr in self.RECORD_ATTRIBUTES: value = getattr(record, attr, None)