Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
django-log-formatter-ecs
Advanced tools
The library formats Django logs in ECS format.
https://www.elastic.co/guide/en/ecs/current/index.html
Mapping to the format is incomplete and best effort has been made to create logical field mappings between Django and ECS.
If you need to amend the mapping you can implement a custom formatter (see below).
pip install django-log-formatter-ecs
Using in a Django logging configuration:
from django_log_formatter_ecs import ECSFormatter
LOGGING = {
...
"formatters": {
"ecs_formatter": {
"()": ECSFormatter,
},
},
'handlers': {
'ecs': {
'formatter': 'ecs_formatter',
...
},
},
"loggers": {
"django": {
"handlers": ["ecs"],
...
},
},
}
This package uses kubi_ecs_logger https://github.com/kumina/kubi_ecs_logger for base ECS formatting
This package uses Django IPware https://github.com/un33k/django-ipware for IP address capture.
This package is compatible with django-user_agents https://pypi.org/project/django-user-agents/ which, when used, will enhance logged user agent information.
DLFE_APP_NAME
- used to define the application name that should be logged.
DLFE_LOG_SENSITIVE_USER_DATA
- the formatter checks this setting to see if user information should be logged. If this is not set to true, only the user's id is logged.
DLFE_ZIPKIN_HEADERS
- used for defining custom zipkin headers, the defaults is :code:("X-B3-TraceId" "X-B3-SpanId")
The Django configuration file logged is determined by running:
os.getenv('DJANGO_SETTINGS_MODULE')
ECS_FORMATTERS = {
"root": ECSSystemFormatter,
"django.request": ECSRequestFormatter,
"django.db.backends": ECSSystemFormatter,
}
The default class for other loggers is:
ECSSystemFormatter
If you wish to create your own ECS formatter, you can inherit from ECSSystemFormatter and call _get_event_base to get the base level logging data for use in augmentation:
class ECSSystemFormatter(ECSFormatterBase):
def get_event(self):
logger_event = self._get_event_base()
# Customise logger event
return logger_event
django-log-formatter-ecs
packageClone the repository:
git clone https://github.com/uktrade/django-log-formatter-ecs.git && cd django-log-formatter-ecs
Install the required dependencies:
pip install poetry && poetry install && poetry run pre-commit install
Run poetry run pytest
in the root directory to run all tests.
Or, run poetry run tox
in the root directory to run all tests for multiple Python versions. See the tox
configuration file.
FAQs
Formats Django logs in ECS format.
We found that django-log-formatter-ecs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.