Skip to content

Feat/logging fixes#69

Merged
thedevyashsaini merged 2 commits into
mainfrom
feat/logging-fixes
Jun 9, 2026
Merged

Feat/logging fixes#69
thedevyashsaini merged 2 commits into
mainfrom
feat/logging-fixes

Conversation

@thedevyashsaini

Copy link
Copy Markdown
Member

No description provided.

@thedevyashsaini thedevyashsaini merged commit f7f7017 into main Jun 9, 2026
2 of 3 checks passed
@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR reworks the logger to read SCRAWN_DEBUG and SCRAWN_LOG_FILE from the environment (dropping the static ScrawnConfig.logging.enableDebug flag) and adds a graceful fallback when the log file cannot be written. It also updates parseURLToTarget to infer protocol-aware default ports instead of always falling back to the gRPC default.

  • logger.ts: initialization is now wrapped in try/catch with a pino silent fallback; log level and file path are fully env-driven.
  • scrawn.ts: parseURLToTarget now maps https: → 443, http: → 80, other → ScrawnConfig.grpc.defaultPort; the http: → 80 mapping is incorrect for gRPC and will silently break connections when no explicit port is provided.

Confidence Score: 3/5

The logger refactor is safe, but the port-mapping change in parseURLToTarget introduces a silent connectivity regression for http:// URLs without an explicit port.

Any caller using a bare http:// URL (e.g. http://my-grpc-server) without an explicit port will now attempt to connect to port 80 instead of the SDK's gRPC default 8069, causing connection failures with no error message indicating the wrong port was chosen. The logger changes are straightforward and low-risk on their own.

packages/scrawn/src/core/scrawn.ts — the parseURLToTarget port logic needs a second look before merging.

Important Files Changed

Filename Overview
packages/scrawn/src/core/scrawn.ts parseURLToTarget now infers 443 for https: and 80 for http:; the http: → port 80 default is incorrect for gRPC plaintext and will break callers who omit the port.
packages/scrawn/src/utils/logger.ts Switches from ScrawnConfig static flag to SCRAWN_DEBUG env var, adds SCRAWN_LOG_FILE support and graceful fallback; default-path write failures are swallowed silently.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["new Scrawn({ baseURL })"] --> B{"baseURL includes '://'?"}
    B -- No --> C{"baseURL includes ':'?"}
    C -- Yes --> D["use baseURL as-is"]
    C -- No --> E["append :8069 (defaultPort)"]
    B -- Yes --> F["new URL(baseURL)"]
    F --> G{"url.port set?"}
    G -- Yes --> H["use url.hostname:url.port"]
    G -- No --> I{"url.protocol?"}
    I -- "https:" --> J["port = 443"]
    I -- "http:" --> K["port = 80 ⚠️ (gRPC default 8069 expected)"]
    I -- other --> L["port = 8069 (defaultPort)"]
    J --> H
    K --> H
    L --> H
    H --> M["GrpcClient(target)"]
Loading

Reviews (1): Last reviewed commit: "fix: parseURLToTarget uses protocol-appr..." | Re-trigger Greptile

Comment on lines +286 to +291
const protocolPort =
url.protocol === "https:"
? "443"
: url.protocol === "http:"
? "80"
: ScrawnConfig.grpc.defaultPort.toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Using port 80 as the fallback for http: URLs is wrong for gRPC. gRPC plaintext transport does not run on port 80 — the SDK's own default is 8069. Any caller who passes http://my-server (without an explicit port) will now attempt to connect to port 80 and fail silently. Only the https: case has a defensible standard port (443 for TLS gRPC); the http: case should keep falling back to ScrawnConfig.grpc.defaultPort.

Suggested change
const protocolPort =
url.protocol === "https:"
? "443"
: url.protocol === "http:"
? "80"
: ScrawnConfig.grpc.defaultPort.toString();
const protocolPort =
url.protocol === "https:"
? "443"
: ScrawnConfig.grpc.defaultPort.toString();

Comment on lines +25 to +32
} catch (err) {
if (process.env.SCRAWN_LOG_FILE) {
console.error(
`[Scrawn] Cannot write to SCRAWN_LOG_FILE="${logFileName}" — file logging disabled`
);
}
baseLogger = pino({ level: "silent" });
}

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 When writing to the default scrawn.log fails (read-only filesystem, Lambda/edge environments, etc.), the error is swallowed silently — no message is printed, and all SDK logging is disabled. The warning path is guarded by if (process.env.SCRAWN_LOG_FILE), so it only fires for explicitly configured paths. Users debugging a silent SDK in production have no indication that logging was disabled.

Suggested change
} catch (err) {
if (process.env.SCRAWN_LOG_FILE) {
console.error(
`[Scrawn] Cannot write to SCRAWN_LOG_FILE="${logFileName}" — file logging disabled`
);
}
baseLogger = pino({ level: "silent" });
}
} catch (err) {
console.error(
`[Scrawn] Cannot write to log file "${logFileName}" — file logging disabled`
);
baseLogger = pino({ level: "silent" });
}

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.

1 participant