-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adding plaintext and JSON logging formatters #1426
Draft
Alsheh
wants to merge
32
commits into
Supervisor:main
Choose a base branch
from
Alsheh:logging-formatters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
putting formatter creation logic in a class
Adding the ability to add default values for required fields in the logformat
Adding the only supervisor dependency: python-json-logger
Adding log attributes to DummyPConfig object
Adding Some CI Tests + setting logger level by description
Adding the ability to set level by number
Undoing parts of previous commits
Logging formatters local
Making the logger backward compatible
Removing jsonformatter dependency
loggers updates
Fixing an issue where numbers are considered valid JSON by the praser
Hi. I'm quite interested in this PR and willing to contribute if needed. What are the next steps here? Looks like it needs some tests for the new functionality? |
hey @ion-f3 - thanks for expressing interest in this PR and your contribution is welcome! Next steps:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds two configurable logging formatters:
plaintext
andJSON
. The formatter will format the supervisord logs as well as the logs of its child processes.The logging parameters that can be added under any section in the supervisor config file to control how each process renders its logs are as follows:
loglevel
: can be one ofcritical
,error
,warn
,info
,debug
,trace
, orblather
.logformat
: this parameter dictates how to convert some of the fields available in the LogRecord into text. NOTE: using the%
operator will conflict with the environment variables expansion syntax so use the python string format style{
.logformatter
: can be one ofplaintext
orjson
.JSON Log Formatter:
In order to configure the
supervisord
to emit logs in a JSON format, the following configuration can be used:Output:
PLAINTEXT Log Formatter:
Reversing the above log format and putting
levelname
andasctime
in square brackets with theplaintext
formatter:Output (note the
app
uses the default log format which can be configured under theapp
section):Using default values in the log format:
Any field is specified in the log format but not defined in the log record can default to some value in this form:
{<field>:<default-value>}
. You can also make the field default to an environment variable using the Supervisor environment variables expansion syntax{<field>:%(ENV_X)s}
!Example config for a log format that uses the
process_name
field which will default tosupervisord
sinceprocess_name
is undefined in the log record:Output:
Advanced Log Format Example
This example combines the following:
JSON
formatter forsupervisord
.plaintext
formatter to output logs in thekey=value
form for Nginx.process_name
used in both log formats which will default to the defined process name in log format.supervisord
and Nginx includes the python version in the logs from an environment variable ({python_version:%(ENV_PYTHON_VERSION)s}
) which leverages the fact that supervisor expands environment variables in the config file in this form%(ENV_*)
.Output (note the mixed log formats):
Resolves: #553 #1337 #1002