Alliance Auth Loki Logger
Python logging handler and formatter for loki for django. Supports blocking calls and non blocking ones, using threading.
Build on top of django-loki-reloaded.
Why?
A single location for all logs across auth, Separate to auth! With search and notifications etc. Complete with python trace type data for everything.
Installation
Have a loki instance configured and running
Bare Metal:
pip install allianceauth-loki-logging
or
pip install git+https://github.com/Solar-Helix-Independent-Transport/allianceauth-loki-logging.git
Docker
add this to your requirements file and rebuild your image
allianceauth-loki-logging>=1.0.0
or
allianceauth-loki-logging @ git+https://github.com/Solar-Helix-Independent-Transport/allianceauth-loki-logging.git
Usage
LokiHandler is a custom logging handler that pushes log messages to Loki.
Modify your settings to integrate allianceauth_loki_logging with Django's logging:
in your local.py add this at the end, Be sure to read the comments and update any that need to be updated. Specifically the url for loki.
LOKI_URL = "'http://loki:3100/loki/api/v1/push'
### Override the defaults from base.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'extension_file': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(BASE_DIR, 'log/extensions.log'),
'formatter': 'verbose',
'maxBytes': 1024 * 1024 * 5, # edit this line to change max log file size
'backupCount': 5, # edit this line to change number of log backups
},
'console': {
'level': 'DEBUG' if DEBUG else 'INFO', # edit this line to change logging level to console
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
'notifications': { # creates notifications for users with logging_notifications permission
'level': 'ERROR', # edit this line to change logging level to notifications
'class': 'allianceauth.notifications.handlers.NotificationHandler',
'formatter': 'verbose',
},
},
'loggers': {
'allianceauth': {
'handlers': ['notifications'],
'level': 'ERROR',
},
'extensions': {
'handlers': ['extension_file'],
'level': 'DEBUG' if DEBUG else 'INFO',
}
}
}
### LOKI Specific settings
LOGGING['formatters']['loki'] = {
'class': 'allianceauth_loki_logging.LokiFormatter' # required
}
print(f"Configuring Loki Log job to: {os.path.basename(os.sys.argv[0])}")
LOGGING['handlers']['loki'] = {
'level': 'DEBUG' if DEBUG else 'INFO', # Required # We are auto setting the log level to only record debug when in debug.
'class': 'allianceauth_loki_logging.LokiHandler', # Required
'formatter': 'loki', #Required
'timeout': 1, # Post request timeout, default is 0.5. Optional
# Loki url. Defaults to localhost. Optional.
'url': , LOKI_URL,
# Extra tags / labels to attach to the log. Optional, but usefull to differentiate instances.
'tags': {
"job":os.path.basename(os.sys.argv[0]), # Auto set the job to differentiate between celery, gunicorn, manage.py etc.
# you could add extra tags here if you were running multiple auths and needed to be able to tell them apart in a single loki instance eg:
# "auth": "CoolAuth 1",
},
# Push mode. Can be 'sync' or 'thread'. Sync is blocking, thread is non-blocking. Defaults to sync. Optional.
'mode': 'thread',
}
LOGGING['root'] = { # Set the root logger
'handlers': ['loki', 'console'],
'level': 'DEBUG' if DEBUG else 'INFO', # Auto set the log level to only record debug when in debug
}
WORKER_HIJACK_ROOT_LOGGER = False # Do not overide with celery logging.
Diagnosing issues with logs not being pushed in HIGHLY threaded environments
add the following to your loki config to bypass the rate limits.
limits_config:
max_streams_per_user: 0
max_global_streams_per_user: 0
Metadata
Release files for allianceauth-loki-logging 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| allianceauth-loki-logging-1.0.1.tar.gz | 5.4 kB | Without provenance | Details for allianceauth-loki-logging-1.0.1.tar.gz |
Release files / allianceauth-loki-logging-1.0.1.tar.gz
| Download URL | allianceauth-loki-logging-1.0.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3b91afd0ff53e95a1d705233f2a8d6112d3637a90d9facaacb55d4a94a3da13
|
|
BLAKE2b-256 checksum How to use checksums |
0deffef3d7fa71d7e8d9db5ff1e142b5f7e06964a80fa119bcc39ee1bc3a6949
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for allianceauth-loki-logging 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.