Skip to content

Conversation

@adamoutler
Copy link
Collaborator

@adamoutler adamoutler commented Sep 23, 2025

The stdout and stderr are useful logs when debugging and trying to figure out why plugin output is causing backend to stop and exception. This commit enables output redirection to /app/stdout.log and /app/stderr.log from the backend. This may need backporting to production as it appears the fields are unused in the frontend log page.

Additionally, when searching logs in the UI, the old logs appear first and your search results will invariably find old information when searching with ctrl-f-"string"-enter. So upon backend start and to keep them relevant, the stdout, stderr, and app logs are cleared.

Summary by CodeRabbit

  • Chores

    • Improved backend startup logging: stdout, stderr, and application logs are now written to dedicated files for better visibility during development and container runs.
    • Added an initial log entry to ensure log files are created/truncated before the service starts.
  • Style

    • Minor formatting and quoting cleanup to improve readability without changing behavior.

The stdout and stderr are useful logs when debugging and trying to figure out why plugin output is causing backend to stop and exception. This commit enables output redirection to `/app/stdout.log` and `/app/stderr.log` from the backend.  This may need backporting to production as it appears the fields are unused in the backend. 

Additionally, when searching logs in the UI, the old logs appear first and your search results will invariably find old information when searching with ctrl-f-"string"-enter. So upon backend start and to keep them relevant, the stdout, stderr, and app logs are cleared.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

The devcontainer backend restart script now initializes log files and redirects stdout and stderr into /app/log/stdout.log and /app/log/stderr.log (stdout/app.log captured via tee) instead of discarding output to /dev/null; launch still uses setsid and background execution.

Changes

Cohort / File(s) Summary of changes
Devcontainer backend restart script
.devcontainer/scripts/restart-backend.sh
Initialize/truncate log files with an initial echo piped to tee; redirect stdout to 1>>"$LOG_DIR/stdout.log" and stderr to 2>>"$LOG_DIR/stderr.log" and capture app.log via tee instead of >/dev/null; preserve background launch with setsid and minor formatting/quoting adjustments.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User as DevContainer
    participant Script as restart-backend.sh
    participant Sys as Shell
    participant Backend as Backend Process
    participant Logs as /app/log/*.log

    User->>Script: run restart-backend.sh
    Note over Script: ensure log files exist / truncate
    Script->>Logs: echo "" \|& tee -a stdout.log stderr.log (create/truncate)

    Note over Script,Sys: launch backend in background via setsid
    Script->>Sys: setsid "${PY}" --port ... 1>>"$LOG_DIR/stdout.log" 2>>"$LOG_DIR/stderr.log" \&

    Sys-->>Backend: start process (background)
    Backend-->>Logs: stdout appended to stdout.log
    Backend-->>Logs: stderr appended to stderr.log
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble at logs, soft and bright,
No more /dev/null in the night.
Tee catches whispers, stdout and cry,
Little pawprints of each byte go by.
Hop, restart—our burrow logs light. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Rework Logging in restart-backend.sh" is concise, names the affected file, and accurately summarizes the primary change to the script's logging behavior (redirecting/clearing stdout and stderr), matching the PR description and diffs.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47f23fc and d843fd4.

📒 Files selected for processing (1)
  • .devcontainer/scripts/restart-backend.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .devcontainer/scripts/restart-backend.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: docker_dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b787589 and 47f23fc.

📒 Files selected for processing (1)
  • .devcontainer/scripts/restart-backend.sh (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: adamoutler
PR: jokob-sk/NetAlertX#1184
File: .devcontainer/scripts/stream-logs.sh:5-6
Timestamp: 2025-09-20T14:08:44.292Z
Learning: The .devcontainer/scripts/stream-logs.sh script in NetAlertX is designed as a diagnostic tool for troubleshooting devcontainer startup issues. When log files don't exist, this indicates that the executable/services didn't start properly, which is valuable diagnostic information. Pre-creating missing files would mask this diagnostic behavior.
📚 Learning: 2025-09-20T14:08:44.292Z
Learnt from: adamoutler
PR: jokob-sk/NetAlertX#1184
File: .devcontainer/scripts/stream-logs.sh:5-6
Timestamp: 2025-09-20T14:08:44.292Z
Learning: The .devcontainer/scripts/stream-logs.sh script in NetAlertX is designed as a diagnostic tool for troubleshooting devcontainer startup issues. When log files don't exist, this indicates that the executable/services didn't start properly, which is valuable diagnostic information. Pre-creating missing files would mask this diagnostic behavior.

Applied to files:

  • .devcontainer/scripts/restart-backend.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: docker_dev

@jokob-sk
Copy link
Collaborator

LMK if you'd like to address the review notes or I just merge it

adamoutler and others added 2 commits September 23, 2025 11:59
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@adamoutler
Copy link
Collaborator Author

adamoutler commented Sep 23, 2025

Go ahead and pull. Thanks.

@jokob-sk jokob-sk merged commit 3dd5c4b into netalertx:main Sep 24, 2025
4 checks passed
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.

2 participants