浏览代码

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

Marian Beermann 8 年之前
父节点
当前提交
cdb4df0885
共有 4 个文件被更改,包括 18 次插入13 次删除
  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
     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

+ 1 - 0
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 ''),
                 })

+ 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,
                 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)
 

+ 1 - 1
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)