All Products
Search
Document Center

Simple Log Service:GetLogs

Last Updated:Jun 11, 2026

Mengkueri data log dari penyimpanan log di Proyek yang ditentukan.

Deskripsi operasi

Catatan

Simple Log Service supports scheduled SQL jobs. For details, see Create a scheduled SQL job.

  • The Host in the request syntax consists of the project name and the Simple Log Service endpoint. Specify the project name in the Host.

  • Create and obtain an AccessKey pair. For details, see AccessKey pair.

Create and use a RAM user to make API calls or perform routine O&M. Using an Alibaba Cloud account AccessKey pair grants access to all APIs and poses a high security risk. Ensure the RAM user has the required permissions for Simple Log Service resources. For details, see Create and authorize a RAM user.

  • Obtain the project name, region, and Logstore name for the logs to query. See Manage a project and Manage a Logstore.

  • Simple Log Service imposes limits on log queries. Design appropriate query and analytic statements and set a reasonable time range. See Log query limits and Log analysis limits.

  • Configure indexes before querying logs. See Create indexes.

  • When the number of matching logs varies significantly, the API cannot predict how many calls are needed to retrieve the complete result. Check the x-log-progress header in each response to determine whether to repeat the call. Each repeated call consumes the same number of query capacity units (CUs).

  • After a log is written to a Logstore, the latency before it becomes queryable through the GetHistograms and GetLogs operations depends on the log type. Simple Log Service classifies logs into two types based on their timestamps:

    • Real-time data: The log timestamp falls within (-180 seconds, 900 seconds] relative to the current server time. For example, if a log is generated at UTC 2014-09-25 12:03:00 and is received by the server at UTC 2014-09-25 12:05:00, the log is classified as real-time data. This is typical in normal scenarios. Real-time data becomes queryable in about 3 seconds.

    • Historical data: The log timestamp falls within [-7 x 86,400 seconds, -180 seconds) relative to the current server time. For example, if a log is generated at UTC 2014-09-25 12:00:00 and is received by the server at UTC 2014-09-25 12:05:00, the log is classified as historical data. This is typical in data backfill scenarios.

Catatan

Simple Log Service calculates the difference between the log time (the __time__ field) and the server receipt time (the __tag__: receive_time field). If the difference falls within (-180 seconds, 900 seconds], the log is real-time data. If the difference falls within [-7 x 86,400 seconds, -180 seconds), the log is historical data.

Authorization

The following table describes the authorization information required for this operation. Add this information to the Action element of a RAM access policy statement to grant RAM users or RAM roles the permission to call this operation.

ActionResource
log:GetLogStoreLogsacs:log:{#regionId}:{#accountId}:project/{#ProjectName}/logstore/{#LogstoreName}

Coba sekarang

Coba API ini di OpenAPI Explorer tanpa perlu penandatanganan manual. Panggilan yang berhasil akan secara otomatis menghasilkan contoh kode SDK sesuai dengan parameter Anda. Unduh kode tersebut dengan kredensial bawaan yang aman untuk penggunaan lokal.

Test

RAM authorization

Tidak ada otorisasi untuk operasi ini. Jika Anda mengalami masalah saat menjalankan operasi ini, hubungi dukungan teknis.

Sintaks permintaan

GET /logstores/{logstore}?type=log HTTP/1.1

Path Parameters

Parameter

Type

Required

Description

Example

logstore

string

Yes

Penyimpanan log yang akan dikueri.

example-logstore

Parameter permintaan

Parameter

Type

Required

Description

Example

project

string

Yes

Nama Proyek.

ali-test-project

from

integer

Yes

Awal pengatur waktu kueri, berdasarkan waktu log yang ditentukan saat data log ditulis.

  • Parameter from dan to mendefinisikan interval tertutup kiri dan terbuka kanan [from, to). Jika from sama dengan to, interval tidak valid dan sistem akan mengembalikan error.

  • Nilai: stempel waktu UNIX yang mewakili jumlah detik yang berlalu sejak 1 Januari 1970, 00:00:00 UTC.

Catatan

Untuk menghindari data yang hilang, sesuaikan waktu kueri ke tingkat menit. Jika pengatur waktu ditentukan dalam pernyataan analitik, pengatur waktu tersebut akan diutamakan.

Untuk menentukan waktu dalam detik di dalam pernyataan analitik, gunakan fungsi from_unixtime atau fungsi to_unixtime untuk mengonversi format waktu. Contoh:

  • * | SELECT * FROM log WHERE from_unixtime(__time__) > from_unixtime(1664186624) AND from_unixtime(__time__) < now()

  • * | SELECT * FROM log WHERE __time__ > to_unixtime(date_parse('2022-10-19 15:46:05', '%Y-%m-%d %H:%i:%s')) AND __time__ < to_unixtime(now()).

1627268185

to

integer

Yes

Akhir pengatur waktu kueri, berdasarkan waktu log yang ditentukan saat data log ditulis.

  • Parameter from dan to mendefinisikan interval tertutup kiri dan terbuka kanan [from, to). Jika from sama dengan to, interval tidak valid dan sistem akan mengembalikan error.

  • Nilai: stempel waktu UNIX yang mewakili jumlah detik yang berlalu sejak 1 Januari 1970, 00:00:00 UTC.

Catatan

Untuk menghindari data yang hilang, sesuaikan waktu kueri ke tingkat menit. Jika pengatur waktu ditentukan dalam pernyataan analitik, pengatur waktu tersebut akan diutamakan.

Untuk menentukan waktu dalam detik di dalam pernyataan analitik, gunakan fungsi from_unixtime atau fungsi to_unixtime untuk mengonversi format waktu. Contoh:

  • * | SELECT * FROM log WHERE from_unixtime(__time__) > from_unixtime(1664186624) AND from_unixtime(__time__) < now()

  • * | SELECT * FROM log WHERE __time__ > to_unixtime(date_parse('2022-10-19 15:46:05', '%Y-%m-%d %H:%i:%s')) AND __time__ < to_unixtime(now()).

1627269085

query

string

No

Pernyataan pencarian atau pernyataan analitik. Lihat Ikhtisar kueri dan Ikhtisar analisis. Untuk mengaktifkan fitur SQL Eksklusif, tambahkan set session parallel_sql=true; ke pernyataan analitik. Contoh: * | set session parallel_sql=true; select count(*) as pv. Untuk masalah kueri dan analisis umum, lihat Kesalahan umum yang terjadi saat Anda mengueri dan menganalisis log.

Catatan

Ketika parameter query berisi pernyataan analitik (pernyataan SQL), parameter line dan offset akan diabaikan. Atur keduanya ke 0 dan gunakan klausa LIMIT dalam pernyataan SQL untuk paginasi. Lihat Melakukan paginasi pada hasil kueri dan analisis.

status: 401 | SELECT remote_addr,COUNT(*) as pv GROUP by remote_addr ORDER by pv desc limit 5

topic

string

No

Topik log. Nilai default: string kosong. Lihat Topik.

topic

line

integer

No

Hanya valid ketika parameter query adalah pernyataan pencarian. Jumlah maksimum log yang akan dikembalikan. Nilai valid: 0 hingga 100. Nilai default: 100. Lihat Melakukan paginasi pada hasil kueri dan analisis.

100

offset

integer

No

Hanya valid ketika parameter query adalah pernyataan pencarian. Baris awal untuk kueri. Nilai default: 0. Lihat Melakukan paginasi pada hasil kueri dan analisis.

0

reverse

boolean

No

Apakah akan mengembalikan log dalam urutan menurun berdasarkan stempel waktu, dengan presisi tingkat menit.

  • true: Urutan menurun (terbaru terlebih dahulu).

  • false (default): Urutan menaik (terlama terlebih dahulu).

Penting
  • Ketika parameter query adalah pernyataan pencarian, parameter reverse mengontrol urutan pengurutan.

  • Ketika parameter query menyertakan pernyataan analitik, parameter reverse akan diabaikan. Gunakan klausa ORDER BY dalam pernyataan SQL sebagai gantinya. ORDER BY default ke menaik (asc). Tentukan desc untuk urutan menurun.

false

powerSql

boolean

No

Apakah akan mengaktifkan fitur SQL Eksklusif. Lihat Mengaktifkan fitur SQL Eksklusif.

  • true: Mengaktifkan SQL Eksklusif.

  • false (default): Menggunakan SQL Standar.

Sebagai alternatif, tambahkan set session parallel_sql=true; ke pernyataan analitik dalam parameter query untuk mengaktifkan SQL Eksklusif.

false

Elemen respons

Element

Type

Description

Example

array

The log array. Each element is a log entry.

object

The log array. Each element is a log entry.

[{'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.XXX.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}, {'remote_addr': '198.51.100.XXX', 'pv': '1', '__source__': '', '__time__': '1649902984'}]

Contoh

Respons sukses

JSONformat

[
  {
    "test": "test",
    "test2": 1
  }
]

Kode kesalahan

Lihat Error Codes untuk daftar lengkap.

Catatan rilis

Lihat Release Notes untuk daftar lengkap.