All Products
Search
Document Center

Simple Log Service:Configure Simple Log Service CLI

Last Updated:Sep 02, 2024

After you configure Simple 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 CLI accounts and global parameters.

Use the credentials of Alibaba Cloud CLI

Simple Log Service CLI can use the credentials that are configured for Alibaba Cloud CLI to verify accounts. If you have installed Alibaba Cloud CLI, you do not need to configure accounts. For more information, see Configure Alibaba Cloud CLI.

Simple Log Service CLI reads credentials from the following sources in descending order of priority: subcommands of Simple Log Service CLI, configuration file of Simple 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 Simple Log Service CLI, such as an AccessKey pair and a region

When a subcommand is run, Simple Log Service CLI preferentially reads credentials from the parameters in the subcommand for verification. This type of source has the highest priority.

The profile parameter that is configured for Simple Log Service CLI

When a subcommand is run, Simple 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 Simple Log Service CLI

Simple Log Service CLI reads credentials from the ALIYUN_LOG_CLI environment variable that is configured in the system.

The configuration file of Simple 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

Simple 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

Simple Log Service CLI reads credentials from the ALICLOUD environment variable that is configured in the system.

The configuration file of Alibaba Cloud CLI

Simple Log Service CLI reads credentials from the configuration file of Alibaba Cloud CLI.

Note

The path to the configuration file varies based on the operating system that is in use.

  • Linux: ~/.aliyun/config.json

  • Windows: C:\Users\UserName\.aliyun\config.json

Configure an endpoint and an AccessKey pair for the default account

By default, Simple Log Service CLI uses the main account to perform all operations. Before you can use Simple Log Service CLI, you must configure an AccessKey pair and an endpoint for the main account and grant the main account the required permissions to manage projects.

  1. Log on to the server on which Simple Log Service CLI is installed.

  2. Configure an endpoint and an AccessKey pair for the default account.

    Run the following command:

    aliyunlog configure "AccessKey ID" "AccessKey Secret" Endpoint
  3. Verify the configuration result.

    Open the .aliyunlogcli configuration file. If the file contains information similar to the following example, the default account is configured.

    [main]
    access-id = LTAI******pLMZ
    access-key = XjAsP******eRqax
    region-endpoint = cn-hangzhou.log.aliyuncs.com
    sts-token =
    Note

    The path to the .aliyunlogcli configuration file varies based on the operating system that is in use.

    • Linux: ~/.aliyunlogcli

    • Windows: C:\Users\UserName\.aliyunlogcli

    If the default account fails to be configured, you can fix the error based on the error code that is returned.

Configure endpoints and AccessKey pairs for multiple accounts

If you want to manage log data across accounts, you must configure AccessKey pairs and endpoints for the accounts.

  1. Log on to the server on which Simple Log Service CLI is installed.

  2. Configure AccessKey pairs and endpoints for multiple accounts.

    Run the following command:

    aliyunlog configure "AccessKey ID" "AccessKey Secret" Endpoint Name
    • Replace Name with the name of an account that you configure.

  3. Verify the configuration result.

    Open the ~/.aliyunlogcli configuration file. If the file contains information similar to the following example, the accounts are configured.

    [main]
    access-id = LTAI******pLMZ
    access-key = XjAsP******eRqax
    region-endpoint = cn-hangzhou.log.aliyuncs.com
    sts-token =
    
    [test]
    access-id = As******sPzvb
    access-key = FtagJeR******bQqax
    region-endpoint = cn-shanghai.log.aliyuncs.com
    sts-token =
    Note

    The path to the .aliyunlogcli configuration file varies based on the operating system that is in use.

    • Linux: ~/.aliyunlogcli

    • Windows: C:\Users\UserName\.aliyunlogcli

    If the accounts fail to be configured, you can fix the error based on the error code that is returned.

    If you use Simple Log Service CLI to run a command, you can use --client-name=testName to specify the account that you want to use. For example, if you run the aliyunlog log create_project ..... --client-name=test command, the test account is used to create the project.

Specify the output format

Simple 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 Simple 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.

  • Escape characters

    By default, the non-English characters in the output of Simple Log Service CLI are escaped characters. If you want Simple 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, Simple 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 Simple 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.

In this case, you must use backslashes (\) to escape the special characters or use single quotation marks (') to reference the special characters. Examples:

  • 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"

For more information, see Quoting.