调用CLI命令写入日志到指定Logstore。

请求语法

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 JSON Object file://./putlogs.json 写入日志的配置文件路径。
关于该命令的全局参数,请参见 全局参数

示例

  1. 创建putlogs.json文件。其内容示例如下:
    {
    "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. 使用默认账号给logstore-a中写入日志。命令示例如下:
    aliyunlog log put_logs --request="file://./putlogs.json"

    命令执行成功后,无响应消息。

  3. 查询已写入logstore-a的日志。命令示例如下:
    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"
    返回结果如下:
    [
      {
        "__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"
      }
    ]

错误码

如果返回报错信息,请参见具体接口的错误码处理。更多信息,请参见PutLogs错误码处理

API参考

PutLogs