Metadata-Version: 2.4
Name: nlog-cli
Version: 0.1.0
Summary: Kibana 账号密码鉴权的 ES 日志查询 + 索引运维 CLI 工具
License-Expression: MIT
License-File: LICENSE
Keywords: cli,elasticsearch,kibana,logging
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Logging
Requires-Python: >=3.12
Requires-Dist: httpx>=0.27.0
Requires-Dist: rich>=13.0.0
Requires-Dist: typer>=0.9.0
Description-Content-Type: text/markdown

# nlog-cli

纯 Kibana 账号密码鉴权的 ES 日志查询 + 索引运维 CLI 工具。

## 特性

- 只需 Kibana 账号 + 密码，无需 ES 地址、无需浏览器登录
- 1:1 复刻 Kibana DevTools DSL，复制即用
- 全链路能力：日志检索、索引列表、索引统计、Mapping、Settings
- 支持时间范围、traceId、关键词检索，自动生成 ES Bool DSL
- 输出格式：json / 单行日志 / 表格展示

## 项目结构

```
nlog-cli/
├── pyproject.toml          # 项目构建与 PyPI 发布配置
├── setup.sh                # 一键安装脚本
├── README.md
├── LICENSE
├── nlog_cli/
│   ├── __init__.py         # 版本号
│   ├── cli.py              # typer 子命令入口
│   ├── client.py           # Kibana HTTP 客户端（Basic Auth + Console Proxy）
│   ├── config.py           # ~/.nlog-cli/config.toml 配置读写
│   └── formatter.py        # json / text / table 输出格式化
└── docs/
    └── superpowers/specs/
        └── 2026-04-17-nlog-cli-design.md   # 设计文档
```

## 安装

### 方式一：一键安装（推荐）

```bash
git clone https://github.com/yanxiao/nlog-cli.git
cd nlog-cli
bash setup.sh
```

脚本会自动完成：检查 Python 环境 → 安装 CLI → 引导配置 Kibana 连接。

已配置过可跳过认证步骤：

```bash
bash setup.sh --skip-auth
```

### 方式二：远程安装（PyPI）

```bash
pip install nlog-cli
```

安装后需手动配置连接：

```bash
nlog config
```

### 方式三：本地源码安装

```bash
git clone https://github.com/yanxiao/nlog-cli.git
cd nlog-cli
pip install -e .
nlog config
```

安装完成后验证：

```bash
nlog -h
```

## 快速开始

```bash
# 配置 Kibana 连接
nlog config

# 查询日志
nlog search -i app-log-* -q "error" --time-from "now-1h"

# 按 traceId 查询
nlog search -i app-log-* -t "abc-123-def"

# 表格输出
nlog search -i app-log-* -q "timeout" -f table

# 列出索引
nlog indices "app-log-*"

# 查看索引统计
nlog stats app-log-2026.04.17

# 查看 Mapping
nlog mapping app-log-2026.04.17

# 查看 Settings
nlog settings app-log-2026.04.17

# 原生 DSL 透传
nlog dsl "GET /app-log-*/_search" --body '{"query":{"match_all":{}},"size":5}'

# 从文件读取 DSL
nlog dsl "POST /app-log-*/_search" --body-file query.json
```

## 命令列表

| 命令 | 说明 |
|------|------|
| `nlog config` | 配置 Kibana 连接信息 |
| `nlog search` | 日志检索 |
| `nlog indices` | 列出索引 |
| `nlog stats` | 索引统计 |
| `nlog mapping` | 查看 Mapping |
| `nlog settings` | 查看 Settings |
| `nlog dsl` | 原生 DSL 透传 |

每个命令都支持 `-h` / `--help` 查看详细帮助。

## 配置文件

配置存放在 `~/.nlog-cli/config.toml`：

```toml
[default]
kibana_url = "https://kibana.example.com"
username = "your-username"
password = "your-password"
space = "default"
```

支持多 profile：

```bash
nlog config --profile prod
nlog search -i app-log-* -q "error" --profile prod
```

## 卸载

```bash
# 卸载 CLI
pip uninstall nlog-cli

# 删除配置文件（可选）
rm -rf ~/.nlog-cli
```

## License

MIT
