After you configure Log Service CLI, you do not need to configure global parameters each time you run a command. The global parameters include the AccessKey pair, endpoint, and output format. This topic describes how to configure Log Service CLI.
Prerequisites
Use the credentials of Alibaba Cloud CLI
Log Service CLI reads credentials from the following sources in descending order of priority: subcommands of Log Service CLI, configuration file of Log Service CLI, configuration file of Alibaba Cloud CLI, and environment variables.
Credential source in descending order of priority | Description |
---|---|
The global parameters that are passed to the subcommands of Log Service CLI, such as an AccessKey pair and a region | When a subcommand is run, Log Service CLI preferentially reads credentials from the parameters in the subcommand for verification. This type of source has the highest priority. For more information, see Global parameters. |
The profile parameter that is configured for Log Service CLI | When a subcommand is run, Log Service CLI reads credentials based on the following
setting: --profile=Name of a credential configuration in the config.json file of Alibaba Cloud CLI . For more information about the --profile parameter, see Global parameters.
|
The ALIYUN_LOG_CLI environment variable that is configured for Log Service CLI | Log Service CLI reads credentials from the ALIYUN_LOG_CLI environment variable that is configured in the system. |
The configuration file of Log Service CLI | The file is named in the .aliyunlogcli format. For more information, see Configure an endpoint and an AccessKey pair for the default account and Configure endpoints and AccessKey pairs for multiple accounts. |
The ALIBABACLOUD environment variable that is configured for Alibaba Cloud CLI | Log Service CLI reads credentials from the ALIBABACLOUD environment variable that is configured in the system. |
The ALICLOUD environment variable that is configured for Alibaba Cloud CLI | Log Service CLI reads credentials from the ALICLOUD environment variable that is configured in the system. |
The configuration file of Alibaba Cloud CLI | Log Service CLI reads credentials from the configuration file of Alibaba Cloud CLI.
Log Service CLI can use the credentials that are configured for Alibaba Cloud CLI
to verify accounts. For more information, see Configure Alibaba Cloud CLI.
Note The path to the configuration file varies based on the operating system that is in
use.
|
Configure an endpoint and an AccessKey pair for the default account
By default, Log Service CLI uses the main account to perform all operations. Before you can use Log Service CLI, you must configure the main account.
Configure endpoints and AccessKey pairs for multiple accounts
If you want to manage log data across multiple accounts, you must configure endpoints and AccessKey pairs for the accounts.
Specify the output format
Log Service CLI can format output and escape characters in the output. If you want to format output and escape characters, you can use the following methods:
- Format JSON output
By default, the output of Log Service CLI is in the JSON format and is displayed in one line. In this case, the output is difficult to read. To improve readability, you can use one of the following methods to format the JSON output:
- Format the output of a specified command
For example, you can use the
aliyunlog log get_log .... --format-output=json
command to format the JSON output of the get_log command. - Format the output of all commands
You can use the
aliyunlog configure --format-output=json
command to format the JSON output of all commands.
- Format the output of a specified command
- Escape characters
By default, the non-English characters in the output of Log Service CLI are escaped characters. If you want Log Service CLI to return the original characters, such as Chinese strings, you can specify
no_escape
for--format-output
.If you run the
aliyunlog configure --format-output=no_escape
command, Log Service CLI does not escape characters in the output of commands. The original characters are returned.
Escape special characters
If you run a command in Log Service CLI and the query statement contains dollar signs ($), grave accents (`), backslashes (\), or exclamation points (!), an error occurs during the execution, or the query result is inaccurate.
- If you want to escape the special characters in the query parameter by using backslashes
(\), run the following command:
aliyunlog log get_log_all --project="my-project" --logstore="my-logstore" --query="event_name:\$_enter" --from_time="2021-06-24 15:00:00+08:00" --to_time="2021-06-24 16:00:00+08:00"
- If you want to reference the special characters in the query parameter by using single
quotation marks ('), run the following command:
aliyunlog log get_log_all --project="my-project" --logstore="my-logstore" --query='event_name:$_enter' --from_time="2021-06-24 15:00:00+08:00" --to_time="2021-06-24 16:00:00+08:00"