Skip to content

chore: avoid log files on disk and move them to console for containers #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fmenezes
Copy link
Collaborator

@fmenezes fmenezes commented Jul 4, 2025

Proposed changes

stop storing log files on disk for containers, log them to console

Checklist

@fmenezes fmenezes marked this pull request as ready for review July 4, 2025 16:40
@Copilot Copilot AI review requested due to automatic review settings July 4, 2025 16:40
@fmenezes fmenezes requested a review from a team as a code owner July 4, 2025 16:40
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR centralizes container detection logic, removes disk-based log files in container environments, and adds presets to switch between console and file logging.

  • Extract detectContainerEnv into a shared util
  • Update Telemetry and Server to use container detection for choosing log presets
  • Rename and split initializeLogger into setStdioPreset (file logging) and setDockerPreset (console logging)

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/common/container.ts New detectContainerEnv helper to detect Linux container runtime
src/telemetry/telemetry.ts Remove inline isContainerEnv, import and use detectContainerEnv
src/server.ts Replace initializeLogger with setStdioPreset/setDockerPreset based on container detection
src/logger.ts Split logger init into setStdioPreset and setDockerPreset
Comments suppressed due to low confidence (3)

src/common/container.ts:3

  • Add unit tests for detectContainerEnv to verify correct container detection across different environments (e.g., with and without /.dockerenv files).
export async function detectContainerEnv(): Promise<boolean> {

src/logger.ts:183

  • [nitpick] Public API functions setStdioPreset and setDockerPreset are undocumented; adding JSDoc comments would clarify their behavior and parameters.
export async function setStdioPreset(server: McpServer, logPath: string): Promise<void> {

src/logger.ts:190

  • [nitpick] The name setStdioPreset implies STDIO logging but configures a DiskLogger; consider renaming it (e.g., setFilePreset) to avoid confusion.
export function setDockerPreset(server: McpServer): void {

Comment on lines 3 to 9
export async function detectContainerEnv(): Promise<boolean> {
if (process.platform !== "linux") {
return false; // we only support linux containers for now
}

if (process.env.container) {
return true;
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Consider caching the result of detectContainerEnv in a module‐level variable to avoid repeated filesystem checks when invoked multiple times.

Suggested change
export async function detectContainerEnv(): Promise<boolean> {
if (process.platform !== "linux") {
return false; // we only support linux containers for now
}
if (process.env.container) {
return true;
let cachedContainerEnv: boolean | null = null;
export async function detectContainerEnv(): Promise<boolean> {
if (cachedContainerEnv !== null) {
return cachedContainerEnv;
}
if (process.platform !== "linux") {
cachedContainerEnv = false; // we only support linux containers for now
return cachedContainerEnv;
}
if (process.env.container) {
cachedContainerEnv = true;
return cachedContainerEnv;

Copilot uses AI. Check for mistakes.

@coveralls
Copy link
Collaborator

coveralls commented Jul 4, 2025

Pull Request Test Coverage Report for Build 16078025857

Details

  • 14 of 21 (66.67%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 74.053%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/server.ts 3 4 75.0%
src/common/container.ts 11 14 78.57%
src/logger.ts 0 3 0.0%
Totals Coverage Status
Change from base Build 16077040616: -0.1%
Covered Lines: 821
Relevant Lines: 1029

💛 - Coveralls

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