Skip to content

fix(logging): render heartbeat payloads in debug output#226

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:bob/log-heartbeat-data-196
Open

fix(logging): render heartbeat payloads in debug output#226
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:bob/log-heartbeat-data-196

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Fixes #196.

Summary

  • add a small formatter for heartbeat debug payloads
  • log previous/current heartbeat data as readable key=value text instead of raw objects
  • keep the change scoped to the heartbeat path called out in the issue

Verification

  • npx tsc --noEmit
  • npx vite build
  • npx prettier --check src/background/heartbeat.ts

@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a small formatter function to render heartbeat payloads as readable text in debug logs. The two debug log calls inside the core heartbeat function are updated to use it.

  • The new formatHeartbeatLogData function serialises each field using JSON stringify with an explicit undefined fallback.
  • Debug output now shows all heartbeat fields with quoted strings and unquoted primitives instead of a raw object dump.

Confidence Score: 5/5

Safe to merge — the change is additive and scoped to debug logging with no impact on heartbeat send logic.

The formatter is a pure string-building utility with no side effects. Both updated log sites call it only inside existing conditional branches, leaving the heartbeat send path unchanged. All expected value types are handled correctly by JSON.stringify.

No files require special attention.

Important Files Changed

Filename Overview
src/background/heartbeat.ts Adds formatHeartbeatLogData and updates two debug log calls; correct handling of all expected value types, no logic issues introduced.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[heartbeat called] --> B{tab valid?}
    B -- No --> C[warn + return]
    B -- Yes --> D[build data object]
    D --> E[getHeartbeatData]
    E --> F{previousData exists AND differs?}
    F -- Yes --> G[formatHeartbeatLogData previousData]
    G --> H[console.debug previous payload]
    H --> I[sendHeartbeat previousData]
    F -- No --> J[formatHeartbeatLogData current data]
    I --> J
    J --> K[console.debug current payload]
    K --> L[sendHeartbeat current data]
    L --> M[setHeartbeatData]
Loading

Reviews (2): Last reviewed commit: "fix(logging): quote string heartbeat log..." | Re-trigger Greptile

Comment on lines +12 to +17
const formattedValue =
typeof value === 'string'
? value
: value === undefined
? 'undefined'
: JSON.stringify(value)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unquoted string values may make the log ambiguous when a URL or page title contains the , separator. For example, url=https://example.com, title=Hello, World is hard to parse visually. Wrapping string values in quotes makes field boundaries unambiguous.

Suggested change
const formattedValue =
typeof value === 'string'
? value
: value === undefined
? 'undefined'
: JSON.stringify(value)
const formattedValue =
typeof value === 'string'
? JSON.stringify(value)
: value === undefined
? 'undefined'
: JSON.stringify(value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logging prints [object Object] instead of actual object

1 participant