repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
7a37a0a
parent
5ead68b
author
Eric Bower
date
2026-01-18 10:42:36 -0500 EST
feat(pico): access_logs cli command
1 files changed,  +26, -1
M pkg/apps/pico/cli.go
+26, -1
 1@@ -50,10 +50,11 @@ func (c *Cmd) output(out string) {
 2 }
 3 
 4 func (c *Cmd) help() {
 5-	helpStr := "Commands: [help, user, logs, chat, not-found]\n"
 6+	helpStr := "Commands: [help, user, logs, access_logs, chat, not-found]\n"
 7 	helpStr += "help - this message\n"
 8 	helpStr += "user - display user information (returns name, id, account created, pico+ expiration)\n"
 9 	helpStr += "logs - stream user logs\n"
10+	helpStr += "access_logs - fetch access logs from the last 30 days\n"
11 	helpStr += "chat - IRC chat (must enable pty with `-t` to the SSH command)\n"
12 	helpStr += "not-found - return all status 404 requests for a host (hostname.com [year|month])\n"
13 	c.output(helpStr)
14@@ -96,6 +97,24 @@ func (c *Cmd) notFound(host, interval string) error {
15 	return nil
16 }
17 
18+func (c *Cmd) access_logs(ctx context.Context) error {
19+	fromDate := time.Now().AddDate(0, 0, -30)
20+	logs, err := c.Dbpool.FindAccessLogs(c.User.ID, &fromDate)
21+	if err != nil {
22+		return err
23+	}
24+
25+	for _, log := range logs {
26+		jsonData, err := json.Marshal(log)
27+		if err != nil {
28+			c.Log.Error("json marshall", "err", err)
29+			continue
30+		}
31+		c.output(string(jsonData))
32+	}
33+	return nil
34+}
35+
36 func (c *Cmd) logs(ctx context.Context) error {
37 	conn := shared.NewPicoPipeClient()
38 	stdoutPipe, err := pipeLogger.ReadLogs(ctx, c.Log, conn)
39@@ -246,6 +265,12 @@ func Middleware(handler *CliHandler) pssh.SSHServerMiddleware {
40 						sesh.Fatal(err)
41 					}
42 					return nil
43+				case "access_logs":
44+					err = opts.access_logs(sesh.Context())
45+					if err != nil {
46+						sesh.Fatal(err)
47+					}
48+					return nil
49 				default:
50 					return next(sesh)
51 				}