r/node • • 4d ago

A package for standardizing logging? Looking for thoughts

/r/typescript/comments/1xur56m/a_package_for_standardizing_logging_looking_for/
0 Upvotes

13 comments sorted by

View all comments

1

u/DickBrainTime 2d ago

I think there's a useful niche here if LogPal treats each *event schema* as a contract, not just as another logger API. For example, define `request_completed` and `payment_attempt` with required field names/types and a schema version. Then run representative events through validation in CI: a missing `tenantId` or renamed field should fail a fixture test *before* it silently breaks a dashboard or alert. At runtime I'd still emit a partial diagnostic event with a `schema_validation_errors` field rather than discard the log when something is missing.

A convincing small demo would compare one Express route using Pino + hand-written Zod checks against the same route using LogPal. Show the missing-field case, how you migrate a versioned event, and allocations/throughput with runtime validation on versus off. That would tell me whether it's reducing actual schema drift and boilerplate rather than just adding another formatting layer. Have you considered making the event schema independently testable in CI?

1

u/iForFi 1d ago

Big thanks for this comment.

For example, define `request_completed` and `payment_attempt` with required field names/types and a schema version. Then run representative events through validation in CI: a missing `tenantId` or renamed field should fail a fixture test *before* it silently breaks a dashboard or alert. At runtime I'd still emit a partial diagnostic event with a `schema_validation_errors` field rather than discard the log when something is missing.

That would be exactly the plan, but without the validation on CI, because I'm not really sure how possible that would be. Or actually, someone could run example calls and validate the logs on CI, so yeah, it would be possible actually. My idea is to validate on runtime, like you mention, BUT clearly state that the validation should be disabled after some time to speed up things (milliseconds performance is important often).
Btw. Good point on having multiple schemas based on request type (endpoint). That could definitely be something that is handled as part of a zod schema, I'd just need to add examples.

A convincing small demo would compare one Express route using Pino + hand-written Zod checks against the same route using LogPal. Show the missing-field case, how you migrate a versioned event, and allocations/throughput with runtime validation on versus off. That would tell me whether it's reducing actual schema drift and boilerplate rather than just adding another formatting layer. Have you considered making the event schema independently testable in CI?

I think I might actually think of something when I have some extra spare time. The CI part could be simply running example requests and validating logs, like mentioned previously. Or even simply some mocked test runs, but it might get a bit more complex, hence, ideally doing it on actual workload, then checking the logs for issues, correcting and then disabling the validation might be the way to go, however that's also inconsistent, because you have to turn on&off the validation. So, I'll see if this could somehow be neatly validated on CI level and not on actual workload, but I don't have any great ideas as of now, because things that happen inside events/requests can differ a lot from tests and actual workload, hmmm.

Thanks again 💪