Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ sudo mv clog /usr/local/bin/
| \-s | \--status | Show system resource bar at the bottom of the terminal. |
| \-d | \--dashboard | Enable 1-second dashboard mode for real-time metrics. |
| \-c | \--clear-screen | Clear terminal before starting and on exit. |
| \-r | \--remote-ip | Use direct connection IP instead of client_ip. |
| | \--help | Show the help menu and usage instructions. |

----
Expand Down Expand Up @@ -172,6 +173,14 @@ clog --clear-screen /path/to/access.log

---

### Forcing Remote IP
By default, `clog` prioritizes the Caddy `client_ip` field to show the visitor's real IP behind proxies, falling back to `remote_ip` if missing. To force using Caddy's direct connection IP (`remote_ip`) instead:
```bash
clog --remote-ip /path/to/access.log
```

---

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for more details.

Expand Down
21 changes: 17 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// CLOG v0.6.4 - Caddy Log Viewer
// CLOG v0.6.5 - Caddy Log Viewer
// Source Repository: https://github.com/hellotimking/clog

package main
Expand Down Expand Up @@ -27,6 +27,7 @@ type CaddyLog struct {
Duration float64 `json:"duration"`
Request struct {
RemoteIP string `json:"remote_ip"`
ClientIP string `json:"client_ip"`
Method string `json:"method"`
Host string `json:"host"`
URI string `json:"uri"`
Expand All @@ -43,6 +44,7 @@ var (
lastSampleTime time.Time
cachedLogs []CaddyLog
cachedStats LogStats
remoteIP bool
)

type LogStats struct {
Expand Down Expand Up @@ -232,7 +234,7 @@ func main() {
var f, host string

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "\033[1mCLOG v0.6.4 - High-Visibility Caddy Logs\033[0m\n")
fmt.Fprintf(os.Stderr, "\033[1mCLOG v0.6.5 - High-Visibility Caddy Logs\033[0m\n")
fmt.Fprintf(os.Stderr, "Usage: clog [options] <logfile>\n\nOptions:\n")
fmt.Fprintf(os.Stderr, " --lines, -l number of previous lines to show\n")
fmt.Fprintf(os.Stderr, " --host, -h only show logs for this domain or IP\n")
Expand All @@ -243,10 +245,11 @@ func main() {
fmt.Fprintf(os.Stderr, " --status, -s show system resource bar at bottom\n")
fmt.Fprintf(os.Stderr, " --dashboard, -d enable 1-second dashboard mode\n")
fmt.Fprintf(os.Stderr, " --clear-screen, -c clear terminal before starting and on exit\n")
fmt.Fprintf(os.Stderr, " -r, --remote-ip Use direct connection IP instead of client IP.\n")
fmt.Fprintf(os.Stderr, " --help show this help menu\n\n")
}

// CLOG v0.6.4 - Caddy Log Viewer
// CLOG v0.6.5 - Caddy Log Viewer
// Source Repository: https://github.com/hellotimking/clog

flag.IntVar(&lCount, "l", 0, "")
Expand All @@ -263,6 +266,8 @@ func main() {
flag.BoolVar(&all, "all", false, "")
flag.BoolVar(&clear, "c", false, "")
flag.BoolVar(&clear, "clear-screen", false, "")
flag.BoolVar(&remoteIP, "r", false, "")
flag.BoolVar(&remoteIP, "remote-ip", false, "")
flag.BoolVar(&count, "co", false, "")
flag.BoolVar(&count, "count", false, "")
flag.BoolVar(&status, "s", false, "")
Expand Down Expand Up @@ -340,7 +345,12 @@ func processLogs(filePath string, lCount int, ha bool, e bool, all bool, f strin
for _, line := range rawLines {
if line == "" { continue }
var l CaddyLog
if err := json.Unmarshal([]byte(line), &l); err == nil { newLogs = append(newLogs, l) }
if err := json.Unmarshal([]byte(line), &l); err == nil {
if !remoteIP && l.Request.ClientIP != "" {
l.Request.RemoteIP = l.Request.ClientIP
}
newLogs = append(newLogs, l)
}
}
cachedLogs = newLogs
cachedStats = calculateStats(cachedLogs)
Expand Down Expand Up @@ -401,6 +411,9 @@ func processLogs(filePath string, lCount int, ha bool, e bool, all bool, f strin
for line := range t.Lines {
var l CaddyLog
if err := json.Unmarshal([]byte(line.Text), &l); err != nil { continue }
if !remoteIP && l.Request.ClientIP != "" {
l.Request.RemoteIP = l.Request.ClientIP
}
if host != "" {
h := strings.ToLower(host)
if !strings.Contains(strings.ToLower(l.Request.RemoteIP), h) && !strings.Contains(strings.ToLower(l.Request.Host), h) { continue }
Expand Down