Files
appointment_tool/logs/LogSender.py
T

51 lines
1.7 KiB
Python

import datetime
import logging
import sys
import oci
from oci.loggingingestion import LoggingClient
from oci.loggingingestion.models import PutLogsDetails, LogEntryBatch, LogEntry
from logs.AppLogging import init_logger
LOG_ERROR = "ERROR"
LOG_INFO = "INFO"
LOG_APPOINTMENT_ERROR = "APPOINTMENT_ERROR"
LOG_APPOINTMENT_TIMEOUT = "TIMEOUT"
LOG_APPOINTMENT_SUCCESS = "SUCCESS"
class LogSender:
def __init__(self):
self._config = oci.config.from_file("~/.oci/logger_config")
self._identity = oci.identity.IdentityClient(self._config)
self._loggingingestion_client = LoggingClient(self._config)
def send_log(self, msg: str, subject="appointment", type: str = "INFO"):
log_id = "ocid1.log.oc1.eu-frankfurt-1.amaaaaaacvc3jtia5enufv5jxe6binq4ndaty7pt5mk7uidipfd62ynwdhnq"
response = self._loggingingestion_client.put_logs(
log_id=log_id,
put_logs_details=PutLogsDetails(
specversion="1.0",
log_entry_batches=[
LogEntryBatch(
entries=[LogEntry(
data=msg,
id=log_id,
time=datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ"))],
source="Appointment",
type=type,
defaultlogentrytime=datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
subject=subject)])
)
return response
if __name__ == '__main__':
init_logger()
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(stream=sys.stdout))
log_sender = LogSender()
response = log_sender.send_log("test2")
print(response)