hey team, I have my Fleet configured using ElasticCloud and I need to configure the elastic-agent on my Django project where I'm configuring my logging like:
ELASTIC_APM = {
'SERVICE_NAME': 'alan-backend',
'SERVER_URL': 'myapmserver',
'SECRET_TOKEN': 'sercrettoken',
'DEBUG': True,
'ENVIRONMENT': ENVIROMENT,
'ELASTIC_APM_LOG_LEVEL': 'DEBUG',
}
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': f"%(levelname)s %(asctime)s - %(module)s - %(message)s"
},
},
'handlers': {
'elasticapm': {
'level': 'INFO',
'class': 'elasticapm.contrib.django.handlers.LoggingHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '/logs/alan_backend.log',
'formatter': 'verbose',
},
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'alan_backend': {
'handlers': ['console', 'elasticapm', 'file'],
'level': 'DEBUG',
'propagate': False,
},
'elasticapm.errors': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
},
}
And I have my docker compose
... my alanbackend container writing the logs to ./logs/logs/alan_backend.logs...
elastic_agent:
image: docker.elastic.co/beats/elastic-agent:8.4.3
container_name: elastic_agent
volumes:
- ./logs:/logs:ro
environment:
- FLEET_URL=https://myfleetelasticcloudurl.com
- ELASTICSEARCH_USERNAME=elastic
- ELASTICSEARCH_PASSWORD=password
- FLEET_ENROLLMENT_TOKEN=token
- FLEET_ENROLL=1
ports:
- 8220:8220
command: ["elastic-agent", "run"]
# filebeat:
# image: docker.elastic.co/beats/filebeat:8.4.3
# container_name: filebeat
# user: root
# configs:
# - source: fb_config
# target: /usr/share/filebeat/filebeat.yml
# volumes:
# # - ./filebeat.yml:/usr/share/filebeat/filebeat.yml:ro
# - ./logs:/logs:ro
# - filebeat_data:/usr/share/filebeat/data
# - /var/run/docker.sock:/var/run/docker.sock
# # This is needed for filebeat to load container log path as specified in filebeat.yml
# - /var/lib/docker/containers/:/var/lib/docker/containers/:ro
# - /var/log/audit/:/var/log/audit/:ro
# - /var/log/:/var/log/:ro
# command: ["--strict.perms=false"]
# depends_on:
# - alan_backend
I have filebeat commented because I'm not sure if I should use it or not, but here we go.
Right now I'm able to see all my transactions via APM, but the point is that all my logger.info() calls that I'm doing on my Django project are being sent as ERROR ( maybe because of 'ELASTIC_APM_LOG_LEVEL': 'DEBUG', ?! )
my elastic-agent.yml
agent.monitoring:
enabled: true
logs: true
metrics: true
http:
enabled: true
host: localhost
port: 6791
# agent.inputs:
# - type: log
# enabled: true
# paths:
# - /logs/alan_backend.log
not sure about the agent.inputs
and it's not 100% clear for me if I need to use only elastic-agent or if I need filebeat AND elastic-agent
additional info:
I mean, i tried for several hours reading a lot of documentations but still not clear how achieve the result of being able to see all my INFO logs AND getting the ERROR logs being handled errors so I can create monitors and all the stuff.