Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nhairs/python-json-logger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.3.0
Choose a base ref
...
head repository: nhairs/python-json-logger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 6 commits
  • 9 files changed
  • 5 contributors

Commits on Mar 30, 2025

  1. [core] support DictConfigurator prefixes for rename_fields and static…

    …_fields (#45)
    
    Python logging config supports access to
    [external](https://docs.python.org/3/library/logging.config.html#access-to-external-objects)
    and
    [internal](https://docs.python.org/3/library/logging.config.html#access-to-internal-objects)
    objects via
    [DictConfiguator](https://docs.python.org/3/library/logging.config.html#configuration-functions)
    prefixes.
    
    This works internally by warpping the dict with a
    [ConvertingDict](https://github.com/python/cpython/blob/main/Lib/logging/config.py#L337)
    that requires an explicit call to it's
    [\_\_getitem\_\_](https://github.com/python/cpython/blob/main/Lib/logging/config.py#L340)
    dunder method for the
    [conversion](https://github.com/python/cpython/blob/main/Lib/logging/config.py#L307)
    to take place (using the specific converter for the specified prefix).
    
    This allows, for example, having a *log_config.yaml* file like:
    
    ```yaml
    version: 1
    disable_existing_loggers: False
    formatters:
      default:
        "()": pythonjsonlogger.json.JsonFormatter
        format: "%(asctime)s %(levelname)s %(name)s %(module)s %(funcName)s %(lineno)s %(message)s"
        rename_fields:
          "asctime": "timestamp"
          "levelname": "status"
        static_fields:
          "service": ext://logging_config.PROJECT_NAME
          "env": ext://logging_config.ENVIRONMENT
          "version": ext://logging_config.PROJECT_VERSION
          "app_log": "true"
    handlers:
      default:
        formatter: default
        class: logging.StreamHandler
        stream: ext://sys.stderr
      access:
        formatter: default
        class: logging.StreamHandler
        stream: ext://sys.stdout
    loggers:
      uvicorn.error:
        level: INFO
        handlers:
          - default
        propagate: no
      uvicorn.access:
        level: INFO
        handlers:
          - access
        propagate: no
    ```
    
    where *service*, *env* and *version* values are taken from the external
    resource *logging_config.py*.
    
    The content for *logging_config.py* could be something like (for getting
    some values from project metadata or environment variables):
    
    ```python
    import importlib.metadata
    import os
    
    
    def get_version_metadata():
        # https://stackoverflow.com/a/78082532
        version = importlib.metadata.version(PROJECT_NAME)
        return version
    
    
    PROJECT_NAME = 'test-api'
    PROJECT_VERSION = get_version_metadata()
    ENVIRONMENT = os.environ.get('ENVIRONMENT', 'dev')
    ```
    
    ---------
    
    Co-authored-by: Nicholas Hairs <info@nicholashairs.com>
    rubensa and nhairs authored Mar 30, 2025
    Configuration menu
    Copy the full SHA
    6884b59 View commit details
    Browse the repository at this point in the history

Commits on Apr 27, 2025

  1. v4.0.0.dev0 release

    nhairs committed Apr 27, 2025
    Configuration menu
    Copy the full SHA
    1f0cbd0 View commit details
    Browse the repository at this point in the history

Commits on Jun 26, 2025

  1. [docs] Fix typo in quickstart: exluded (#56)

    Per title
    ftnext authored Jun 26, 2025
    Configuration menu
    Copy the full SHA
    27231ed View commit details
    Browse the repository at this point in the history
  2. [docs] Update documentation (#57)

    Various minor fixes as suggested by jules.google
    
    ---------
    
    Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
    nhairs and google-labs-jules[bot] authored Jun 26, 2025
    Configuration menu
    Copy the full SHA
    03ad4d1 View commit details
    Browse the repository at this point in the history
  3. [docs] Add style guide (#58)

    Per title
    
    ---------
    
    Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
    nhairs and google-labs-jules[bot] authored Jun 26, 2025
    Configuration menu
    Copy the full SHA
    f36b8b5 View commit details
    Browse the repository at this point in the history

Commits on Jul 18, 2025

  1. Configuration menu
    Copy the full SHA
    0843f52 View commit details
    Browse the repository at this point in the history
Loading