Skip to content

Commit

Permalink
Improved documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Brennan committed Oct 31, 2024
1 parent dae9413 commit 84c22ba
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions sat/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def __new__(cls, *args, **kwargs):


class SATLogger(SingletonLoggerMixin):
"""
Logging wrapper for SAT applications.
The purpose for the mixin is to enable a logging.basicConfig setup to be called a single time,
but to allow all the application files to continue to use the same logging setup syntax.
The singleton mixin will check to see if the setup function has already been called in the runtime,
and if not it calls the setup (initializing the Elastic logging handler and formatters).
"""

def __init__(self, name: str = __name__, level: int = logging.INFO) -> None:
self.logger = logging.getLogger(name)

Expand Down Expand Up @@ -70,10 +79,21 @@ def filter(self, record):
return top_module_name not in ['elastic', 'elastic_transport']

def setup_sat_logging_with_defaults():
print('setting up sat logger with defaults')
"""
Sets up a basic logging config with an Elastic Client Handler using values from environment variables
Depends on the following Environment Variables
ELASTIC_ENABLE_LOGGING: string value for booleans, `'True'` or `'False'`: Decides whether Elastic log handler
should be used, and also controls whether other needed configuration is checked for. Defaults to False
ELASTIC_URL: str: url for the Elastic server including protocol and port, e.g. `'https://elk.example.com:9200`
ELASTIC_USERNAME: str: elastic username
ELASTIC_PASSWORD: str: elastic password
ELASTIC_INDEX: str: Name of the index this app should log to
APP_NAME: str: Name of the app label included in the logs
"""

# Elastic loging feature flag defaults to false, don't want to blow up local development if no environment variables are set
# Elastic loging feature flag defaults to false, don't want to blow up local development or tests if no environment variables are set
enable_elastic_string = os.getenv('ELASTIC_ENABLE_LOGGING', '')
if enable_elastic_string.lower() == 'true':
enable_elastic_logging = True
Expand Down

0 comments on commit 84c22ba

Please sign in to comment.