Skip to content

Commit 56a5b4a

Browse files
committed
Add elk
1 parent 8819ddd commit 56a5b4a

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

.env_meeting.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ FLASK_SECRET_KEY =
1616

1717
NGROK_TOKEN =
1818

19-
DEBUG =
19+
DEBUG =
20+
21+
ELK_HOST =
22+
ELK_PORT =
23+
ELK_PREFIX =

data/config.py

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
'password': env.str('DB_PASS'),
4444
}
4545

46+
ELK_CONFIG = {
47+
'host': env.str('ELK_HOST'),
48+
'port': env.str('ELK_PORT'),
49+
'prefix': env.str('ELK_PREFIX')
50+
}
4651

4752
def OAUTH_URL():
4853
with open('etc/oauth-server', 'r') as f:

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ pytest~=7.1.3
1919
dateparser~=1.1.1
2020
pytimeparse~=1.1.8
2121
click~=8.1.3
22-
pyngrok~=5.1.0
22+
pyngrok~=5.1.0
23+
24+
python-logstash-async==2.3.0

utils/logging.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import logging
22

3-
from data.config import DEBUG
3+
from logstash_async.handler import AsynchronousLogstashHandler
4+
from logstash_async.formatter import LogstashFormatter
5+
6+
from data.config import DEBUG, ELK_CONFIG
47

58
formatter = logging.Formatter('%(filename)-15s %(name)-8s LINE:%(lineno)-4d '
69
f'%(levelname)-8s [%(asctime)s] > %(message)s')
@@ -18,5 +21,16 @@ def create_logger(logger='', level=logging.INFO, console=True):
1821
return logger
1922

2023

24+
logstash_handler = AsynchronousLogstashHandler(ELK_CONFIG['host'], int(ELK_CONFIG['port']), database_path=None)
25+
logstash_handler.setFormatter(
26+
LogstashFormatter(
27+
message_type=f"{ELK_CONFIG['prefix']}",
28+
extra_prefix=f"{ELK_CONFIG['prefix']}"
29+
)
30+
)
31+
root = logging.getLogger('')
32+
root.setLevel(logging.INFO)
33+
root.addHandler(logstash_handler)
34+
2135
create_logger('slack_bolt.AsyncApp')
2236
slack_logging = create_logger('meeting')

0 commit comments

Comments
 (0)