Adding plaintext and JSON logging formatters#1426
Draft
Alsheh wants to merge 32 commits intoSupervisor:mainfrom
Draft
Adding plaintext and JSON logging formatters#1426Alsheh wants to merge 32 commits intoSupervisor:mainfrom
Alsheh wants to merge 32 commits intoSupervisor:mainfrom
Conversation
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? |
Author
|
hey @ion-f3 - thanks for expressing interest in this PR and your contribution is welcome! Next steps:
|
This file contains hidden or 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
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:
plaintextandJSON. 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 ofplaintextorjson.JSON Log Formatter:
In order to configure the
supervisordto emit logs in a JSON format, the following configuration can be used:Output:
PLAINTEXT Log Formatter:
Reversing the above log format and putting
levelnameandasctimein square brackets with theplaintextformatter:Output (note the
appuses the default log format which can be configured under theappsection):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_namefield which will default tosupervisordsinceprocess_nameis undefined in the log record:Output:
Advanced Log Format Example
This example combines the following:
JSONformatter forsupervisord.plaintextformatter to output logs in thekey=valueform for Nginx.process_nameused in both log formats which will default to the defined process name in log format.supervisordand 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