Write JSON logs (PutLogs)

Updated at:

Run CLI commands to write JSON-formatted log data to a specified Logstore.

Prerequisites

Before you begin, make sure that:

  • Simple Log Service (SLS) is activated. For more information, see Get started with SLS.

  • The SLS CLI is installed and configured. For more information, see Install and configure the new SLS CLI.

  • An SLS project and Logstore are created. For more information, see Create a project and Create a Logstore.

Note

The value of the __time__ field must be a Unix timestamp in seconds, specified as a string.

Command syntax

aliyun sls put-json-logs --project=<value> --logstore=<value> --logs <value> [--logs <value> ...] [--topic=<value>] [--source=<value>]

Parameters

The following table describes the required and command-specific parameters.

ParameterTypeRequiredExampleDescription
--projectStringYesaliyun-test-projectThe name of the project.
--logstoreStringYesaliyun-test-logstoreThe name of the Logstore.
--logsStringYesSee the example belowThe log content in JSON format. You can specify this parameter multiple times to write multiple log entries.
--topicStringNoapp-serverThe log topic tag. Use this parameter to categorize logs.
--sourceStringNo192.168.1.10The log source tag, such as a server IP address.

For information about global parameters, see Global parameters.