-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_ingestor.py
More file actions
29 lines (25 loc) · 888 Bytes
/
log_ingestor.py
File metadata and controls
29 lines (25 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logging
import json
from datetime import datetime
class LogIngestor:
def __init__(self, log_paths):
self.log_paths = log_paths
self.loggers = self.setup_loggers()
def setup_loggers(self):
loggers = {}
for path in self.log_paths:
logger = logging.getLogger(path)
logger.setLevel(logging.INFO)
handler = logging.FileHandler(path)
handler.setFormatter(logging.Formatter('%(message)s'))
logger.addHandler(handler)
loggers[path] = logger
return loggers
def ingest_log(self, log_data):
try:
file_path = log_data['metadata']['source']
logger = self.loggers[file_path]
log_string = json.dumps(log_data)
logger.info(log_string)
except Exception as e:
print(f"Error ingesting log: {e}")