-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from UKPLab/logging
Centrialzed Logging
- Loading branch information
Showing
24 changed files
with
209 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
__pycache__/ | ||
*.py[cod] | ||
.venv | ||
.pytest_cache | ||
.es-data | ||
.DS_Store | ||
*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pythonjsonlogger import jsonlogger | ||
from datetime import datetime; | ||
|
||
class ElkJsonFormatter(jsonlogger.JsonFormatter): | ||
def add_fields(self, log_record, record, message_dict): | ||
super(ElkJsonFormatter, self).add_fields(log_record, record, message_dict) | ||
log_record['@timestamp'] = datetime.now().isoformat() | ||
log_record['level'] = record.levelname | ||
log_record['logger'] = record.name | ||
log_record['application'] = 'SQUARE' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .ElkJsonFormatter import ElkJsonFormatter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This package is for formatting logs as JSON. | ||
|
||
To build run `python setup.py sdist`. | ||
|
||
When changing the code, please update the version in `setup.py` and the default version in the bash `distribute_tar_to_services.sh` script. Then run the script to distribute the tar ball to the listed services in the script (update if necessary) to make the new version installable. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
# Distributes tar ball of ElkJsonFormatter to parent directories listed in $services | ||
# Please update version when creating new ElkJsonFormatter | ||
version=${1:-"0.0.2"} | ||
services=(square-backend) | ||
for service in $services; do | ||
cp dist/ElkJsonFormatter-${version}.tar.gz ../$service/ElkJsonFormatter.tar.gz | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-json-logger==2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name="ElkJsonFormatter", | ||
version="0.0.2", | ||
packages=find_packages(include=['ElkJsonFormatter']), | ||
install_requires=["python-json-logger==2.0.1"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cluster.name: "docker-cluster" | ||
network.host: 0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
filebeat.inputs: | ||
- type: container | ||
paths: | ||
- '/var/lib/docker/containers/*/*.log' | ||
|
||
processors: | ||
# - add_docker_metadata: | ||
# host: "unix:///var/run/docker.sock" | ||
|
||
- decode_json_fields: | ||
fields: ["message"] | ||
target: "square" | ||
overwrite_keys: true | ||
|
||
output.logstash: | ||
hosts: ["logstash:5044"] | ||
|
||
logging.json: true | ||
logging.metrics.enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
server.name: kibana | ||
server.host: 0.0.0.0 | ||
elasticsearch.hosts: [ "http://elasticsearch:9200" ] | ||
monitoring.ui.container.elasticsearch.enabled: true | ||
|
||
## X-Pack security credentials | ||
# | ||
elasticsearch.username: elastic | ||
elasticsearch.password: changeme |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
version: "3.2" | ||
|
||
services: | ||
elasticsearch: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:7.13.2 | ||
volumes: | ||
- type: bind | ||
source: ./config/elasticsearch.yml | ||
target: /usr/share/elasticsearch/config/elasticsearch.yml | ||
read_only: true | ||
- type: volume | ||
source: logging-es-data | ||
target: /usr/share/elasticsearch/data | ||
environment: | ||
ES_JAVA_OPTS: "-Xmx256m -Xms256m" | ||
ELASTIC_PASSWORD: changeme | ||
discovery.type: single-node | ||
networks: | ||
- elk | ||
logstash: | ||
image: docker.elastic.co/logstash/logstash:7.13.2 | ||
volumes: | ||
- type: bind | ||
source: ./config/logstash.yml | ||
target: /usr/share/logstash/config/logstash.yml | ||
read_only: true | ||
- type: bind | ||
source: ./logstash/pipeline | ||
target: /usr/share/logstash/pipeline | ||
read_only: true | ||
ports: | ||
- "5044:5044" | ||
environment: | ||
LS_JAVA_OPTS: "-Xmx256m -Xms256m" | ||
networks: | ||
- elk | ||
depends_on: | ||
- elasticsearch | ||
kibana: | ||
image: docker.elastic.co/kibana/kibana:7.13.2 | ||
volumes: | ||
- type: bind | ||
source: ./config/kibana.yml | ||
target: /usr/share/kibana/config/kibana.yml | ||
read_only: true | ||
ports: | ||
- "5601:5601" | ||
networks: | ||
- elk | ||
depends_on: | ||
- elasticsearch | ||
|
||
filebeat: | ||
image: "docker.elastic.co/beats/filebeat:7.13.2" | ||
command: -e --strict.perms=false | ||
user: root | ||
volumes: | ||
- type: bind | ||
source: ./config/filebeat.yml | ||
target: /usr/share/filebeat/filebeat.yml | ||
read_only: true | ||
- type: bind | ||
source: /var/lib/docker | ||
target: /var/lib/docker | ||
read_only: true | ||
- type: bind | ||
source: /var/run/docker.sock | ||
target: /var/run/docker.sock | ||
networks: | ||
- elk | ||
depends_on: | ||
- elasticsearch | ||
|
||
networks: | ||
elk: | ||
driver: bridge | ||
|
||
volumes: | ||
logging-es-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
input { | ||
beats { | ||
port => 5044 | ||
} | ||
} | ||
|
||
filter { | ||
if [square][application] != "SQUARE" { | ||
drop { } | ||
} | ||
} | ||
|
||
output { | ||
elasticsearch { | ||
hosts => "elasticsearch:9200" | ||
user => "elastic" | ||
password => "changeme" | ||
ecs_compatibility => disabled | ||
index => "square-logs" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[loggers] | ||
keys = root | ||
|
||
[logger_root] | ||
level = DEBUG | ||
handlers = root | ||
|
||
[handlers] | ||
keys = root | ||
|
||
[handler_root] | ||
class = StreamHandler | ||
level = DEBUG | ||
formatter = json | ||
|
||
[formatters] | ||
keys = json | ||
|
||
[formatter_json] | ||
class = ElkJsonFormatter.ElkJsonFormatter | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters