📝 ️ 1. Says

In logging, you may know logging, or use your own methods of recording to files, but the Eliot logger I’ve described may meet your requirements

  • Output log information in a structured manner
  • It can be used to parse and filter logs
  • Not only record simple information, but also track the execution of the program
  • Very good performance, using non-clogging IO
  • This can be used in combination with Logstash/Elasticsearch

Eliot making address

Eliot – tree lot address

📝 2. Ann

python3 -m pip install eliot eliot-tree
Copy the code

📝 3. Use

Type the following in medusa.py:

#! /usr/bin/env python # _*_ Coding: UTF-8 _*_ import time from eliot import * to_file(open('./medusa_log.log', 'w', encoding='UTF-8')) def __worker(i): """ with start_action(action_type="__worker", urls= I): time.sleep(4) print(I) def medusa(_: (list, tuple) : """ define a function that performs task work """ with start_action(action_type="worker", urls=_): for I in _: __worker(i) if __name__ == '__main__': bui = 1, 'MedusaSorcerer' medusa(bui)Copy the code

Parsing code:

  • We’ve defined one in the codebuiThe tuple object, which is the argument given to the worker function
  • Job functionmedusaThe received parameters are iterated, delivering each iterated element to__workerfunction
  • to_fileThe function declares that log content is saved as a file and specifies a file object

4 📝 transport line

When python3 medusa.py is run, the medusa_log.log file will be created in the same directory.

{"urls": [1, "MedusaSorcerer"], "action_status": "started", "timestamp": 1595313658.5557268, "task_uuid": "58b309ff-ab22-40bb-89c6-bfd951ce4f4a", "action_type": "worker", "task_level": [1]} {"urls": 1, "action_status": "Started ", "timestamp": 1595313658.556727, "task_uuid":" 58b309FF-ab22-40bb-89c6-bfd951ce4f4a ", "action_type": "__worker", "task_level": [2, 1]} {"action_status": "Succeeded ", "timestamp": 1595313662.562169, "task_uuid": "58b309ff-ab22-40bb-89c6-bfd951ce4f4a", "action_type": "__worker", "task_level": [2, 2]} {"urls": "MedusaSorcerer", "action_status": "started", "TIMESTAMP ": 1595313662.562169, "task_uuid": "58b309ff-ab22-40bb-89c6-bfd951ce4f4a", "action_type": "__worker", "task_level": [3, 1]} {"action_status": "Succeeded ", "timestamp": 1595313666.5714984," task_uUID ": "58b309FF-AB22-40bb-89c6-bfd951ce4f4a ", "action_type": "__worker", "task_level": [3, 2]} {"action_status": "Succeeded ", "timestamp": 1595313666.5714984, "task_uuid": "58b309ff-ab22-40bb-89c6-bfd951ce4f4a", "action_type": "worker", "task_level": [4]}Copy the code
  • Line 1: Executemedusa()The task log is created when
  • Line 2: Records the array passing through the history__worker()Task logs created when
  • Line 3: records the first substitution__worker()End log after data execution is complete
  • Line 4: Records the second pass through the ages__worker()Task log
  • Line 5: Records the second substitution__worker()End log after data execution is complete
  • Row 6: RecordedmedusaTask logs generated after a task is executed

How do you implement filtering next?

📝 5. Filter

useeliot-tree --helpFor related help information:

Format the output log content:

Retrieve containaction_statusKey log content:

Retrieves the specified task UUID:

Retrieve time range tasks:

Note that the format of the time needs to be consistentISO8601Standard.






What is your world like?