Skip to content

Centralize desktop log infrastructure [WPB-27016]#9692

Open
screendriver wants to merge 8 commits into
devfrom
refactor/centralize-desktop-log-infrastructure
Open

Centralize desktop log infrastructure [WPB-27016]#9692
screendriver wants to merge 8 commits into
devfrom
refactor/centralize-desktop-log-infrastructure

Conversation

@screendriver

@screendriver screendriver commented Jul 10, 2026

Copy link
Copy Markdown
Member
TaskWPB-27016 [Web] Fix desktop log rotation, retention, and directory organization

Problem

Desktop logging responsibilities are currently spread across the Electron main process, the logger factory, SSO logging, log export, and account deletion.

Several modules construct their own paths below app.getPath('userData'). Some of these paths are resolved during module initialization, before portable mode or --user_data_dir can update Electron's final user-data location.

This duplication makes the logging lifecycle difficult to understand and makes subsequent rotation and retention changes unnecessarily risky.

Intent

Create one explicit boundary for desktop log paths and filesystem operations without changing the existing logging behavior.

This pull request prepares the codebase for later changes to restart handling, rotation, retention, and directory organization.

Add Electron-independent helpers for constructing the existing log root, main-process log file, legacy webview directory, and SSO log file paths.

Cover the legacy path formats with focused main-process tests. No runtime call sites or logging behavior change in this commit.
Read Electron’s current user-data directory whenever the main-process logger is created, so portable and custom user-data paths determine the log root.

Add regression coverage proving the resolved log directory changes when Electron’s user-data path changes. No log files are written by the test.
Apply portable user-data configuration before main logger creation and resolve all main-process log paths through the logging helpers.

Preserve the existing webview log directory format and startup behavior while removing duplicated path construction from main.ts.
Resolve the log root lazily for SSO console logging and account log deletion.

Use shared path helpers while preserving the existing account log-file layout and deletion target.
Resolve the default log root lazily for discovery and export.

Add temporary-directory regression coverage for nested .log and .old files, symbolic-link exclusion, relative and absolute results, and preserved export paths.
Move the existing startup .log-to-.old migration into the logging module.

Keep main.ts focused on orchestration and add temporary-directory coverage for nested log migration while preserving existing .old files.
Avoid creating SSO, account-deletion, and log-export loggers during module initialization.

This ensures their log paths are resolved only after portable or custom user-data configuration has taken effect.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

@semgrep-code-wireapp

Copy link
Copy Markdown

Semgrep found 12 path-join-resolve-traversal findings:

Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

View Dataflow Graph
flowchart LR
    classDef invis fill:white, stroke: none
    classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none

    subgraph File0["<b>electron/src/logging/loggerUtils.ts</b>"]
        direction LR
        %% Source

        subgraph Source
            direction LR

            v0["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L34 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 34] base</a>"]
        end
        %% Intermediate

        subgraph Traces0[Traces]
            direction TB

            v2["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L34 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 34] base</a>"]

            v3["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L41 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 41] getLogFilenames</a>"]

            v4["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L41 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 41] relativeFilePaths</a>"]

            v5["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L43 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 43] of</a>"]

            v6["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L43 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 43] relativeFilePath</a>"]
        end
            v2 --> v3
            v3 --> v4
            v4 --> v5
            v5 --> v6
        %% Sink

        subgraph Sink
            direction LR

            v1["<a href=https://github.com/wireapp/wire-desktop/blob/bc1bfe54974d78e3beca0c1765a2d396ad9a8f94/electron/src/logging/loggerUtils.ts#L44 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 44] relativeFilePath</a>"]
        end
    end
    %% Class Assignment
    Source:::invis
    Sink:::invis

    Traces0:::invis
    File0:::invis

    %% Connections

    Source --> Traces0
    Traces0 --> Sink

Loading

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants