Skip to content

Log timestamps show UTC instead of the user's configured timezone #289

Description

@kindralai

Problem

Log timestamps in the admin Logs tab show UTC time instead of the user's configured timezone. For example, at 14:59 CEST (Europe/Zurich, UTC+2) the log shows 12:59:00.

Root cause

_BufferHandler.emit() at admin.py:456 formats timestamps using the system's local timezone:

"time": datetime.fromtimestamp(record.created).strftime("%H:%M:%S"),

datetime.fromtimestamp() without a tz argument uses the system/process timezone, which in Docker is typically UTC. The user's configured timezone is stored in the agent config (config.agent.timezone, default "Europe/Zurich") and is also editable via the You tab in the admin UI, but the log handler never reads it.

Affected area

  • Logs tab (/partials/logs-content): every log line's time field is formatted in UTC
  • The ts field (record.created) stores the correct UTC Unix timestamp, so the data is not lost — it's purely a display-time conversion issue

Proposed fix

In _BufferHandler.emit(), resolve the configured timezone and use it for formatting:

from zoneinfo import ZoneInfo

# Resolve the user's timezone (agent config, fallback UTC)
tz_name = "UTC"
if agent_state and agent_state.agent and agent_state.agent.config:
    tz_name = getattr(agent_state.agent.config.agent, "timezone", None) or tz_name

"time": datetime.fromtimestamp(
    record.created, tz=ZoneInfo(tz_name)
).strftime("%H:%M:%S"),

Alternatively, the timezone can be read from config_store.get("agent.timezone") if agent_state is unavailable (e.g. during startup before the agent is initialised).

Acceptance criteria

  • Log timestamps show the user's configured timezone from the You tab
  • When no timezone is configured (or during startup before the agent loads), fall back to UTC
  • Changing the timezone in the You tab is reflected in new log lines (no restart needed)
  • The ts field (Unix timestamp) is unaffected — it remains UTC for internal use
  • Timezone change applies to newly emitted log lines only (historic lines keep their rendered time, which is acceptable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions