Feat/logging fixes#69
Conversation
… fallback on write failure
…80 for HTTP) instead of defaulting to 8069
Greptile SummaryThis PR reworks the logger to read
Confidence Score: 3/5The 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
|
| const protocolPort = | ||
| url.protocol === "https:" | ||
| ? "443" | ||
| : url.protocol === "http:" | ||
| ? "80" | ||
| : ScrawnConfig.grpc.defaultPort.toString(); |
There was a problem hiding this comment.
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.
| const protocolPort = | |
| url.protocol === "https:" | |
| ? "443" | |
| : url.protocol === "http:" | |
| ? "80" | |
| : ScrawnConfig.grpc.defaultPort.toString(); | |
| const protocolPort = | |
| url.protocol === "https:" | |
| ? "443" | |
| : ScrawnConfig.grpc.defaultPort.toString(); |
| } 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" }); | ||
| } |
There was a problem hiding this comment.
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.
| } 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" }); | |
| } |
No description provided.