Skip to content

Simpler configuration #31

Open
Open
@danizen

Description

@danizen

It is great to support multiple elasticsearch nodes as you do. It would be nice to be able to specify the hostname, scheme, and port in a single string:

Thanks for writing this. I'm not sure why Elastic themselves have not.

from cmreslogging.handlers import CMRESHandler
handler = CMRESHandler(hosts=[
                               'https://elastic-1.internal.example.com', 
                               'https://elastic-2.internal.example.com],
                           auth_type=CMRESHandler.AuthType.NO_AUTH,
                           es_index_name="my_python_index",
                           es_additional_fields={'App': 'MyAppName', 'Environment': 'Dev'})
log = logging.getLogger("PythonTest")
log.setLevel(logging.INFO)
log.addHandler(handler)

Our elastic is also behind a load balancer, so that fault-tolerance doesn't require an array, it would be nice to specify the hosts as a simple string in the case that there is one of them:

from cmreslogging.handlers import CMRESHandler
handler = CMRESHandler(hosts='https://elastic.internal.example.com', 
                           auth_type=CMRESHandler.AuthType.NO_AUTH,
                           es_index_name="my_python_index",
                           es_additional_fields={'App': 'MyAppName', 'Environment': 'Dev'})
log = logging.getLogger("PythonTest")
log.setLevel(logging.INFO)
log.addHandler(handler)

It would be nice to be able to specify the authentication as an object rather than a pair (now moving to dictionary based configuration:

LOGGING = {
    ...
    'handlers': {
        "elastic": {
            'formatter': 'full',
            'level': 'DEBUG',
            'class': 'cmreslogging.handlers.CMRESHandler',
            'hosts': 'https://elastic.internal.example.com',
            'auth': CMRESHandler.auth.BasicAuth('username', 'password'),
            'flush_frequency_in_sec': 1,
            'es_index_name': 'mplusadmin-pylogs',
            'es_additional_fields': {
                'app': 'nlmcatutils',
            },
        },
        ...
   },
}

This combination of simplification reduces the dictionary configuration complexity by 3 full keys:

  • use_ssl = not needed because it is implied by scheme
  • verify_ssl = not needed because it is implied by scheme, still available to turn off
  • auth_type and auth_details combined into auth

Also, the specification of hosts is a little simpler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions