Allow sending logs to stdout by using STDOUT_LOG env var #334
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
We are currently using PgCat in production 💃 (at least for some hours already), thanks for the good work!.
There are two things that have came up during the deployment:
Logs are all written to stderr: We expect error logging to go to stderr and warns/info/etc to stdout. This is because we monitor the output of every piece of software we run and have set alarms to check whether there is an increase in the error logging. Current logging implementation does not allow a fine grained control over this.
Stats filled out the buffer: There is a buffer for sending stats in the code, it is currently set to 100_000. When we started using this, during peaks of traffic, this buffer filled up and led the system into an inconsistent state and a flood of
[2023-02-23T12:09:59.609264Z WARN pgcat::stats] Got event ServerActive { client_id: 1612304972, server_id: 1350173897 } for unregistered server
Started. Our current implementation reaches 100k clients connected to 4 different instances of pgcat, so at high traffic, that buffer can fill up.We propose a solution here where the log can be configured to log to stdout (maintaining backward compatibility), and also where the buffer is increased (by 5).
Logging mechanism
The idea was to use a special kind of logger that allows sending logs to different targets depending on the log level.
By default, if nothing is set, it acts as a regular env_log logger, it sends everything to standard error.
If the Env variable
STDOUT_LOG
is defined, it will be used for configuring the standard out logger.The behavior is:
STDOUT_LOG
env var), it will be send to standard output.of the RUST_LOG env var.
So to summarize, if no
STDOUT_LOG
env var is present, the logger is the default logger. IfSTDOUT_LOG
is set, everything but errors, that matches the log level set in theSTDOUT_LOG
env var is sent to stdout. You can have also some esoteric configuration where you setRUST_LOG=debug
andSTDOUT_LOG=info
, in here, erros will go to stderr, warns and infos to stdout and debugs to stderr.In a previous contribution I was said that 'We are not supporting env vars for configuration yet' but given that this is a special case, because is the log system I implemented it this way. If you think the name of the ENV var is not the right one, or have another proposal for the implementation just let me know. Still, independently of the implementation, I think logging everything to stderr is not flexive enough, actually that's why stderr/stdout exists.
If we agree on a merge, I'll write documentation on the README for whaver was agreed upon.