Writes logs to a specified Logstore.

Request syntax

aliyunlog log put_logs --request=<value> [--access-id=<value>] [--access-key=<value>] [--sts-token=<value>] [--region-endpoint=<value>] [--client-name=<value>] [--jmes-filter=<value>] [--format-output=<value>] [--decode-output=<value>]

Request parameters

The following table describes the required and specific parameters of the put_logs command.
Parameter Type Required Example Description
--request JSON Object Yes file://./putlogs.json The path of the configuration file that is used to write logs to a Logstore.
For information about the global parameters of the Log Service command-line interface (CLI), see Global variables.

Examples

  1. Create a file named putlogs.json. The following example shows the content of the putlogs.json file:
    {
    "project": "aliyun-test-project",
    "logstore": "logstore-a",
    "topic": "topic1",
    "source": "source1",
    "logtags": [
      [
        "tag1",
        "v1"
      ],
      [
        "tag2",
        "v2"
      ]
    ],
    "hashKey": "1231231234",
    "logitems": [
      {
        "timestamp": 1622191200,
        "contents": [
          [
            "key1",
            "v1"
          ],
          [
            "key2",
            "v2"
          ]
        ]
      },
      {
        "timestamp": 1622191500,
        "contents": [
          [
            "key3",
            "v3"
          ],
          [
            "key4",
            "v4"
          ]
        ]
      }
    ]
    }
  2. Use the default account to write logs to a Logstore named logstore-a. Run the following command:
    aliyunlog log put_logs --request="file://./putlogs.json"

    After you run the command, no responses are returned.

  3. Query the logs that are written to the Logstore named logstore-a. Run the following command:
    aliyunlog log get_log_all --project="aliyun-test-project" --logstore="logstore-a" --from_time="2021-05-28 16:40:00" --to_time="2021-05-28 16:45:00"
    The following output is returned:
    [
      {
        "__source__": "source1",
        "__tag__:__client_ip__": "203.0.113.129",
        "__tag__:__receive_time__": "1622191755",
        "__tag__:tag1": "v1",
        "__tag__:tag2": "v2",
        "__time__": "1622191200",
        "__topic__": "topic1",
        "key1": "v1",
        "key2": "v2"
      },
      {
        "__source__": "source1",
        "__tag__:__client_ip__": "203.0.113.129",
        "__tag__:__receive_time__": "1622192694",
        "__tag__:tag1": "v1",
        "__tag__:tag2": "v2",
        "__time__": "1622191200",
        "__topic__": "topic1",
        "key1": "v1",
        "key2": "v2"
      },
      {
        "__source__": "source1",
        "__tag__:__client_ip__": "203.0.113.129",
        "__tag__:__receive_time__": "1622634296",
        "__tag__:tag1": "v1",
        "__tag__:tag2": "v2",
        "__time__": "1622191200",
        "__topic__": "topic1",
        "key1": "v1",
        "key2": "v2"
      }
    ]

Error codes

If an error message is returned, fix the error based on the error codes of the related API operation. For more information, see Error codes of PutLogs.

API reference

PutLogs