Skip to main content

Log library to establish communication with FTP server and AWS CloudWatch; as well as to publish log message to these platforms.

Project description

Python Application Logging Module

The centralized application logging library.

Logging Data Level

  • FATAL: Log the application/ solution/ API state or behaviours that causes the system to terminate unintentionally; or have to cause the system to halt.
  • ERROR: Log the application/ solution/ API state or behaviours that causes the system response abnormally; or is returning not expected out; but the system is still running.
  • DEBUG: Log the application/ solution/ API behaviours or state change.
  • INFO: Log the AI model performance or output.

Unique ID Generation

Please do use uuid4 for generating the random unique ID.

import uuid 

id = uuid.uuid4()

Otherwise use uuid5 for fixed id generation.

import uuid 

id = uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')

Examples

The Example of Creating the Log Group and Log Stream

This example shows the approach of creating the log group and log stream on the AWS CloudWatch.

from lorisboto3Client import Boto3Client 

aws_region = "<your_region>"
aws_role_key = "<your_role_key>"
aws_role_secret = "<your_aws_role_secret>"

# Establishing connection with AWS Cloud Service
client = Boto3Client(aws_region, aws_role_key, aws_role_secret)

log_group_name = "<your_log_group>"
log_stream_name = "<your_log_stream>"
client.create_log_group_stream(log_group_name, log_stream_name)

The Example of Getting Present Log Group

This example shows the approach of getting the present log groups on the AWS CloudWatch.

from loris_log.boto3Client import Boto3Client

aws_region = "<your_region>"
aws_role_key = "<your_role_key>"
aws_role_secret = "<your_aws_role_secret>"

# Establishing connection with AWS Cloud Service
client = Boto3Client(aws_region, aws_role_key, aws_role_secret)

# Pulling the log group names from the cloud.
log_group = "<your_log_group_name>"
response = client.get_log_groups(log_group)

The Example of Getting Present Log Stream

This example shows the approach of getting the present log streams on the AWS CloudWatch.

from loris_log.boto3Client import Boto3Client 

aws_region = "<your_region>"
aws_role_key = "<your_role_key>"
aws_role_secret = "<your_aws_role_secret>"

# Establishing connection with AWS Cloud Service
client = Boto3Client(aws_region, aws_role_key, aws_role_secret)

# Pulling the log group names from the cloud.
log_stream = "<your_log_stream_name>"
response = client.get_log_groups(log_stream)

The Example of Pushing Log to CloudWatch

This example shows the approach of pushing the log message onto the AWS Cloudwatch for the specific log group, as well as log stream.

from loris_log.boto3Client import Boto3Client
from loris_log.customLog import CustomLog
import uuid

# define the credentials
aws_region = "<your_region>"
aws_role_key = "<your_role_key>"
aws_role_secret = "<your_aws_role_secret>"

# Establishing connection with AWS Cloud Service
client = Boto3Client(aws_region, aws_role_key, aws_role_secret)

# define the log group and log stream
log_group = "<your_log_group_name>"
log_stream = "<your_log_stream_name>"

# example of creating debug message
id = uuid.uuid4()
name = "<your_log_name>"
message = ["[200]", "your", "log", "message"]

log = CustomLog.set_debug_message(id, name, message)

# example of pushing the message to the cloudwatch
client.set_log_message(log_group, log_stream, log)

Example of Establishing Connection With Remote FTP Server

This example shows the approach of establishing communication with the remote FTP server.

from loris_log.ftpClient import FtpClient

ftp_server_hostname = "<your_ftp_server_hostname>"
ftp_server_port = int(your_ftp_port_number)
ftp_server_username = "<your_username>"
ftp_server_password = "<your_password>"

client = FtpClient(ftp_server_hostname,
                    ftp_server_port,
                    ftp_server_username,
                    ftp_server_password)

Example of Pushing Embedded Device Data to Remote Server

This example shows the approach of pushing embedded device data onto the remote FTP server.

from loris_log.ftpClient import FtpClient
from loris_log.customLog import CustomLog
import datetime

# Establish the connection.
ftp_server_hostname = "<your_ftp_server_hostname>"
ftp_server_port = int(your_ftp_port_number)
ftp_server_username = "<your_username>"
ftp_server_password = "<your_password>"

client = FtpClient(ftp_server_hostname,
                    ftp_server_port,
                    ftp_server_username,
                    ftp_server_password)

# Create the csv file
flle_path = "log_testing/data"
filename = "example"
client.create_ftp_log_data(file_path, filename)

# Construct the message string
uu_id = uuid.uuid4()
start_time = datetime.datetime.now()
target_start_time = start_time.strftime("%H:%M:%S")
end_time = datetime.datetime.now()
target_end_time = end_time.strftime("%H:%M:%S")
result = "32"
groundtruth = "3"
log = CustomLog.set_ftp_log_data(uu_id, target_start_time, target_end_time, result, groundtruth)

# Push the message to remote FTP server
client.set_ftp_log_data(file_path, filenanme, file_data_message)

Example of Pushing the Log Message to Remote FTP Server

This example shows the approach of pushing log message onto the remote FTP server.

# Establish the connection.
ftp_server_hostname = "<your_ftp_server_hostname>"
ftp_server_port = int(your_ftp_port_number)
ftp_server_username = "<your_username>"
ftp_server_password = "<your_password>"

client = FtpClient(ftp_server_hostname,
                    ftp_server_port,
                    ftp_server_username,
                    ftp_server_password)
      
log_name = "<your_log_name>"
log_message = ["your", "log", "message"]
logfile_path = "log/testing"
logfile_name = "sample"

# Construct the log message.
info_message = CustomLog.set_info_message(id, target_name, target_info_message)

# Push the message onto the specfied file
ftp_client.set_ftp_log_file(logfile_path, logfile_name)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loris_log-0.1.1b1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

loris_log-0.1.1b1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file loris_log-0.1.1b1.tar.gz.

File metadata

  • Download URL: loris_log-0.1.1b1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for loris_log-0.1.1b1.tar.gz
Algorithm Hash digest
SHA256 c3eab56adfd2af494cdc28b701de6d10c066de80b8178132fdb70e9e01708d4e
MD5 51d80c428d4c6c71698863fe66f08063
BLAKE2b-256 7b0702851b85679e51f62424c0bc805b81b1d309f0b1d0d3acd36870ca447300

See more details on using hashes here.

File details

Details for the file loris_log-0.1.1b1-py3-none-any.whl.

File metadata

  • Download URL: loris_log-0.1.1b1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for loris_log-0.1.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc62e6a357fd5998d3f6006eab8a31978a44b34f65faa033e6bcf6431a66a406
MD5 31dc9c1dc8d66bddf9db3178d722dac9
BLAKE2b-256 03862a3a4b8f9d82203e65e51996caab5c7afbff3c253f79cb636145d784b4a2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page