Przeglądaj źródła

--log-json: time property on most progress/log objects, remove is_prompt

Marian Beermann 8 lat temu
rodzic
commit
cdb4df0885
4 zmienionych plików z 18 dodań i 13 usunięć
  1. 14 10
      docs/internals/frontends.rst
  2. 1 0
      src/borg/archive.py
  3. 2 2
      src/borg/helpers.py
  4. 1 1
      src/borg/logger.py

+ 14 - 10
docs/internals/frontends.rst

@@ -39,6 +39,8 @@ archive_progress
         Number of (regular) files processed so far
         Number of (regular) files processed so far
     path
     path
         Current path
         Current path
+    time
+        Unix timestamp (float)
 
 
 progress_message
 progress_message
     A message-based progress information with no concrete progress information, just a 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*.
         can have this property set to *true*.
     message
     message
         current progress message (may be empty/absent)
         current progress message (may be empty/absent)
+    time
+        Unix timestamp (float)
 
 
 progress_percent
 progress_percent
     Absolute progress information with defined end/total and current value.
     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*
         Array that describes the current item, may be *null*, contents depend on *msgid*
     total
     total
         Total value
         Total value
+    time
+        Unix timestamp (float)
 
 
 file_status
 file_status
     This is only output by :ref:`borg_create` and :ref:`borg_recreate` if ``--list`` is specified. The usual
     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
 log_message
     Any regular log output invokes this type. Regular log options and filtering applies to these as well.
     Any regular log output invokes this type. Regular log options and filtering applies to these as well.
 
 
-    created
+    time
         Unix timestamp (float)
         Unix timestamp (float)
     levelname
     levelname
         Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL
         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*,
 are still read verbatim from *stdin*, while prompts are JSON messages printed to *stderr*,
 just like log messages.
 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,
 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
 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
 environment variable that can be used to override the prompt. It is the same for all JSON
 messages pertaining to the same prompt.
 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)
 .. rubric:: Examples (reformatted, each object would be on exactly one line)
 
 
 Providing an invalid answer::
 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: "}
      "message": "... Type 'YES' if you understand this and want to continue: "}
     incorrect answer  # input on stdin
     incorrect answer  # input on stdin
     {"type": "question_invalid_answer", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "is_prompt": false,
     {"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::
 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: "}
      "message": "... Type 'YES' if you understand this and want to continue: "}
     NO  # input on stdin
     NO  # input on stdin
     {"type": "question_accepted_false", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING",
     {"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::
 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: "}
      "message": "... Type 'YES' if you understand this and want to continue: "}
     YES  # input on stdin
     YES  # input on stdin
     # no further output, just like the prompt without --log-json
     # no further output, just like the prompt without --log-json

+ 1 - 0
src/borg/archive.py

@@ -97,6 +97,7 @@ class Statistics:
             if self.output_json:
             if self.output_json:
                 data = self.as_dict()
                 data = self.as_dict()
                 data.update({
                 data.update({
+                    'time': time.time(),
                     'type': 'archive_progress',
                     'type': 'archive_progress',
                     'path': remove_surrogates(item.path if item else ''),
                     'path': remove_surrogates(item.path if item else ''),
                 })
                 })

+ 2 - 2
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,
                 type='question_%s' % msg_type,
                 msgid=msgid,
                 msgid=msgid,
                 message=msg,
                 message=msg,
-                is_prompt=is_prompt,
             ))
             ))
             print(json.dumps(kwargs), file=sys.stderr)
             print(json.dumps(kwargs), file=sys.stderr)
         else:
         else:
@@ -1474,7 +1473,8 @@ class ProgressIndicatorBase:
             operation=self.id,
             operation=self.id,
             msgid=self.msgid,
             msgid=self.msgid,
             type=self.JSON_TYPE,
             type=self.JSON_TYPE,
-            finished=finished
+            finished=finished,
+            time=time.time(),
         ))
         ))
         print(json.dumps(kwargs), file=sys.stderr)
         print(json.dumps(kwargs), file=sys.stderr)
 
 

+ 1 - 1
src/borg/logger.py

@@ -204,7 +204,6 @@ def create_logger(name=None):
 
 
 class JsonFormatter(logging.Formatter):
 class JsonFormatter(logging.Formatter):
     RECORD_ATTRIBUTES = (
     RECORD_ATTRIBUTES = (
-        'created',
         'levelname',
         'levelname',
         'name',
         'name',
         'message',
         'message',
@@ -224,6 +223,7 @@ class JsonFormatter(logging.Formatter):
         super().format(record)
         super().format(record)
         data = {
         data = {
             'type': 'log_message',
             'type': 'log_message',
+            'time': record.created,
         }
         }
         for attr in self.RECORD_ATTRIBUTES:
         for attr in self.RECORD_ATTRIBUTES:
             value = getattr(record, attr, None)
             value = getattr(record, attr, None)