Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

chore(logs): keep the tags and read the slog level

BaaRai3112fef43802
diff --git a/egress/egress.go b/egress/egress.go
index ad93dc0..b95abdc 100644
--- a/egress/egress.go
+++ b/egress/egress.go
@@ -68,7 +68,7 @@ func ProfileByName(name string) (p Profile, ok bool) {
return Profile{Name: "off"}, false
}
if ua := strings.TrimSpace(os.Getenv("ARTEX_TARGET_USER_AGENT")); strings.ContainsFunc(ua, unicode.IsControl) {
- slog.Warn("ARTEX_TARGET_USER_AGENT contains a control character, ignored")
+ slog.Warn("[egress] ARTEX_TARGET_USER_AGENT contains a control character, ignored")
} else {
p.UserAgent = ua
}
@@ -81,7 +81,7 @@ func ProfileFromEnv() Profile {
name := strings.TrimSpace(os.Getenv("ARTEX_NOISE_PROFILE"))
p, ok := ProfileByName(name)
if !ok && name != "" {
- slog.Warn("unknown noise profile, using off", "ARTEX_NOISE_PROFILE", name)
+ slog.Warn("[egress] unknown noise profile, using off", "ARTEX_NOISE_PROFILE", name)
}
return p
}
@@ -105,7 +105,7 @@ func Current() *Governor {
initCurrent.Do(func() {
g := New(ProfileFromEnv())
if current.CompareAndSwap(nil, g) {
- slog.Info("noise profile active", "profile", g.p.Name)
+ slog.Info("[egress] noise profile active", "profile", g.p.Name)
}
startReporter()
})
@@ -120,7 +120,7 @@ func CurrentProfile() Profile { return Current().p }
func SetProfile(p Profile) *Governor {
g := New(p)
current.Store(g)
- slog.Info("noise profile active", "profile", g.p.Name)
+ slog.Info("[egress] noise profile active", "profile", g.p.Name)
startReporter()
return g
}
diff --git a/enrich/enrich.go b/enrich/enrich.go
index f64e577..ac06687 100644
--- a/enrich/enrich.go
+++ b/enrich/enrich.go
@@ -75,7 +75,7 @@ func New(as *db.AssetStore, proxy func() string, workers int) *Engine {
Timeout: 4 * time.Second,
})
if err != nil {
- slog.Warn("dnsx init failed, DNS resolution disabled", "err", err)
+ slog.Warn("[enrich] dnsx init failed, DNS resolution disabled", "err", err)
resolv = nil
}
e := &Engine{
@@ -146,7 +146,7 @@ func (e *Engine) enqueue(j job) {
select {
case e.jobs <- j:
default: // queue full → drop (best-effort enrichment)
- slog.Warn("enrich queue full, dropping job", "kind", j.kind, "id", j.id)
+ slog.Warn("[enrich] enrich queue full, dropping job", "kind", j.kind, "id", j.id)
}
}
diff --git a/evidence/store.go b/evidence/store.go
index 2bc20b2..68e4232 100644
--- a/evidence/store.go
+++ b/evidence/store.go
@@ -443,7 +443,7 @@ func (s *Store) RunGC(ctx context.Context) {
return
case now := <-timer.C:
if err := s.Collect(ctx, now); err != nil && !errors.Is(err, context.Canceled) {
- slog.Error("evidence cleanup failed", "err", err)
+ slog.Error("[evidence] evidence cleanup failed", "err", err)
}
}
}
diff --git a/server/logsink.go b/server/logsink.go
index 36fac4b..fcbb579 100644
--- a/server/logsink.go
+++ b/server/logsink.go
@@ -209,20 +209,47 @@ func (s *logSinkT) subscribe() (<-chan LogLine, func()) {
}
// parseLog pulls a level + [tag] out of a standard-logger line; the timestamp is
-// the capture time (RFC3339).
+// the capture time (RFC3339). Lines written by the slog text handler carry the level
+// word right after the LstdFlags timestamp ("WARN [traffic] ..."): that word is the
+// level, and the tag after it is the tag. Lines without a level word keep the
+// keyword guess and the leading-tag rule.
func parseLog(line string) LogLine {
msg := line
// strip the "2006/01/02 15:04:05" LstdFlags prefix if present
if len(msg) >= 20 && msg[4] == '/' && msg[7] == '/' && msg[10] == ' ' {
msg = strings.TrimSpace(msg[19:])
}
- tag := ""
+ if word, rest, ok := strings.Cut(msg, " "); ok {
+ if level := slogLevel(word); level != "" {
+ tag, text := splitTag(rest)
+ return LogLine{TS: time.Now().Format(time.RFC3339), Level: level, Tag: tag, Text: text}
+ }
+ }
+ tag, _ := splitTag(msg)
+ return LogLine{TS: time.Now().Format(time.RFC3339), Level: levelOf(msg), Tag: tag, Text: msg}
+}
+
+// slogLevel maps the slog level word to the sink's level, "" when word is not one.
+func slogLevel(word string) string {
+ switch word {
+ case "DEBUG", "INFO":
+ return "info"
+ case "WARN":
+ return "warn"
+ case "ERROR":
+ return "error"
+ }
+ return ""
+}
+
+// splitTag returns the leading [tag] of msg and the text after it.
+func splitTag(msg string) (tag, text string) {
if strings.HasPrefix(msg, "[") {
if i := strings.IndexByte(msg, ']'); i > 1 {
- tag = msg[1:i]
+ return msg[1:i], strings.TrimSpace(msg[i+1:])
}
}
- return LogLine{TS: time.Now().Format(time.RFC3339), Level: levelOf(msg), Tag: tag, Text: msg}
+ return "", msg
}
func levelOf(msg string) string {
diff --git a/server/logsink_parse_test.go b/server/logsink_parse_test.go
new file mode 100644
index 0000000..d80bf92
--- /dev/null
+++ b/server/logsink_parse_test.go
@@ -0,0 +1,43 @@
+package server
+
+import "testing"
+
+// The line as the default slog handler writes it through the standard logger.
+func TestParseLogSlogWarnLineKeepsTagAndLevel(t *testing.T) {
+ line := "2026/11/23 13:48:50 WARN [traffic] MITM failed, falling back to passthrough host=example.com ttl=1m0s err=boom"
+ got := parseLog(line)
+ if got.Tag != "traffic" {
+ t.Fatalf("tag = %q, want traffic", got.Tag)
+ }
+ if got.Level != "warn" {
+ t.Fatalf("level = %q, want warn", got.Level)
+ }
+ want := "MITM failed, falling back to passthrough host=example.com ttl=1m0s err=boom"
+ if got.Text != want {
+ t.Fatalf("text = %q, want %q", got.Text, want)
+ }
+}
+
+func TestParseLogSlogLevelWords(t *testing.T) {
+ cases := map[string]string{
+ "2026/11/23 13:48:50 INFO [egress] noise profile active profile=balanced": "info",
+ "2026/11/23 13:48:50 DEBUG [enrich] probe": "info",
+ "2026/11/23 13:48:50 ERROR [evidence] cleanup failed err=disk": "error",
+ }
+ for line, level := range cases {
+ if got := parseLog(line); got.Level != level {
+ t.Fatalf("%q: level = %q, want %q", line, got.Level, level)
+ }
+ }
+}
+
+// Lines without a level word keep the keyword guess and the leading-tag rule.
+func TestParseLogWithoutLevelWordKeepsRules(t *testing.T) {
+ got := parseLog("2026/11/23 13:48:50 [pg] connection refused")
+ if got.Tag != "pg" || got.Level != "error" {
+ t.Fatalf("tag/level = %q/%q, want pg/error", got.Tag, got.Level)
+ }
+ if got.Text != "[pg] connection refused" {
+ t.Fatalf("text = %q, want the line with its tag", got.Text)
+ }
+}
diff --git a/traffic/external.go b/traffic/external.go
index 7bc5700..8b55fd7 100644
--- a/traffic/external.go
+++ b/traffic/external.go
@@ -69,7 +69,7 @@ func (t *Traffic) RecordExternal(e ExternalExchange) error {
id := fmt.Sprintf("%d-%04d", now.Unix(), n%10000)
if err := t.insertExchange(id, now.Unix(), host, method, db.TemplatePath(u.EscapedPath()), u.String(), status, respCT, len(e.RequestBody), len(e.ResponseBody), reqHead, reqB, respHead, respB); err != nil {
- slog.Error("failed to ingest external exchange", "url", u.String(), "err", err)
+ slog.Error("[traffic] failed to ingest external exchange", "url", u.String(), "err", err)
return err
}
return nil
diff --git a/traffic/pace.go b/traffic/pace.go
index 4f3cdd5..b17fc37 100644
--- a/traffic/pace.go
+++ b/traffic/pace.go
@@ -62,6 +62,6 @@ func pace(f *mproxy.Flow) {
defer cancel()
host := egress.HostKey(f.Request.URL)
if err := egress.Wait(ctx, host); err != nil {
- slog.Warn("pacing request stopped waiting, sending unpaced", "host", host, "err", err)
+ slog.Warn("[traffic] pacing request stopped waiting, sending unpaced", "host", host, "err", err)
}
}
diff --git a/traffic/raw_tcp.go b/traffic/raw_tcp.go
index 299d097..4baeebb 100644
--- a/traffic/raw_tcp.go
+++ b/traffic/raw_tcp.go
@@ -64,13 +64,13 @@ func (t *Traffic) spillRawDir(data []byte, previewCap int) (preview []byte, blob
h := hex.EncodeToString(sum[:])
blobDir := filepath.Join(t.dir, "_blobs", "sha256", h[:2])
if err := os.MkdirAll(blobDir, 0o700); err != nil {
- slog.Error("failed to create blob directory", "err", err)
+ slog.Error("[traffic/socks5] failed to create blob directory", "err", err)
return append([]byte(nil), data[:previewCap]...), ""
}
blobPath := filepath.Join(blobDir, h+".bin")
if _, err := os.Stat(blobPath); os.IsNotExist(err) {
if err := writeBlobAtomic(blobDir, blobPath, h, data); err != nil {
- slog.Error("failed to write blob", "hash", h, "err", err)
+ slog.Error("[traffic/socks5] failed to write blob", "hash", h, "err", err)
return append([]byte(nil), data[:previewCap]...), ""
}
}
diff --git a/traffic/rewrite_flow.go b/traffic/rewrite_flow.go
index 8247544..2f1796c 100644
--- a/traffic/rewrite_flow.go
+++ b/traffic/rewrite_flow.go
@@ -219,7 +219,7 @@ func (t *snapTable) convertLocked(cost int64) bool {
t.tombs++
*victim = reqSnap{done: victim.done, rules: victim.rules, host: victim.host, tomb: true, reason: reasonOriginalUnavailable, ruleIDs: ids}
t.conversions.Add(1)
- slog.Warn("rewrite snapshot released under pressure, exchange recorded as original request unavailable", "host", victim.host, "rules", ids)
+ slog.Warn("[traffic] rewrite snapshot released under pressure, exchange recorded as original request unavailable", "host", victim.host, "rules", ids)
return true
}
@@ -239,7 +239,7 @@ func (t *snapTable) refuseLocked(k flowKey, e *reqSnap) {
}
if now := t.now(); now.Sub(t.lastFullLog) >= time.Minute {
t.lastFullLog = now
- slog.Warn("rewrite snapshot table full, requests sent without rewriting", "refused", t.capacity.Load(), "without_trace", t.tombDrops.Load())
+ slog.Warn("[traffic] rewrite snapshot table full, requests sent without rewriting", "refused", t.capacity.Load(), "without_trace", t.tombDrops.Load())
}
}
@@ -469,7 +469,7 @@ func (s *sink) Request(f *mproxy.Flow) {
host := f.Request.URL.Hostname()
defer func() {
if recover() != nil {
- slog.Error("rewrite rules panicked on request, sent as-is", "host", host, "class", rewrite.ErrClassPanic)
+ slog.Error("[traffic] rewrite rules panicked on request, sent as-is", "host", host, "class", rewrite.ErrClassPanic)
}
}()
in := rewrite.Input{Request: engineRequest(f.Request), IsBinary: rulesIsBinary}
@@ -541,7 +541,7 @@ func (s *sink) applyResponse(f *mproxy.Flow, set *rewrite.Set, hooks *HookSet, i
defer func() {
if recover() != nil {
res = rewrite.Result{}
- slog.Error("rewrite rules panicked on response, sent as-is", "host", f.Request.URL.Hostname(), "class", rewrite.ErrClassPanic)
+ slog.Error("[traffic] rewrite rules panicked on response, sent as-is", "host", f.Request.URL.Hostname(), "class", rewrite.ErrClassPanic)
}
}()
r := set.Apply(rewrite.PhaseResponse, in)
@@ -614,7 +614,7 @@ func (s *sink) applyRequestTrace(f *mproxy.Flow, set *rewrite.Set, hooks *HookSe
defer func() {
if recover() != nil {
lines = nil
- slog.Error("rewrite rules panicked on request", "host", f.Request.URL.Hostname(), "class", rewrite.ErrClassPanic)
+ slog.Error("[traffic] rewrite rules panicked on request", "host", f.Request.URL.Hostname(), "class", rewrite.ErrClassPanic)
}
}()
in := rewrite.Input{Request: req, IsBinary: rulesIsBinary}
@@ -649,7 +649,7 @@ func (s *sink) RequestError(f *mproxy.Flow, err error) {
for _, id := range ids {
snap.rules.NoteError(id, rewrite.ErrClassTransport)
}
- slog.Warn("rewritten request failed, host stays intercepted", "host", snap.host, "rules", ids, "class", rewrite.ErrClassTransport)
+ slog.Warn("[traffic] rewritten request failed, host stays intercepted", "host", snap.host, "rules", ids, "class", rewrite.ErrClassTransport)
return
}
}
@@ -675,7 +675,7 @@ func (s *sink) StreamResponseModifier(f *mproxy.Flow, in io.Reader) (out io.Read
return in
}
s.t.snaps.largeResponses.Add(1)
- slog.Warn("large response passed through, not recorded", "host", snap.host, "rules", snap.appliedRuleIDs(), "size_mib", libraryStreamBody>>20)
+ slog.Warn("[traffic] large response passed through, not recorded", "host", snap.host, "rules", snap.appliedRuleIDs(), "size_mib", libraryStreamBody>>20)
return in
}
diff --git a/traffic/socks5.go b/traffic/socks5.go
index 5fd3417..ca735d5 100644
--- a/traffic/socks5.go
+++ b/traffic/socks5.go
@@ -157,7 +157,7 @@ func SOCKS5ConfigFromEnv() (SOCKS5Config, bool) {
case "1", "true", "on", "yes":
enableUDP = true
default:
- slog.Warn("non-boolean SOCKS5 UDP env value, leaving disabled", "env", SOCKS5UDPEnabledEnv, "value", rawUDP)
+ slog.Warn("[traffic] non-boolean SOCKS5 UDP env value, leaving disabled", "env", SOCKS5UDPEnabledEnv, "value", rawUDP)
}
switch rawEnabled {
@@ -179,7 +179,7 @@ func SOCKS5ConfigFromEnv() (SOCKS5Config, bool) {
}
return SOCKS5Config{Addr: addr, EnableUDP: enableUDP}, true
default:
- slog.Warn("non-boolean SOCKS5 env value, leaving disabled", "env", SOCKS5EnabledEnv, "value", rawEnabled)
+ slog.Warn("[traffic] non-boolean SOCKS5 env value, leaving disabled", "env", SOCKS5EnabledEnv, "value", rawEnabled)
return SOCKS5Config{}, false
}
}
@@ -343,7 +343,7 @@ func (s *socks5Server) serve() {
if errors.As(err, &ne) && ne.Timeout() {
continue
}
- slog.Error("socks5 accept error", "err", err)
+ slog.Error("[traffic/socks5] socks5 accept error", "err", err)
return
}
if !s.trackConn(conn) {
@@ -447,7 +447,7 @@ func (s *socks5Server) handleConn(client net.Conn) {
func (s *socks5Server) recordCapture(rec RawTCPCapture) {
if s.t != nil && s.t.db != nil {
if _, err := s.t.RecordRawTCPStream(rec, s.cfg.PreviewBytes); err != nil {
- slog.Error("failed to record raw tcp stream", "host", rec.Host, "port", rec.Port, "err", err)
+ slog.Error("[traffic/socks5] failed to record raw tcp stream", "host", rec.Host, "port", rec.Port, "err", err)
}
}
if s.cfg.OnRecord != nil {
diff --git a/traffic/socks5_udp.go b/traffic/socks5_udp.go
index 77d72d9..f0b8d8e 100644
--- a/traffic/socks5_udp.go
+++ b/traffic/socks5_udp.go
@@ -438,7 +438,7 @@ func (s *socks5Server) recordUDPCapture(rec RawUDPCapture) {
}
if s.t != nil && s.t.db != nil {
if _, err := s.t.RecordRawUDPDatagram(rec, s.cfg.UDPPreviewBytes); err != nil {
- slog.Error("failed to record UDP datagram", "assoc", rec.AssociationID, "dst_host", rec.Host, "dst_port", rec.Port, "err", err)
+ slog.Error("[traffic/socks5-udp] failed to record UDP datagram", "assoc", rec.AssociationID, "dst_host", rec.Host, "dst_port", rec.Port, "err", err)
}
}
}
diff --git a/traffic/stream.go b/traffic/stream.go
index 9f113f4..173bbe2 100644
--- a/traffic/stream.go
+++ b/traffic/stream.go
@@ -152,10 +152,10 @@ func (s *sink) startStream(f *mproxy.Flow, kind string) {
if rewritten, ruleIDs := appliedRules(lines); rewritten {
var re *recordError
errors.As(err, &re)
- slog.Error("failed to record rewritten stream", "kind", kind, "host", f.Request.URL.Hostname(), "step", re.step, "rules", ruleIDs)
+ slog.Error("[traffic] failed to record rewritten stream", "kind", kind, "host", f.Request.URL.Hostname(), "step", re.step, "rules", ruleIDs)
return
}
- slog.Error("failed to record stream", "kind", kind, "url", f.Request.URL.String(), "err", err)
+ slog.Error("[traffic] failed to record stream", "kind", kind, "url", f.Request.URL.String(), "err", err)
return
}
st.id = id
@@ -200,7 +200,7 @@ func lockLib(v any) (unlock func(), ok bool) {
mu := libMutex(v)
if mu == nil {
libMutexMissing.Do(func() {
- slog.Warn("go-mitmproxy stream data has no mu field; stream messages are not recorded")
+ slog.Warn("[traffic] go-mitmproxy stream data has no mu field; stream messages are not recorded")
})
return nil, false
}
@@ -424,7 +424,7 @@ func (t *Traffic) persistStream(st *streamState, rows []streamRow) {
tx, err := t.db.Begin()
if err != nil {
- slog.Error("failed to record stream messages", "exchange_id", st.id, "step", "begin tx", "err", err)
+ slog.Error("[traffic] failed to record stream messages", "exchange_id", st.id, "step", "begin tx", "err", err)
return
}
defer tx.Rollback() //nolint:errcheck // no-op once committed
@@ -436,12 +436,12 @@ func (t *Traffic) persistStream(st *streamState, rows []streamRow) {
if _, err := tx.Exec(`INSERT INTO stream_messages(exchange_id,seq,ts,direction,kind,event,event_id,retry,size,payload,payload_blob,truncated)
VALUES(?,?,?,?,?,?,?,?,?,?,?,?)`, st.id, p.seq, p.ts, p.direction, p.kind, p.event, p.eventID, p.retry, p.size,
inline, nullIfEmpty(p.body.hash), boolInt(p.truncated)); err != nil {
- slog.Error("failed to record stream message", "seq", p.seq, "exchange_id", st.id, "err", err)
+ slog.Error("[traffic] failed to record stream message", "seq", p.seq, "exchange_id", st.id, "err", err)
return
}
if p.body.hash != "" {
if _, err := tx.Exec(`INSERT OR IGNORE INTO blob_refs(hash,exchange_id) VALUES(?,?)`, p.body.hash, st.id); err != nil {
- slog.Error("failed to register stream message blob ref", "seq", p.seq, "exchange_id", st.id, "err", err)
+ slog.Error("[traffic] failed to register stream message blob ref", "seq", p.seq, "exchange_id", st.id, "err", err)
return
}
}
@@ -449,12 +449,12 @@ VALUES(?,?,?,?,?,?,?,?,?,?,?,?)`, st.id, p.seq, p.ts, p.direction, p.kind, p.eve
if meta != nil {
if _, err := tx.Exec(`INSERT INTO stream_messages(exchange_id,seq,ts,direction,kind,size,payload)
VALUES(?,?,?,'meta',0,?,?)`, st.id, metaSeq, time.Now().Unix(), len(meta), meta); err != nil {
- slog.Error("failed to record stream limit marker", "exchange_id", st.id, "err", err)
+ slog.Error("[traffic] failed to record stream limit marker", "exchange_id", st.id, "err", err)
return
}
}
if err := tx.Commit(); err != nil {
- slog.Error("failed to record stream messages", "exchange_id", st.id, "step", "commit", "err", err)
+ slog.Error("[traffic] failed to record stream messages", "exchange_id", st.id, "step", "commit", "err", err)
}
}
@@ -493,12 +493,12 @@ func (t *Traffic) finishStream(st *streamState) {
t.wmu.Lock()
defer t.wmu.Unlock()
if _, err := t.db.Exec(`UPDATE exchanges SET req_len=?, resp_len=? WHERE id=?`, st.reqBytes, st.respBytes, st.id); err != nil {
- slog.Error("failed to record stream sizes", "exchange_id", st.id, "err", err)
+ slog.Error("[traffic] failed to record stream sizes", "exchange_id", st.id, "err", err)
}
if st.dropped {
meta := streamMetaPayload(st)
if _, err := t.db.Exec(`UPDATE stream_messages SET payload=?, size=? WHERE exchange_id=? AND direction='meta'`, meta, len(meta), st.id); err != nil {
- slog.Error("failed to update stream limit marker", "exchange_id", st.id, "err", err)
+ slog.Error("[traffic] failed to update stream limit marker", "exchange_id", st.id, "err", err)
}
}
}
diff --git a/traffic/traffic.go b/traffic/traffic.go
index 39072ce..b84d493 100644
--- a/traffic/traffic.go
+++ b/traffic/traffic.go
@@ -412,7 +412,7 @@ func (t *Traffic) initIndex() error {
}
t.incrementalVacuum = mode == autoVacuumIncremental
if !t.incrementalVacuum {
- slog.Warn("index database does not have incremental vacuum enabled: deleting traffic will not shrink index.sqlite; run one storage compaction to convert it", "auto_vacuum", mode)
+ slog.Warn("[traffic] index database does not have incremental vacuum enabled: deleting traffic will not shrink index.sqlite; run one storage compaction to convert it", "auto_vacuum", mode)
}
if _, err := conn.ExecContext(ctx, indexSchema); err != nil {
return err
@@ -421,7 +421,7 @@ func (t *Traffic) initIndex() error {
return err
}
if _, err := conn.ExecContext(ctx, ftsSchema); err != nil {
- slog.Warn("full-text index unavailable; body search will be disabled", "err", err)
+ slog.Warn("[traffic] full-text index unavailable; body search will be disabled", "err", err)
return nil
}
t.fts = true
@@ -623,7 +623,7 @@ func (t *Traffic) maybePassthrough(f *mproxy.Flow, err error) {
}
until := time.Now().Add(passthroughTTL)
if _, loaded := t.pass.LoadOrStore(host, until); !loaded {
- slog.Warn("MITM failed, falling back to passthrough", "host", host, "ttl", passthroughTTL, "err", err)
+ slog.Warn("[traffic] MITM failed, falling back to passthrough", "host", host, "ttl", passthroughTTL, "err", err)
}
}
@@ -740,10 +740,10 @@ func (t *Traffic) recordViews(rq requestView, rs responseView, lines []rewrite.T
rewritten, ruleIDs := appliedRules(lines)
fail := func(step string, err error) {
if rewritten {
- slog.Error("failed to record rewritten exchange", "host", host, "step", step, "rules", ruleIDs)
+ slog.Error("[traffic] failed to record rewritten exchange", "host", host, "step", step, "rules", ruleIDs)
return
}
- slog.Error("failed to record exchange", "url", url, "step", step, "err", err)
+ slog.Error("[traffic] failed to record exchange", "url", url, "step", step, "err", err)
}
tx, err := t.db.Begin()
@@ -870,14 +870,14 @@ func tightenBlobPerms(root string) {
if d.IsDir() {
if info.Mode().Perm() != 0o700 {
if err := os.Chmod(path, 0o700); err != nil {
- slog.Error("failed to restrict blob directory", "path", path, "err", err)
+ slog.Error("[traffic] failed to restrict blob directory", "path", path, "err", err)
}
}
return nil
}
if info.Mode().IsRegular() && info.Mode().Perm() != 0o600 {
if err := os.Chmod(path, 0o600); err != nil {
- slog.Error("failed to restrict blob", "path", path, "err", err)
+ slog.Error("[traffic] failed to restrict blob", "path", path, "err", err)
}
}
return nil
@@ -911,20 +911,20 @@ func (t *Traffic) spillAt(body []byte, contentType string, maxInline int) stored
// the store only ever holds bodies above maxInlineBody, deduplicated by hash.
blobDir := filepath.Join(t.dir, "_blobs", "sha256", h[:2])
if err := os.MkdirAll(blobDir, 0o700); err != nil {
- slog.Error("failed to create blob directory", "err", err)
+ slog.Error("[traffic] failed to create blob directory", "err", err)
return storedBody{inline: clipBytes(body, blobPreview), index: indexText()}
}
if err := os.Chmod(blobDir, 0o700); err != nil {
- slog.Error("failed to restrict blob directory", "err", err)
+ slog.Error("[traffic] failed to restrict blob directory", "err", err)
}
blobPath := filepath.Join(blobDir, h+".bin")
if _, err := os.Stat(blobPath); os.IsNotExist(err) {
if err := os.WriteFile(blobPath, body, 0o600); err != nil {
- slog.Error("failed to write blob", "hash", h, "err", err)
+ slog.Error("[traffic] failed to write blob", "hash", h, "err", err)
return storedBody{inline: clipBytes(body, blobPreview), index: indexText()}
}
} else if err := os.Chmod(blobPath, 0o600); err != nil {
- slog.Error("failed to restrict blob", "hash", h, "err", err)
+ slog.Error("[traffic] failed to restrict blob", "hash", h, "err", err)
}
sb := storedBody{hash: h, index: indexText()}
if text {
@@ -1607,7 +1607,7 @@ func (t *Traffic) DeleteAll() (deleted int64, reclaimed int64, err error) {
if err := t.compactIndex(); err != nil {
// The deletion is already durable; compaction is disk space, not
// correctness, so it must not turn a completed purge into a failed one.
- slog.Error("failed to compact index", "err", err)
+ slog.Error("[traffic] failed to compact index", "err", err)
return deleted, 0, nil
}
return deleted, before - t.indexBytes(), nil
@@ -1861,7 +1861,7 @@ func (t *Traffic) reapStage(stageDir string) {
}
t.reaping.Go(func() {
if err := os.RemoveAll(stageDir); err != nil {
- slog.Error("failed to clean up legacy traffic directory", "dir", stageDir, "err", err)
+ slog.Error("[traffic] failed to clean up legacy traffic directory", "dir", stageDir, "err", err)
}
})
}
@@ -2215,7 +2215,7 @@ func (t *Traffic) reclaim() {
ctx := context.Background()
conn, err := t.db.Conn(ctx)
if err != nil {
- slog.Error("failed to reclaim index space", "step", "get connection", "err", err)
+ slog.Error("[traffic] failed to reclaim index space", "step", "get connection", "err", err)
return
}
defer conn.Close()
@@ -2226,7 +2226,7 @@ func (t *Traffic) reclaim() {
progressed, err := t.reclaimChunk(ctx, conn, &merges)
t.wmu.Unlock()
if err != nil {
- slog.Error("failed to reclaim index space", "err", err)
+ slog.Error("[traffic] failed to reclaim index space", "err", err)
return
}
if !progressed {
@@ -2236,11 +2236,11 @@ func (t *Traffic) reclaim() {
return // shutdown must not wait out the remaining budget
}
if step+1 >= reclaimMaxSteps {
- slog.Info("index space reclamation unfinished, will continue on the next deletion", "reason", "step limit", "max_steps", reclaimMaxSteps)
+ slog.Info("[traffic] index space reclamation unfinished, will continue on the next deletion", "reason", "step limit", "max_steps", reclaimMaxSteps)
return
}
if time.Now().After(deadline) {
- slog.Info("index space reclamation unfinished, will continue on the next deletion", "reason", "time budget", "budget", reclaimBudget)
+ slog.Info("[traffic] index space reclamation unfinished, will continue on the next deletion", "reason", "time budget", "budget", reclaimBudget)
return
}
}
@@ -2250,7 +2250,7 @@ func (t *Traffic) reclaim() {
t.wmu.Lock()
defer t.wmu.Unlock()
if _, err := conn.ExecContext(ctx, `PRAGMA wal_checkpoint(TRUNCATE)`); err != nil {
- slog.Error("failed to truncate WAL", "err", err)
+ slog.Error("[traffic] failed to truncate WAL", "err", err)
}
})
}
diff --git a/traffic/transparent.go b/traffic/transparent.go
index fbf63b2..0b39569 100644
--- a/traffic/transparent.go
+++ b/traffic/transparent.go
@@ -96,7 +96,7 @@ func TransparentTCPConfigFromEnv() (TransparentTCPConfig, bool) {
}
return TransparentTCPConfig{Addr: rawAddr}, true
default:
- slog.Warn("transparent TCP env var is not a boolean, leaving disabled", "env", TransparentTCPEnabledEnv, "value", rawEnabled)
+ slog.Warn("[traffic] transparent TCP env var is not a boolean, leaving disabled", "env", TransparentTCPEnabledEnv, "value", rawEnabled)
return TransparentTCPConfig{}, false
}
}
@@ -302,7 +302,7 @@ func (s *transparentServer) serve() {
if errors.As(err, &ne) && ne.Timeout() {
continue
}
- slog.Error("transparent proxy accept error", "err", err)
+ slog.Error("[traffic/transparent] transparent proxy accept error", "err", err)
return
}
if !s.trackConn(conn) {
@@ -389,7 +389,7 @@ func (s *transparentServer) handleConn(client net.Conn) {
C2SData: c2sCap.buf,
S2CData: s2cCap.buf,
}, s.cfg.PreviewBytes); err != nil {
- slog.Error("failed to record raw TCP stream", "target", targetAddr, "err", err)
+ slog.Error("[traffic/transparent] failed to record raw TCP stream", "target", targetAddr, "err", err)
}
}
}