SLS Log Query
All credentials and configuration are already set as environment variables. Do not ask the user for any credentials or configuration. Execute the command directly.
Command template
Use python3 (system Python, NOT .venv). The SDK is already installed globally.
python3 scripts/sls_query.py --project PROJECT --logstore LOGSTORE --query "QUERY" --from-time="TIME_RANGE" --limit 100
Default output is a summary (grouped error counts). Add --output text only if user asks for specific log entries.
Replace the placeholders as follows:
PROJECT — derive from the environment the user mentions:
- 生产/prod/线上 → use the literal string
$SLS_PROD_PROJECT(the shell resolves it) - 测试/test → use the literal string
$SLS_TEST_PROJECT(the shell resolves it)
LOGSTORE — derive from the service name the user mentions, using pattern quan-SERVICE-logstore-ENV:
- SERVICE = what the user says (message → message-backend, ai → ai-provider, auth → auth-provider, user → user-provider, cms → cms-provider, content → content-provider)
- ENV = prd (production) or test
QUERY — the log level field is info (not level):
- Error logs:
info: ERROR - Search keyword:
NullPointerException - Combined:
info: ERROR AND timeout
TIME_RANGE: -15m, -1h, -24h, or 2024-01-15 10:00:00
Example
User says: "查一下生产环境 message 服务今天的错误日志"
You should run:
python3 scripts/sls_query.py --project $SLS_PROD_PROJECT --logstore quan-message-backend-logstore-prd --query "info: ERROR" --from-time="-24h" --limit 20
Do not quote $SLS_PROD_PROJECT — let the shell expand it.