can send logs to oracle cloud
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import oci
|
||||
from oci.loggingingestion import LoggingClient
|
||||
from oci.loggingingestion.models import PutLogsDetails, LogEntryBatch, LogEntry
|
||||
|
||||
from utils.AppLogging import init_logger
|
||||
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user