-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/logging fixes #69
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,23 +2,34 @@ import fs from "fs"; | |||||||||||||||||||||||||||||
| import path from "path"; | ||||||||||||||||||||||||||||||
| import chalk from "chalk"; | ||||||||||||||||||||||||||||||
| import pino from "pino"; | ||||||||||||||||||||||||||||||
| import { ScrawnConfig } from "../config.js"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| type LogLevel = "info" | "warn" | "error" | "debug"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // ensure log file directory exists | ||||||||||||||||||||||||||||||
| const logFilePath = path.resolve(process.cwd(), "scrawn.log"); | ||||||||||||||||||||||||||||||
| fs.mkdirSync(path.dirname(logFilePath), { recursive: true }); | ||||||||||||||||||||||||||||||
| const logLevel = process.env.SCRAWN_DEBUG ? "debug" : "info"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // create pino instance writing to file | ||||||||||||||||||||||||||||||
| const baseLogger = pino( | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| name: "scrawn", | ||||||||||||||||||||||||||||||
| level: ScrawnConfig.logging.enableDebug ? "debug" : "info", | ||||||||||||||||||||||||||||||
| timestamp: pino.stdTimeFunctions.isoTime, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| pino.destination(logFilePath) | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| const defaultLogFile = "scrawn.log"; | ||||||||||||||||||||||||||||||
| const logFileName = process.env.SCRAWN_LOG_FILE || defaultLogFile; | ||||||||||||||||||||||||||||||
| const logFilePath = path.resolve(process.cwd(), logFileName); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let baseLogger: pino.Logger; | ||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||
| fs.mkdirSync(path.dirname(logFilePath), { recursive: true }); | ||||||||||||||||||||||||||||||
| baseLogger = pino( | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| name: "scrawn", | ||||||||||||||||||||||||||||||
| level: logLevel, | ||||||||||||||||||||||||||||||
| timestamp: pino.stdTimeFunctions.isoTime, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| pino.destination(logFilePath) | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| } 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" }); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export class ScrawnLogger { | ||||||||||||||||||||||||||||||
| constructor(private context: string = "Scrawn") {} | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http:URLs is wrong for gRPC. gRPC plaintext transport does not run on port 80 — the SDK's own default is8069. Any caller who passeshttp://my-server(without an explicit port) will now attempt to connect to port 80 and fail silently. Only thehttps:case has a defensible standard port (443 for TLS gRPC); thehttp:case should keep falling back toScrawnConfig.grpc.defaultPort.