loris-log


Nameloris-log JSON
Version 0.2.4.post1 PyPI version JSON
download
home_page
SummaryLog library to establish communication with FTP server and AWS CloudWatch; as well as to publish log message to these platforms.
upload_time2023-10-30 07:06:53
maintainer
docs_urlNone
authorKah Seng, Sze Ling, Stanley
requires_python>=3.10
license
keywords log ftp cloudwatch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div style="text-align:center"><img src="https://raw.githubusercontent.com/manjatech/logos/main/loris.jpg" /></div>
<p></p>
<p></p>
<p>
<span><img src="https://img.shields.io/badge/pypi-3775A9?style=for-the-badge&logo=pypi&logoColor=white"/></span>
<span><img src="https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue"/></span>
<span><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white"/></span>
<span><img src="https://img.shields.io/badge/License-MIT-yellow.svg"/></span>
<span><img src="https://raw.githubusercontent.com/manjatech/logos/main/loris_log_coverage/coverage.svg"/></span>
</p>

# PYTZ Library Country Region

The complete list of [country region](https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568) at PYTZ library could refers to pytz library documentation.

# 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.

```python 
import uuid 
from loris_log.boto3Client import Boto3Client

# generating the random uu_id for each calling session.
id = uuid.uuid4()
```

Otherwise use uuid5 for fixed id generation.

```python
import uuid 

# generating the fixed uu_id for each calling session.
id = uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
```

# Log Message onto CloudWatch Examples

## Construct the Error Log Message

This shows the example of constructing the error log message for CloudWatch.

**`def set_error_message(uu_id, name, message)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of an application/ remote host IP address/ service.
- **`message (list)`**: The error message.

```python
from loris_log.customLog import CustomLog
import uuid

# get the random uuid generated
id = uuid.uuid4()
# define the error log message as the string list.
error_message = ["[400]", "Service not found."]
# define the name (string), oftenly is the IP address of remote host, or the application name
name = "192.168.0.0"

# then, construct the corresponding error log message by initialize set_error_message
# function, and passing in the id (uuid::UUID), name (string), and error_message (list).
error_log = CustomLog.set_error_message(id, name, error_message)
```

## Construct the Debug Log Message

This shows the example of constructing the debug log message for CloudWatch. 

**`def set_debug_message(uu_id, name, message)`:**


Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of the application/ remote host IP address/ service.
- **`message (list)`**: The debug message.


```python
from loris_log.customLog import CustomLog
import uuid 

# get the random uuid
id = uuid.uuid4()
# define the debug message as the string list
debug_message = ["[200]", "Service ok"]
# define the name (string), oftenly is the IP address of remote host, or the application name
name = "192.168.0.0"

# then, construct the corresponding debug log message by calling set_debug_message function,
# and passing in the id (uuid::UUID), name (string), and debug_message (string).
debug_log = CustomLog.set_debug_message(id, name, debug_message)
```

## Construct the Fatal Log Message

This shows the example of constructing the fatal log message for CloudWatch.

**`def set_fatal_message(uu_id, name, message)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of the application/ remote host IP address/ service.
- **`message (list)`**: The fatal message.

```python

from loris_log.customLog import CustomLog 
import uuid 

# get the random uuid
id = uuid.uuid4()
# define the fatal message as the string list 
fatal_message = ["[500", "Service terminated unexpectedly"]
# define the name (string), oftenly is the IP address of remote host, or the application name.
name = "192.168.0.0"

# then, construct the corresponding fatal log message by calling the set_fatal_message
# function and passing it id (uuid::UUID), name (string), and message (list).
fatal_log = CustomLog.set_fatal_message(id, name, fatal_message)
```

## Construct the Info Log Message

This shows the example of constructing the info log message for CloudWatch.

**`def set_info_message(uu_id, name, message)`**

Arguments:

- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of the application/ remote IP address/ service.
- **`message (list)`**: The info message.

```python
from loris_log.customLog import CustomLog 
import uuid 

# get the random uuid generated.
id = uuid.uuid4()
# define the fatal message as the string list.
info_message = ["[200]", "the accuracy is 0.99"]
# define the name (string), oftenly is the IP address of remote host, or the application name.
name = "192.168.0.0"

# then, construct the corresponding info log message via calling set_info_message function.
# by passing in the id (uuid::UUID), name (string), and example_fatal_message (string).
info_log = CustomLog.set_info_message(id, name, fatal_message)

```


## Pushing Log Message onto the CloudWatch 

This shows the example of establishing the connection to the AWS CloudWatch service via the following method:

**`def Boto3Client(region_name, aws_key, aws_secret)`**

Arguments:
- **`region_name (string)`**: The AWS service region name. Refers here [region_name](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html).
- **`aws_key (string)`**: The AWS service role access key.
- **`aws_secret (string)`**: The AWS service role secret key.

Then, pushing the constructed message onto the CloudWatch via the `set_log_message` function, after defining its log group and log stream:

**`def set_log_message(log_group_name, log_stream_name, log_message, country_region)`**

Arguments:
- **`log_group_name (string)`**: The name of the log group.
- **`log_stream_name (string)`**: The name of the log stream.
- **`log_message (list)`**: A list of application/ service/ api message.
- **`country_region (string)`**: The country region, follows pytz library. Example `"Asia/Tokyo"`

Below shows the complete example of pushing an log message onto the AWS CloudWatch.


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

# constuct the log message uses the above elaborated approach. The example
# here creates a sample fatal log message.
# ========================================================================
# get the random uuid
id = uuid.uuid4()
# define the fatal message as the string list 
fatal_message = ["[500]", "Service terminated unexpectedly"]
# define the log name (string), oftenly is the IP address of remote host, or the application name.
name = "192.168.0.0"

# then, construct the corresponding fatal log message
fatal_log = CustomLog.set_fatal_message(id, name, fatal_message)

# Subsequently, push the created fatal log message onto the Cloudwatch
# ###############################################################################
# initialize the boto3 client by first define the log group(string), log stream (string), region (string),
# as well as the key (string) and secret (string). All in form of string.
log_group = ""
log_stream = ""
aws_region = ""
aws_key = ""
aws_secret = ""
country_region = ""
# establish the boto3 connection by initialize Boto3Client instance, then
# passing the aws_region (string), aws_key (string) and aws_secret (string).
client = Boto3Client(aws_region, aws_key, aws_secret)
# then push the log message via following set_log_message method by passing them
# log_group name (string), log_stream name (string, the log_messsage (list),
# and the country region
client.set_log_message(log_group, log_stream, fatal_log, country_region)
```

# Log Message onto Remote Server Via FTP Examples

## Construct the Debug Log Message

This shows the example of constructing the debug log message onto the remote FTP server using `set_debug_message` function.

**`def set_debug_message(uu_id, name, message)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of an application/ remote host IP address/ service.
- **`message (list)`**: The debug message.

```python
from loris_log.customLog import CustomLog 

# randomly generated an id using uuid library
id = uuid.uuid4()
# then define the debug log message that is a list
debug_log = ["[200]", "OK"]
# and define the log name that is a string, which usually is the application name
# or the remote host IP address.
name = "192.168.1.1" 

# afterwards, build the complete debug log message string using set_debug_message
# function by passing the id (id::UUID), name (string), and debug_log (list).
debug_message = CustomLog.set_debug_message(id, name, debug_log)
```

## Construct the Info Log Message

This shows the example of constructing the info log message onto the remmote FTP server via the `set_info_message` function.

**`def set_info_message(uu_id, name, message)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of an application/ remote host IP address/ service.
- **`message (list)`**: The info message.

```python
from loris_log.customLog import CustomLog
import uuid 

# get the random uuid generated
id = uuid.uuid4()
# define the info log message as the string list
info_message = ["[200]", "result is 0.9"]
# define the name (string), oftenly is an IP address of remote host, or the application name
name = "192.168.0.0"

# then, construct the corresponding info log message by initialize the set_info_message
# function, and passing in the id (uuid::UUID), name (string), and error_message(list)
info_log = CustomLog.set_info_message(id, name, info_message)
```

## Construct the Error Log Message

This shows the example of constructing the error log message onto the FTP remote server via the `set_error_message` function.

`def set_error_message(uu_id, name, message)`

Arguments:

- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of an application/ remote host IP address/ service.
- **`message (list)`**: The error message.

```python
from loris_log.customLog import CustomLog
import uuid

# get the random uuid generated
id = uuid.uuid4()
# define the error log message as the string list.
error_message = ["[400]", "Service not found."]
# define the name (string), oftenly is the IP address of remote host, or the application name
name = "192.168.0.0"

# then, construct the corresponding error log message by initialize set_error_message
# function, and passing in the id (uuid::UUID), name (string), and error_message (list).
error_log = CustomLog.set_error_message(id, name, error_message)
```

## Construct the Fatal Log Message

This shows the example of constructing the fatal log message for CloudWatch via the `set_fatal_message(uu_id, name, message)` function.

**`def set_fatal_message(uu_id, name, message)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of application/ remote host IP address/ service.
- **`message (list)`**: The fatal message.

```python

from loris_log.customLog import CustomLog 
import uuid 

# get the random uuid
id = uuid.uuid4()
# define the fatal message as the string list 
fatal_message = ["[500", "Service terminated unexpectedly"]
# define the name (string), oftenly is the IP address of remote host, or the application name.
name = "192.168.0.0"

# then, construct the corresponding fatal log message by calling the set_fatal_message
# function and passing it id (uuid::UUID), name (string), and message (list).
fatal_log = CustomLog.set_fatal_message(id, name, fatal_message)
```

## Construct the Log for the Sensor Data

This shows the example of constructing the log message from some embedded device data via the `set_ftp_log_data` function.

**`def set_ftp_log_data(uu_id, starttime, endttime, result, groundtruth)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`starttime (string)`**: The start time of an operation. Conversion from `datetime.datetime.now()`.
- **`endtime (string)`**: The end time of an operation. Conversion from `datetime.datetime.now()`.
- **`result (string)`**: The result of the embedded device/ system/ model etc. Conversion from `double\ float\ long`.
- **`groundtruth (string)`**: The result of embedded device/ system/ model etc. Conversion from `double\ float\ long`.

```python
import datetime 
import uuid
from loris_log.customLog import CustomLog

# generate the uuid
id = uuid.uuid4()
# define the start time
starttime = datetime.datetime.now().strftime("%H:%M:%S")
# define the end time
endtime = datetime.datetime.now().strftime("%H:%M:%S")
# define the result
result = str(32)
# define the groundtruth
groundtruth = str(3)

# construct the log data message
data_log = CustomLog.set_ftp_log_data(id, starttime, endtime, result, groundtruth)
```

# Pushing Info Log Message onto Remote FTP Server

This example shows the approach to push the log message onto the remote FTP server. It first involves construction of the relevant log message. This example, for instance, create the info log message via the `set_info_message` function. 

**`def set_info_message(uu_id, name, message)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`name (string)`**: The name of an application/ remote host IP address/ service.
- **`message (list)`**: The info message.

```python
from loris_log.customLog import CustomLog
import uuid 

# get the random uuid generated
id = uuid.uuid4()
# define the info log message as the string list
info_message = ["[200]", "result is 0.9"]
# define the name (string), oftenly is an IP address of remote host, or the application name
name = "192.168.0.0"

# then, construct the corresponding info log message by initialize the set_info_message
# function, and passing in the id (uuid::UUID), name (string), and error_message(list)
info_log = CustomLog.set_info_message(id, name, info_message)

```

Then, attempt to establish the communication with the target remote FTP server by providing the FTP server `hostname (string)`, `port number (string)`, `username (string)`, as well as the `password (string)` via the `FTPClient` instance

**`def FTPClient(hostname, port_num, username, password)`**

Arguments:
- **`hostname (string)`**: FTP server's hostname.
- **`port_num (integer)`**: FTP server's port number.
- **`username (string)`**: FTP server's username.
- **`password (string)`**: FTP server's password.

as elaborated in the code snippet below.

```python
from loris_log.ftpClient import FtpClient

hostname = ""
port_num = 22
username = ""
password = ""

# Establish the connection to the remote FTP server
client = FtpClient(hostname, port_num, username, password)
```

After the connection was successfully established. It is time to publish the corresponding log message onto the remote FTP server, based on the define file path, and filename via the `set_ftp_log_file` method.

**`def set_ftp_log_file(directory_name, file_name, message, region_country)`**

Arguments:
- **`directory_path (string)`**: The path to the log file.
- **`file_name (string)`**: The log file name (without extension).
- **`message (string)`**: The log message
- **`region_country (string)`**: The log message local timezone; follows pytz timezone.



```python
# define the path for the log file, must follow the defined format
file_path = "log/testing/data"
# then define the log file name and its file extensions
filename = "sample"
# then define the local timezone
country_region = ""

# Push the log file onto the remote FTP server. New log will
client.set_ftp_log_file(file_path, filename, info_log, country_region)
```

If the log file (.log) was previously not created, please remember 
create the relevant folders and file using `create_ftp_log_file`

**`def create_ftp_log_file(file_path, filename, root)`**:

- **`file_path`**: the path to the log file.
- **`filename`**: the name of log file without extension.
- **`root`**: decision whether to create the log file from root directory

```python
file_path = "log_testing/data"
filename = "sample"
root = True

client.create_ftp_log_file(file_path, filename, root)
```

This shows the complete code example

```python
from loris_log.customLog import CustomLog
from loris_log.ftpClient import FtpClient
import uuid

# get the random uuid generated
id = uuid.uuid4()
# define the info log message as the string list
info_message = ["[200]", "result is 0.9"]
# define the name (string), oftenly is an IP address of remote host, or the application name
name = "192.168.0.0"
# then, construct the corresponding info log message by initialize the set_info_message
# function, and passing in the id (uuid::UUID), name (string), and error_message(list)
info_log = CustomLog.set_info_message(id, name, info_message)

# define the FTP server hostname
hostname = ""
# define the FTP server port number
port_num = 22
# define the FTP server username 
username = ""
# define the FTP server password
password = ""
# Establish the connection to the remote FTP server
client = FtpClient(hostname, port_num, username, password)


# define the path for the log file, must follow the defined format
file_path = "log/testing/data"
# then define the log file name and its file extensions
filename = "sample"
# also, define the local timexone
country_region = ""
# then decide if wanted to create the file from root
# directory, true if wanted to, or otherwise.
root = True

# If previously did not create the log message, create the relevant
# log file first
# @note: ignore this step write to existing log file
client.create_ftp_log_file(file_path, filename, root)

# Push the log file onto the remote FTP server. New log will
client.set_ftp_log_file(file_path, filename, info_log, country_region)
```

Please uses `set_error_message`, `set_info_message`, `set_fatal_message`, or `set_debug_message` method to log the `error`, `info`, `fatal` or `debug` message.

# Example of Pushing Sensor Data to Remote FTP Server

This example shows the example of pushing sensor data as log message onto the remote FTP server.

First, construct the log message using the sensor data via the `set_ftp_log_data` method.

**`def set_ftp_log_data(uu_id, starttime, endtime, result, groundtruth)`**

Arguments:
- **`uu_id (uuid::UUID)`**: The generated uuid.
- **`starttime (string)`**: The start time of an operation. Conversion from datetime.datetime.now().
- **`endtime (string)`**: The end time of an operation. Conversion from datetime.datetime.now().
- **`result (string)`**: The result of the sensors, embedded device, system, model etc. Conversion from double/ float/ long.
- **`groundtruth (string)`**: The result of the sensors, embedded device, system, model etc. Conversion from double/ float/ long.

```python
import datetime 
import uuid
from loris_log.customLog import CustomLog

# generate the uuid
id = uuid.uuid4()
# define the start time
starttime = datetime.datetime.now().strftime("%H:%M:%S")
# define the end time
endtime = datetime.datetime.now().strftime("%H:%M:%S")
# define the result
result = str(32)
# define the groundtruth
groundtruth = str(3)

# construct the log data message
data_log = CustomLog.set_ftp_log_data(id, starttime, endtime, result, groundtruth)
```

Once the log message was crafted, it is time to attempt to establish communication with the remote FTP server using the `FTPClient` method.

**`def FTPClient(hostname, port_num, username, password)`**

Arguments:
- **`hostname (string)`**: FTP server's hostname.
- **`port_num (integer)`**: FTP server's port number.
- **`username (string)`**: FTP server's username.
- **`password (string)`**: FTP server's password.

as elaborated in the code snippet below.

```python
from loris_log.ftpClient import FtpClient

hostname = ""
port_num = 22
username = ""
password = ""

# Establish the connection to the remote FTP server
client = FtpClient(hostname, port_num, username, password)
```

Then, defining the path and filename of the corresponding log file, and have the data pushing onto an log file of a FTP server using the `set_ftp_log_data` method.

**`def set_ftp_log_data(directory_path, file_name, log_data)`**

Arguments:
- **`directory_path (string)`**: The path to the log file.
- **`file_name (string)`**: The name of the log file without extension.
- **`log_data (byte)`**: The data to be logged.

```python
# define the path to the log file
directory_path = "/log_testing/data"
# define the log file with its extension
file_name = "log"
# push the log data onto the remote FTP server.
client.set_ftp_log_data(directory_path, file_name, data_log)
```

If the log file (csv file) was not previously created. Please create one
using the method `create_ftp_log_data`.

**`def create_ftp_log_data(file_path, filename, root)`**:

- **`file_path`**: The directory of the log file.
- **`filename`**: The name of log file without extension (without extension).
- **`root`**: The decision whether to start creating the log file from the root directory.

The complete example is as demonstrated below.

```python
import datetime 
import uuid
from loris_log.customLog import CustomLog
from loris_log.ftpClient import FtpClient

# generate the uuid
id = uuid.uuid4()
# define the start time
starttime = datetime.datetime.now().strftime("%H:%M:%S")
# define the end time
endtime = datetime.datetime.now().strftime("%H:%M:%S")
# define the result
result = str(32)
# define the groundtruth
groundtruth = str(3)
# construct the log data message
data_log = CustomLog.set_ftp_log_data(id, starttime, endtime, result, groundtruth)

# define FTP server hostname
hostname = ""
# define FTP server port number
port_num = 22
# define FTP server username
username = ""
# define FTP server password
password = ""
# Establish the connection to the remote FTP server
client = FtpClient(hostname, port_num, username, password)

# define the path to the log file
directory_path = "/log_testing/data"
# define the log file with its extension
file_name = "log"
# define whether to start log creation from root directory
root = True

# @optional, create the log file if it was never created. Ignore this line, if
# the file was existed.
client.create_ftp_log_data(directory_path, file_name, root)

# push the log data onto the remote FTP server.
client.set_ftp_log_data(directory_path, file_name, data_log)

```

# Example of Constructing the Info Log Message for A Sensor 

This example shows the approach to construct the info log message for an sensor using its id whose often is a string of text. 
This is achieve via the `set_sensor_info_message` method as elaborated below.

**`def set_sensor_info_message(sensor_id, name, message)`**

- **`sensor_id (string)`**: The sensor's serial number.
- **`name (string)`**: The name of the application/ service or API.
- **`message (list)`**: A collection of the info log message.

The usage of this method is as presented in code snippet below.

```Python
from log_loris.customLog import CustomLog

sensor_info_log = CustomLog.set_sensor_info_message("[camera-01-2300001]", "[my application]", ["[200]", "OK"])
```

# Example of Constructing the Debug Log Message for A Sensor

This example shows the approach to construct the debug log message for an sensor using its id whose often is a string of text.
This is achieve via the `set_sensor_debug_message` method as elaborated below.

**`def set_sensor_debug_message(sensor_id, name, message)`**

- **`sensor_id (string)`**: The sensor's serial number.
- **`name (string)`**: The name of the application/ service or API.
- **`message (list)`**: A collection of the info log message.

The usage of this method is as presented in code snippet below:

```Python
from log_loris.customLog import CustomLog 

sensor_debug_log = CustomLog.set_sensor_debug_message("[camera-01-2300001]", "[my application]", ["[200]", "OK"])
```

# Example of Constructing the Error Log Message for A Sensor 

This example shows the approach to construct the error log message for an sensor using its id whose often is a string of text.
This is achieve via the `set_sensor_error_message` method as elaborated below.

**`def set_sensor_error_message(sensor_id, name, message)`**

- **`sensor_id (string)`**: The sensor's serial number.
- **`name (string)`**: The name of the application/ service or API.
- **`message (list)`**: A collection of the error log message.

The usage of this method is as presented in code snippet below:

```Python
from loris_log.customLog import CustomLog

sensor_error_log = CustomLog.set_sensor_error_message("[camera-01-2300001]", "[my application]", ["[200]", "OK"])
```

# Example of Constructing the Fatal Log Message for A Sensor 

This example shows the approach to construct the fatal log message for an sensor using its id whose often is a string of text.
This is achieve via the `set_sensor_fatal_message` method as elaborated below.

**`def set_sensor_fatal_message`**: The sensor's serial number.

- **`sensor_id (string)`**: The sensor's serial number.
- **`name (string)`**: The name of the applicatioon/ service or API.
- **`message (list)`**: A collection of the error log message.

The usage of this method is as presented in code snippet below:

```Python
from loris_log.customLog import CustomLog

sensor_fatal_log = CustomLog.set_sensor_fatal_message("[camera-01-2300001]", "[my application]", ["[200]", "OK"])
```


# Example of Publishing Sensor Info Message onto CloudWatch

The initial step requires establishing the connection onto the CloudWatch via the `Boto3Client` as elaborated below.

**`Boto3Client(aws_region, aws_key, aws_secret)`**

- **`aws_region (string)`**: The AWS region.
- **`aws_log_group (string)`**: The AWS CloudWatch log group name.
- **`aws_log_stream (string)`**: The AWS CloudWatch log stream name.

This is follow by constructing the relevant log message 
using  `set_Sensor_info_message`.

**`def set_sensor_info_message(sensor_id, name, message)`**

- **`sensor_id`**: The sensor's serial number.
- **`name`**: The name of the application/ service or API.
- **`message (list)`**: A collection of the info log message.

Follows by pushing the log on the AWS CloudWatch.

**`def set_log_message(log_group, log_stream, info_log, country_region)`**

- **`log_group (string)`**: The AWS CloudWatch log group name.
- **`log_stream (string)`**: The AWS CloudWatch log stream name.
- **`info_log (string)`**: The info log message.
- **`country_region (string)`**: The local timezone, follows pytz library. Example `Asia/Tokyo`.

The complete codes snippet is as below:

```python
from loris_log.boto3Client import BotoClient 
from loris_log.customLog immport CustomLog 

# First, establish the connection to the AWS CloudWatch.
aws_region = ""
aws_log_group = ""
aws_log_stream = ""
client = Boto3Client(aws_region, aws_log_group, aws_log_stream)

# Then, construct the relevant log message; in this example
# a info log message for a sensor
info_message = CustomLog.set_sensor_info_message(
    "[camera-01-2300001]", "[my-app]", ["[200]", "OK"]
)

# Lastly, publishing the log message onto the CloudWatch
log_group = ""
log_stream = ""
country_region = ""
client.set_log_message(log_group, log_stream, info_message, country_region)
```

# Example of Publishing the Info Log Message onto FTP server.

This demonstrates the approach of how to publishing a sensor log message onto
a remote FTP server.

This requires user first establishes the connection to a remote
FTP server using the `FtpClient` method

**`def FtpClient(hostname, port_num, username, password)`**:

- **`hostname (string)`**: The FTP server hostname (IP address).
- **`port_nun (int)`**: The FTP server port number.
- **`username (string)`**: The FTP server username.
- **`password (string)`**: The FTP server password.

Then, it is follows by creating the info log message for the 
sensor using the `set_sensor_info_message` method.

**`def set_sensor_info_message(sensor_id, name, message)`

- **`sensor_id (string)`**: The sensor's id.
- **`name (string)`**: The application/ API name.
- **`message (list)`**: The sensor's log message.

Lastly, publishing the log message and write it onto
a log file via `set_ftp_log_file` method.

**`def set_ftp_log_file(file_path, filename, log_message, country_region)`**

- **`file_path (string)`**: The directory path of the log file.
- **`filename (string)`**: The log file's file name.
- **`log_message (list)`**: The sensor kog message.
- **`country_region`**: The local country timezone, follows pytz library. Example `Asia/Tokyo`

If the log file (.log) was never created, create one first using 
the method `create_ftp_log_file`.

**`def create_ftp_log_file(file_path, filename, root)`**:

- **`file_path`**: The path to the log file.
- **`filename`**: The name of log file without extension.
- **`root`**: The decision to whether create log file started from the root directory.

The complete example code is as presented below:

```python
from loris_log.ftpClient import FtpClient
from loris_log.customLog import CustomLog

hostname = ""
port_num = 00
username = ""
password = ""
# establish connction 
client = FtpClient(hostname, port_num, username, password)

# Then construct the info log message for the sensor
info_message = CustomLog.set_sensor_info_message(
    "camera01-E11]]",
    "[my-app]", ["[200]", "OK"]
)

# Lastly push onto the FTP server.
file_path = "log/testing/data"
filename = "sample"
root = True
country_region = ""

# Optional, create the file if log file not existed
# Otherwise, ignore this line
client.create_ftp_log_file(file_path, filename, root)

# push the log message onto the log file.
client.set_ftp_log_file(file_path, filename, info_message, country_region)
```
# Example of creating the log file from root directory

This demonstrates the approach to create log file from the parent directory.

First, establising the connection to the remote FTP server via `FTPClient` method.

**`FTPClient(hostname, port, username, password)`**:

- **`hostname`**: the host name of the FTP server.
- **`port`**: the port number of the FTP server.
- **`username`**: the username of the FTP server.
- **`password`**: the password of the FTP server.

subsequently, create the log file by setting the root parameter to True inside
`create_ftp_log_file` method.

**`create_ftp_log_file(file_path, filename, root)`**:

- **`file_path`**: the log file's file path.
- **`filename`**: the name of the log file.
- **`root`**: let the log file created from the root directory.

The complete code snippet is as below

```python
from loris_log.ftpClient import FtpClient

port = 22
hostname = ""
username = ""
password = ""

# establish the connection with the remote FTP server.
client = FtpClient(hostname, port, username, password)

# then, create the log file from the root directory
file_path = "testing/sample"
filename = "sample"
root = True

client.create_ftp_log_file(
    file_path, filename, root
)
```

# Example of creating the log file but not from root directory

This demonstrates the approach to create the log file, but not from the parent directory.

First, establising the connection to the remote FTP server via `FTPClient` method

**`FTPClient(hostname, port, username, password)`**:

- **`hostname`**: the host name of the FTP server.
- **`port`**: the port number of the FTP server.
- **`username`**: the username of the FTP server.
- **`password`**: the password of the FTP server.

subsequently, create the log file by setting the root parameter to True inside
`create_ftp_log_file` method.

**`create_ftp_log_file(file_path, filename, root)`**:

- **`file_path`**: the log file's file path.
- **`filename`**: the name of the log file.
- **`root`**: let the log file created from the root directory.

The complete code snippet is as below

```python
from loris_log.ftpClient import FtpClient

port = 22
hostname = ""
username = ""
password = ""

# establish the connection with the remote FTP server.
client = FtpClient(hostname, port, username, password)

# then, create the log file from the root directory
file_path = "testing/sample"
filename = "sample"
root = False

client.create_ftp_log_file(
    file_path, filename, root
)
```

# Example of creating the log file for sensor's data from root directory

This demonstrates the approach to create log file from the parent directory.

First, establising the connection to the remote FTP server via `FTPClient` method.

**`FTPClient(hostname, port, username, password)`**:

- **`hostname`**: the host name of the FTP server.
- **`port`**: the port number of the FTP server.
- **`username`**: the username of the FTP server.
- **`password`**: the password of the FTP server.

subsequently, create the log file by setting the root parameter to True inside
`create_ftp_log_data` method.

**`create_ftp_log_data(file_path, filename, root)`**:

- **`file_path`**: the log file's file path.
- **`filename`**: the name of the log file.
- **`root`**: let the log file created from the root directory.

The complete code snippet is as below

```python
from loris_log.ftpClient import FtpClient

port = 22
hostname = ""
username = ""
password = ""

# establish the connection with the remote FTP server.
client = FtpClient(hostname, port, username, password)

# then, create the log file from the root directory
file_path = "testing/sample"
filename = "sample"
root = True

client.create_ftp_log_data(
    file_path, filename, root
)
```
# Example of creating the log file for sensor's data not from root directory

This demonstrates the approach to create the log file, but not from the parent directory.

First, establising the connection to the remote FTP server via `FTPClient` method.

**`FTPClient(hostname, port, username, password)`**:

- **`hostname`**: the host name of the FTP server.
- **`port`**: the port number of the FTP server.
- **`username`**: the username of the FTP server.
- **`password`**: the password of the FTP server.

subsequently, create the log file by setting the root parameter to True inside
`create_ftp_log_data` method.

**`create_ftp_log_data(file_path, filename, root)`**:

- **`file_path`**: the log file's file path.
- **`filename`**: the name of the log file.
- **`root`**: let the log file created from the root directory.

The complete code snippet is as below

```python
from loris_log.ftpClient import FtpClient

port = 22
hostname = ""
username = ""
password = ""

# establish the connection with the remote FTP server.
client = FtpClient(hostname, port, username, password)

# then, create the log file from the root directory
file_path = "testing/sample"
filename = "sample"
root = False

client.create_ftp_log_data(
    file_path, filename, root
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "loris-log",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "log,FTP,CloudWatch",
    "author": "Kah Seng, Sze Ling, Stanley",
    "author_email": "Kah Seng <lim0709@gmail.com>, Sze Ling <sltang@handalindah.com.my>, Stanley <stanly@handalindah.com.my>",
    "download_url": "https://files.pythonhosted.org/packages/45/b2/91a9d418558737e6623957b7e2fd1c25127367317a808458c90447c9cea6/loris_log-0.2.4.post1.tar.gz",
    "platform": null,
    "description": "<div style=\"text-align:center\"><img src=\"https://raw.githubusercontent.com/manjatech/logos/main/loris.jpg\" /></div>\n<p></p>\n<p></p>\n<p>\n<span><img src=\"https://img.shields.io/badge/pypi-3775A9?style=for-the-badge&logo=pypi&logoColor=white\"/></span>\n<span><img src=\"https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue\"/></span>\n<span><img src=\"https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white\"/></span>\n<span><img src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"/></span>\n<span><img src=\"https://raw.githubusercontent.com/manjatech/logos/main/loris_log_coverage/coverage.svg\"/></span>\n</p>\n\n# PYTZ Library Country Region\n\nThe complete list of [country region](https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568) at PYTZ library could refers to pytz library documentation.\n\n# Python Application Logging Module \n\nThe centralized application logging library.\n\n# Logging Data Level\n\n- **`FATAL`**: Log the application/ solution/ API state or behaviours that causes the system to terminate unintentionally; or have to cause the system to halt.\n- **`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.\n- **`DEBUG`**: Log the application/ solution/ API behaviours or state change.\n- **`INFO`**: Log the AI model performance or output.\n\n# Unique ID Generation\n\nPlease do use uuid4 for generating the random unique ID.\n\n```python \nimport uuid \nfrom loris_log.boto3Client import Boto3Client\n\n# generating the random uu_id for each calling session.\nid = uuid.uuid4()\n```\n\nOtherwise use uuid5 for fixed id generation.\n\n```python\nimport uuid \n\n# generating the fixed uu_id for each calling session.\nid = uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')\n```\n\n# Log Message onto CloudWatch Examples\n\n## Construct the Error Log Message\n\nThis shows the example of constructing the error log message for CloudWatch.\n\n**`def set_error_message(uu_id, name, message)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of an application/ remote host IP address/ service.\n- **`message (list)`**: The error message.\n\n```python\nfrom loris_log.customLog import CustomLog\nimport uuid\n\n# get the random uuid generated\nid = uuid.uuid4()\n# define the error log message as the string list.\nerror_message = [\"[400]\", \"Service not found.\"]\n# define the name (string), oftenly is the IP address of remote host, or the application name\nname = \"192.168.0.0\"\n\n# then, construct the corresponding error log message by initialize set_error_message\n# function, and passing in the id (uuid::UUID), name (string), and error_message (list).\nerror_log = CustomLog.set_error_message(id, name, error_message)\n```\n\n## Construct the Debug Log Message\n\nThis shows the example of constructing the debug log message for CloudWatch. \n\n**`def set_debug_message(uu_id, name, message)`:**\n\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of the application/ remote host IP address/ service.\n- **`message (list)`**: The debug message.\n\n\n```python\nfrom loris_log.customLog import CustomLog\nimport uuid \n\n# get the random uuid\nid = uuid.uuid4()\n# define the debug message as the string list\ndebug_message = [\"[200]\", \"Service ok\"]\n# define the name (string), oftenly is the IP address of remote host, or the application name\nname = \"192.168.0.0\"\n\n# then, construct the corresponding debug log message by calling set_debug_message function,\n# and passing in the id (uuid::UUID), name (string), and debug_message (string).\ndebug_log = CustomLog.set_debug_message(id, name, debug_message)\n```\n\n## Construct the Fatal Log Message\n\nThis shows the example of constructing the fatal log message for CloudWatch.\n\n**`def set_fatal_message(uu_id, name, message)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of the application/ remote host IP address/ service.\n- **`message (list)`**: The fatal message.\n\n```python\n\nfrom loris_log.customLog import CustomLog \nimport uuid \n\n# get the random uuid\nid = uuid.uuid4()\n# define the fatal message as the string list \nfatal_message = [\"[500\", \"Service terminated unexpectedly\"]\n# define the name (string), oftenly is the IP address of remote host, or the application name.\nname = \"192.168.0.0\"\n\n# then, construct the corresponding fatal log message by calling the set_fatal_message\n# function and passing it id (uuid::UUID), name (string), and message (list).\nfatal_log = CustomLog.set_fatal_message(id, name, fatal_message)\n```\n\n## Construct the Info Log Message\n\nThis shows the example of constructing the info log message for CloudWatch.\n\n**`def set_info_message(uu_id, name, message)`**\n\nArguments:\n\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of the application/ remote IP address/ service.\n- **`message (list)`**: The info message.\n\n```python\nfrom loris_log.customLog import CustomLog \nimport uuid \n\n# get the random uuid generated.\nid = uuid.uuid4()\n# define the fatal message as the string list.\ninfo_message = [\"[200]\", \"the accuracy is 0.99\"]\n# define the name (string), oftenly is the IP address of remote host, or the application name.\nname = \"192.168.0.0\"\n\n# then, construct the corresponding info log message via calling set_info_message function.\n# by passing in the id (uuid::UUID), name (string), and example_fatal_message (string).\ninfo_log = CustomLog.set_info_message(id, name, fatal_message)\n\n```\n\n\n## Pushing Log Message onto the CloudWatch \n\nThis shows the example of establishing the connection to the AWS CloudWatch service via the following method:\n\n**`def Boto3Client(region_name, aws_key, aws_secret)`**\n\nArguments:\n- **`region_name (string)`**: The AWS service region name. Refers here [region_name](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html).\n- **`aws_key (string)`**: The AWS service role access key.\n- **`aws_secret (string)`**: The AWS service role secret key.\n\nThen, pushing the constructed message onto the CloudWatch via the `set_log_message` function, after defining its log group and log stream:\n\n**`def set_log_message(log_group_name, log_stream_name, log_message, country_region)`**\n\nArguments:\n- **`log_group_name (string)`**: The name of the log group.\n- **`log_stream_name (string)`**: The name of the log stream.\n- **`log_message (list)`**: A list of application/ service/ api message.\n- **`country_region (string)`**: The country region, follows pytz library. Example `\"Asia/Tokyo\"`\n\nBelow shows the complete example of pushing an log message onto the AWS CloudWatch.\n\n\n```python\nimport uuid\nfrom loris_log.customLog import CustomLog\nfrom loris_log.boto3Client import Boto3Client\n\n# constuct the log message uses the above elaborated approach. The example\n# here creates a sample fatal log message.\n# ========================================================================\n# get the random uuid\nid = uuid.uuid4()\n# define the fatal message as the string list \nfatal_message = [\"[500]\", \"Service terminated unexpectedly\"]\n# define the log name (string), oftenly is the IP address of remote host, or the application name.\nname = \"192.168.0.0\"\n\n# then, construct the corresponding fatal log message\nfatal_log = CustomLog.set_fatal_message(id, name, fatal_message)\n\n# Subsequently, push the created fatal log message onto the Cloudwatch\n# ###############################################################################\n# initialize the boto3 client by first define the log group(string), log stream (string), region (string),\n# as well as the key (string) and secret (string). All in form of string.\nlog_group = \"\"\nlog_stream = \"\"\naws_region = \"\"\naws_key = \"\"\naws_secret = \"\"\ncountry_region = \"\"\n# establish the boto3 connection by initialize Boto3Client instance, then\n# passing the aws_region (string), aws_key (string) and aws_secret (string).\nclient = Boto3Client(aws_region, aws_key, aws_secret)\n# then push the log message via following set_log_message method by passing them\n# log_group name (string), log_stream name (string, the log_messsage (list),\n# and the country region\nclient.set_log_message(log_group, log_stream, fatal_log, country_region)\n```\n\n# Log Message onto Remote Server Via FTP Examples\n\n## Construct the Debug Log Message\n\nThis shows the example of constructing the debug log message onto the remote FTP server using `set_debug_message` function.\n\n**`def set_debug_message(uu_id, name, message)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of an application/ remote host IP address/ service.\n- **`message (list)`**: The debug message.\n\n```python\nfrom loris_log.customLog import CustomLog \n\n# randomly generated an id using uuid library\nid = uuid.uuid4()\n# then define the debug log message that is a list\ndebug_log = [\"[200]\", \"OK\"]\n# and define the log name that is a string, which usually is the application name\n# or the remote host IP address.\nname = \"192.168.1.1\" \n\n# afterwards, build the complete debug log message string using set_debug_message\n# function by passing the id (id::UUID), name (string), and debug_log (list).\ndebug_message = CustomLog.set_debug_message(id, name, debug_log)\n```\n\n## Construct the Info Log Message\n\nThis shows the example of constructing the info log message onto the remmote FTP server via the `set_info_message` function.\n\n**`def set_info_message(uu_id, name, message)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of an application/ remote host IP address/ service.\n- **`message (list)`**: The info message.\n\n```python\nfrom loris_log.customLog import CustomLog\nimport uuid \n\n# get the random uuid generated\nid = uuid.uuid4()\n# define the info log message as the string list\ninfo_message = [\"[200]\", \"result is 0.9\"]\n# define the name (string), oftenly is an IP address of remote host, or the application name\nname = \"192.168.0.0\"\n\n# then, construct the corresponding info log message by initialize the set_info_message\n# function, and passing in the id (uuid::UUID), name (string), and error_message(list)\ninfo_log = CustomLog.set_info_message(id, name, info_message)\n```\n\n## Construct the Error Log Message\n\nThis shows the example of constructing the error log message onto the FTP remote server via the `set_error_message` function.\n\n`def set_error_message(uu_id, name, message)`\n\nArguments:\n\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of an application/ remote host IP address/ service.\n- **`message (list)`**: The error message.\n\n```python\nfrom loris_log.customLog import CustomLog\nimport uuid\n\n# get the random uuid generated\nid = uuid.uuid4()\n# define the error log message as the string list.\nerror_message = [\"[400]\", \"Service not found.\"]\n# define the name (string), oftenly is the IP address of remote host, or the application name\nname = \"192.168.0.0\"\n\n# then, construct the corresponding error log message by initialize set_error_message\n# function, and passing in the id (uuid::UUID), name (string), and error_message (list).\nerror_log = CustomLog.set_error_message(id, name, error_message)\n```\n\n## Construct the Fatal Log Message\n\nThis shows the example of constructing the fatal log message for CloudWatch via the `set_fatal_message(uu_id, name, message)` function.\n\n**`def set_fatal_message(uu_id, name, message)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of application/ remote host IP address/ service.\n- **`message (list)`**: The fatal message.\n\n```python\n\nfrom loris_log.customLog import CustomLog \nimport uuid \n\n# get the random uuid\nid = uuid.uuid4()\n# define the fatal message as the string list \nfatal_message = [\"[500\", \"Service terminated unexpectedly\"]\n# define the name (string), oftenly is the IP address of remote host, or the application name.\nname = \"192.168.0.0\"\n\n# then, construct the corresponding fatal log message by calling the set_fatal_message\n# function and passing it id (uuid::UUID), name (string), and message (list).\nfatal_log = CustomLog.set_fatal_message(id, name, fatal_message)\n```\n\n## Construct the Log for the Sensor Data\n\nThis shows the example of constructing the log message from some embedded device data via the `set_ftp_log_data` function.\n\n**`def set_ftp_log_data(uu_id, starttime, endttime, result, groundtruth)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`starttime (string)`**: The start time of an operation. Conversion from `datetime.datetime.now()`.\n- **`endtime (string)`**: The end time of an operation. Conversion from `datetime.datetime.now()`.\n- **`result (string)`**: The result of the embedded device/ system/ model etc. Conversion from `double\\ float\\ long`.\n- **`groundtruth (string)`**: The result of embedded device/ system/ model etc. Conversion from `double\\ float\\ long`.\n\n```python\nimport datetime \nimport uuid\nfrom loris_log.customLog import CustomLog\n\n# generate the uuid\nid = uuid.uuid4()\n# define the start time\nstarttime = datetime.datetime.now().strftime(\"%H:%M:%S\")\n# define the end time\nendtime = datetime.datetime.now().strftime(\"%H:%M:%S\")\n# define the result\nresult = str(32)\n# define the groundtruth\ngroundtruth = str(3)\n\n# construct the log data message\ndata_log = CustomLog.set_ftp_log_data(id, starttime, endtime, result, groundtruth)\n```\n\n# Pushing Info Log Message onto Remote FTP Server\n\nThis example shows the approach to push the log message onto the remote FTP server. It first involves construction of the relevant log message. This example, for instance, create the info log message via the `set_info_message` function. \n\n**`def set_info_message(uu_id, name, message)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`name (string)`**: The name of an application/ remote host IP address/ service.\n- **`message (list)`**: The info message.\n\n```python\nfrom loris_log.customLog import CustomLog\nimport uuid \n\n# get the random uuid generated\nid = uuid.uuid4()\n# define the info log message as the string list\ninfo_message = [\"[200]\", \"result is 0.9\"]\n# define the name (string), oftenly is an IP address of remote host, or the application name\nname = \"192.168.0.0\"\n\n# then, construct the corresponding info log message by initialize the set_info_message\n# function, and passing in the id (uuid::UUID), name (string), and error_message(list)\ninfo_log = CustomLog.set_info_message(id, name, info_message)\n\n```\n\nThen, attempt to establish the communication with the target remote FTP server by providing the FTP server `hostname (string)`, `port number (string)`, `username (string)`, as well as the `password (string)` via the `FTPClient` instance\n\n**`def FTPClient(hostname, port_num, username, password)`**\n\nArguments:\n- **`hostname (string)`**: FTP server's hostname.\n- **`port_num (integer)`**: FTP server's port number.\n- **`username (string)`**: FTP server's username.\n- **`password (string)`**: FTP server's password.\n\nas elaborated in the code snippet below.\n\n```python\nfrom loris_log.ftpClient import FtpClient\n\nhostname = \"\"\nport_num = 22\nusername = \"\"\npassword = \"\"\n\n# Establish the connection to the remote FTP server\nclient = FtpClient(hostname, port_num, username, password)\n```\n\nAfter the connection was successfully established. It is time to publish the corresponding log message onto the remote FTP server, based on the define file path, and filename via the `set_ftp_log_file` method.\n\n**`def set_ftp_log_file(directory_name, file_name, message, region_country)`**\n\nArguments:\n- **`directory_path (string)`**: The path to the log file.\n- **`file_name (string)`**: The log file name (without extension).\n- **`message (string)`**: The log message\n- **`region_country (string)`**: The log message local timezone; follows pytz timezone.\n\n\n\n```python\n# define the path for the log file, must follow the defined format\nfile_path = \"log/testing/data\"\n# then define the log file name and its file extensions\nfilename = \"sample\"\n# then define the local timezone\ncountry_region = \"\"\n\n# Push the log file onto the remote FTP server. New log will\nclient.set_ftp_log_file(file_path, filename, info_log, country_region)\n```\n\nIf the log file (.log) was previously not created, please remember \ncreate the relevant folders and file using `create_ftp_log_file`\n\n**`def create_ftp_log_file(file_path, filename, root)`**:\n\n- **`file_path`**: the path to the log file.\n- **`filename`**: the name of log file without extension.\n- **`root`**: decision whether to create the log file from root directory\n\n```python\nfile_path = \"log_testing/data\"\nfilename = \"sample\"\nroot = True\n\nclient.create_ftp_log_file(file_path, filename, root)\n```\n\nThis shows the complete code example\n\n```python\nfrom loris_log.customLog import CustomLog\nfrom loris_log.ftpClient import FtpClient\nimport uuid\n\n# get the random uuid generated\nid = uuid.uuid4()\n# define the info log message as the string list\ninfo_message = [\"[200]\", \"result is 0.9\"]\n# define the name (string), oftenly is an IP address of remote host, or the application name\nname = \"192.168.0.0\"\n# then, construct the corresponding info log message by initialize the set_info_message\n# function, and passing in the id (uuid::UUID), name (string), and error_message(list)\ninfo_log = CustomLog.set_info_message(id, name, info_message)\n\n# define the FTP server hostname\nhostname = \"\"\n# define the FTP server port number\nport_num = 22\n# define the FTP server username \nusername = \"\"\n# define the FTP server password\npassword = \"\"\n# Establish the connection to the remote FTP server\nclient = FtpClient(hostname, port_num, username, password)\n\n\n# define the path for the log file, must follow the defined format\nfile_path = \"log/testing/data\"\n# then define the log file name and its file extensions\nfilename = \"sample\"\n# also, define the local timexone\ncountry_region = \"\"\n# then decide if wanted to create the file from root\n# directory, true if wanted to, or otherwise.\nroot = True\n\n# If previously did not create the log message, create the relevant\n# log file first\n# @note: ignore this step write to existing log file\nclient.create_ftp_log_file(file_path, filename, root)\n\n# Push the log file onto the remote FTP server. New log will\nclient.set_ftp_log_file(file_path, filename, info_log, country_region)\n```\n\nPlease uses `set_error_message`, `set_info_message`, `set_fatal_message`, or `set_debug_message` method to log the `error`, `info`, `fatal` or `debug` message.\n\n# Example of Pushing Sensor Data to Remote FTP Server\n\nThis example shows the example of pushing sensor data as log message onto the remote FTP server.\n\nFirst, construct the log message using the sensor data via the `set_ftp_log_data` method.\n\n**`def set_ftp_log_data(uu_id, starttime, endtime, result, groundtruth)`**\n\nArguments:\n- **`uu_id (uuid::UUID)`**: The generated uuid.\n- **`starttime (string)`**: The start time of an operation. Conversion from datetime.datetime.now().\n- **`endtime (string)`**: The end time of an operation. Conversion from datetime.datetime.now().\n- **`result (string)`**: The result of the sensors, embedded device, system, model etc. Conversion from double/ float/ long.\n- **`groundtruth (string)`**: The result of the sensors, embedded device, system, model etc. Conversion from double/ float/ long.\n\n```python\nimport datetime \nimport uuid\nfrom loris_log.customLog import CustomLog\n\n# generate the uuid\nid = uuid.uuid4()\n# define the start time\nstarttime = datetime.datetime.now().strftime(\"%H:%M:%S\")\n# define the end time\nendtime = datetime.datetime.now().strftime(\"%H:%M:%S\")\n# define the result\nresult = str(32)\n# define the groundtruth\ngroundtruth = str(3)\n\n# construct the log data message\ndata_log = CustomLog.set_ftp_log_data(id, starttime, endtime, result, groundtruth)\n```\n\nOnce the log message was crafted, it is time to attempt to establish communication with the remote FTP server using the `FTPClient` method.\n\n**`def FTPClient(hostname, port_num, username, password)`**\n\nArguments:\n- **`hostname (string)`**: FTP server's hostname.\n- **`port_num (integer)`**: FTP server's port number.\n- **`username (string)`**: FTP server's username.\n- **`password (string)`**: FTP server's password.\n\nas elaborated in the code snippet below.\n\n```python\nfrom loris_log.ftpClient import FtpClient\n\nhostname = \"\"\nport_num = 22\nusername = \"\"\npassword = \"\"\n\n# Establish the connection to the remote FTP server\nclient = FtpClient(hostname, port_num, username, password)\n```\n\nThen, defining the path and filename of the corresponding log file, and have the data pushing onto an log file of a FTP server using the `set_ftp_log_data` method.\n\n**`def set_ftp_log_data(directory_path, file_name, log_data)`**\n\nArguments:\n- **`directory_path (string)`**: The path to the log file.\n- **`file_name (string)`**: The name of the log file without extension.\n- **`log_data (byte)`**: The data to be logged.\n\n```python\n# define the path to the log file\ndirectory_path = \"/log_testing/data\"\n# define the log file with its extension\nfile_name = \"log\"\n# push the log data onto the remote FTP server.\nclient.set_ftp_log_data(directory_path, file_name, data_log)\n```\n\nIf the log file (csv file) was not previously created. Please create one\nusing the method `create_ftp_log_data`.\n\n**`def create_ftp_log_data(file_path, filename, root)`**:\n\n- **`file_path`**: The directory of the log file.\n- **`filename`**: The name of log file without extension (without extension).\n- **`root`**: The decision whether to start creating the log file from the root directory.\n\nThe complete example is as demonstrated below.\n\n```python\nimport datetime \nimport uuid\nfrom loris_log.customLog import CustomLog\nfrom loris_log.ftpClient import FtpClient\n\n# generate the uuid\nid = uuid.uuid4()\n# define the start time\nstarttime = datetime.datetime.now().strftime(\"%H:%M:%S\")\n# define the end time\nendtime = datetime.datetime.now().strftime(\"%H:%M:%S\")\n# define the result\nresult = str(32)\n# define the groundtruth\ngroundtruth = str(3)\n# construct the log data message\ndata_log = CustomLog.set_ftp_log_data(id, starttime, endtime, result, groundtruth)\n\n# define FTP server hostname\nhostname = \"\"\n# define FTP server port number\nport_num = 22\n# define FTP server username\nusername = \"\"\n# define FTP server password\npassword = \"\"\n# Establish the connection to the remote FTP server\nclient = FtpClient(hostname, port_num, username, password)\n\n# define the path to the log file\ndirectory_path = \"/log_testing/data\"\n# define the log file with its extension\nfile_name = \"log\"\n# define whether to start log creation from root directory\nroot = True\n\n# @optional, create the log file if it was never created. Ignore this line, if\n# the file was existed.\nclient.create_ftp_log_data(directory_path, file_name, root)\n\n# push the log data onto the remote FTP server.\nclient.set_ftp_log_data(directory_path, file_name, data_log)\n\n```\n\n# Example of Constructing the Info Log Message for A Sensor \n\nThis example shows the approach to construct the info log message for an sensor using its id whose often is a string of text. \nThis is achieve via the `set_sensor_info_message` method as elaborated below.\n\n**`def set_sensor_info_message(sensor_id, name, message)`**\n\n- **`sensor_id (string)`**: The sensor's serial number.\n- **`name (string)`**: The name of the application/ service or API.\n- **`message (list)`**: A collection of the info log message.\n\nThe usage of this method is as presented in code snippet below.\n\n```Python\nfrom log_loris.customLog import CustomLog\n\nsensor_info_log = CustomLog.set_sensor_info_message(\"[camera-01-2300001]\", \"[my application]\", [\"[200]\", \"OK\"])\n```\n\n# Example of Constructing the Debug Log Message for A Sensor\n\nThis example shows the approach to construct the debug log message for an sensor using its id whose often is a string of text.\nThis is achieve via the `set_sensor_debug_message` method as elaborated below.\n\n**`def set_sensor_debug_message(sensor_id, name, message)`**\n\n- **`sensor_id (string)`**: The sensor's serial number.\n- **`name (string)`**: The name of the application/ service or API.\n- **`message (list)`**: A collection of the info log message.\n\nThe usage of this method is as presented in code snippet below:\n\n```Python\nfrom log_loris.customLog import CustomLog \n\nsensor_debug_log = CustomLog.set_sensor_debug_message(\"[camera-01-2300001]\", \"[my application]\", [\"[200]\", \"OK\"])\n```\n\n# Example of Constructing the Error Log Message for A Sensor \n\nThis example shows the approach to construct the error log message for an sensor using its id whose often is a string of text.\nThis is achieve via the `set_sensor_error_message` method as elaborated below.\n\n**`def set_sensor_error_message(sensor_id, name, message)`**\n\n- **`sensor_id (string)`**: The sensor's serial number.\n- **`name (string)`**: The name of the application/ service or API.\n- **`message (list)`**: A collection of the error log message.\n\nThe usage of this method is as presented in code snippet below:\n\n```Python\nfrom loris_log.customLog import CustomLog\n\nsensor_error_log = CustomLog.set_sensor_error_message(\"[camera-01-2300001]\", \"[my application]\", [\"[200]\", \"OK\"])\n```\n\n# Example of Constructing the Fatal Log Message for A Sensor \n\nThis example shows the approach to construct the fatal log message for an sensor using its id whose often is a string of text.\nThis is achieve via the `set_sensor_fatal_message` method as elaborated below.\n\n**`def set_sensor_fatal_message`**: The sensor's serial number.\n\n- **`sensor_id (string)`**: The sensor's serial number.\n- **`name (string)`**: The name of the applicatioon/ service or API.\n- **`message (list)`**: A collection of the error log message.\n\nThe usage of this method is as presented in code snippet below:\n\n```Python\nfrom loris_log.customLog import CustomLog\n\nsensor_fatal_log = CustomLog.set_sensor_fatal_message(\"[camera-01-2300001]\", \"[my application]\", [\"[200]\", \"OK\"])\n```\n\n\n# Example of Publishing Sensor Info Message onto CloudWatch\n\nThe initial step requires establishing the connection onto the CloudWatch via the `Boto3Client` as elaborated below.\n\n**`Boto3Client(aws_region, aws_key, aws_secret)`**\n\n- **`aws_region (string)`**: The AWS region.\n- **`aws_log_group (string)`**: The AWS CloudWatch log group name.\n- **`aws_log_stream (string)`**: The AWS CloudWatch log stream name.\n\nThis is follow by constructing the relevant log message \nusing  `set_Sensor_info_message`.\n\n**`def set_sensor_info_message(sensor_id, name, message)`**\n\n- **`sensor_id`**: The sensor's serial number.\n- **`name`**: The name of the application/ service or API.\n- **`message (list)`**: A collection of the info log message.\n\nFollows by pushing the log on the AWS CloudWatch.\n\n**`def set_log_message(log_group, log_stream, info_log, country_region)`**\n\n- **`log_group (string)`**: The AWS CloudWatch log group name.\n- **`log_stream (string)`**: The AWS CloudWatch log stream name.\n- **`info_log (string)`**: The info log message.\n- **`country_region (string)`**: The local timezone, follows pytz library. Example `Asia/Tokyo`.\n\nThe complete codes snippet is as below:\n\n```python\nfrom loris_log.boto3Client import BotoClient \nfrom loris_log.customLog immport CustomLog \n\n# First, establish the connection to the AWS CloudWatch.\naws_region = \"\"\naws_log_group = \"\"\naws_log_stream = \"\"\nclient = Boto3Client(aws_region, aws_log_group, aws_log_stream)\n\n# Then, construct the relevant log message; in this example\n# a info log message for a sensor\ninfo_message = CustomLog.set_sensor_info_message(\n    \"[camera-01-2300001]\", \"[my-app]\", [\"[200]\", \"OK\"]\n)\n\n# Lastly, publishing the log message onto the CloudWatch\nlog_group = \"\"\nlog_stream = \"\"\ncountry_region = \"\"\nclient.set_log_message(log_group, log_stream, info_message, country_region)\n```\n\n# Example of Publishing the Info Log Message onto FTP server.\n\nThis demonstrates the approach of how to publishing a sensor log message onto\na remote FTP server.\n\nThis requires user first establishes the connection to a remote\nFTP server using the `FtpClient` method\n\n**`def FtpClient(hostname, port_num, username, password)`**:\n\n- **`hostname (string)`**: The FTP server hostname (IP address).\n- **`port_nun (int)`**: The FTP server port number.\n- **`username (string)`**: The FTP server username.\n- **`password (string)`**: The FTP server password.\n\nThen, it is follows by creating the info log message for the \nsensor using the `set_sensor_info_message` method.\n\n**`def set_sensor_info_message(sensor_id, name, message)`\n\n- **`sensor_id (string)`**: The sensor's id.\n- **`name (string)`**: The application/ API name.\n- **`message (list)`**: The sensor's log message.\n\nLastly, publishing the log message and write it onto\na log file via `set_ftp_log_file` method.\n\n**`def set_ftp_log_file(file_path, filename, log_message, country_region)`**\n\n- **`file_path (string)`**: The directory path of the log file.\n- **`filename (string)`**: The log file's file name.\n- **`log_message (list)`**: The sensor kog message.\n- **`country_region`**: The local country timezone, follows pytz library. Example `Asia/Tokyo`\n\nIf the log file (.log) was never created, create one first using \nthe method `create_ftp_log_file`.\n\n**`def create_ftp_log_file(file_path, filename, root)`**:\n\n- **`file_path`**: The path to the log file.\n- **`filename`**: The name of log file without extension.\n- **`root`**: The decision to whether create log file started from the root directory.\n\nThe complete example code is as presented below:\n\n```python\nfrom loris_log.ftpClient import FtpClient\nfrom loris_log.customLog import CustomLog\n\nhostname = \"\"\nport_num = 00\nusername = \"\"\npassword = \"\"\n# establish connction \nclient = FtpClient(hostname, port_num, username, password)\n\n# Then construct the info log message for the sensor\ninfo_message = CustomLog.set_sensor_info_message(\n    \"camera01-E11]]\",\n    \"[my-app]\", [\"[200]\", \"OK\"]\n)\n\n# Lastly push onto the FTP server.\nfile_path = \"log/testing/data\"\nfilename = \"sample\"\nroot = True\ncountry_region = \"\"\n\n# Optional, create the file if log file not existed\n# Otherwise, ignore this line\nclient.create_ftp_log_file(file_path, filename, root)\n\n# push the log message onto the log file.\nclient.set_ftp_log_file(file_path, filename, info_message, country_region)\n```\n# Example of creating the log file from root directory\n\nThis demonstrates the approach to create log file from the parent directory.\n\nFirst, establising the connection to the remote FTP server via `FTPClient` method.\n\n**`FTPClient(hostname, port, username, password)`**:\n\n- **`hostname`**: the host name of the FTP server.\n- **`port`**: the port number of the FTP server.\n- **`username`**: the username of the FTP server.\n- **`password`**: the password of the FTP server.\n\nsubsequently, create the log file by setting the root parameter to True inside\n`create_ftp_log_file` method.\n\n**`create_ftp_log_file(file_path, filename, root)`**:\n\n- **`file_path`**: the log file's file path.\n- **`filename`**: the name of the log file.\n- **`root`**: let the log file created from the root directory.\n\nThe complete code snippet is as below\n\n```python\nfrom loris_log.ftpClient import FtpClient\n\nport = 22\nhostname = \"\"\nusername = \"\"\npassword = \"\"\n\n# establish the connection with the remote FTP server.\nclient = FtpClient(hostname, port, username, password)\n\n# then, create the log file from the root directory\nfile_path = \"testing/sample\"\nfilename = \"sample\"\nroot = True\n\nclient.create_ftp_log_file(\n    file_path, filename, root\n)\n```\n\n# Example of creating the log file but not from root directory\n\nThis demonstrates the approach to create the log file, but not from the parent directory.\n\nFirst, establising the connection to the remote FTP server via `FTPClient` method\n\n**`FTPClient(hostname, port, username, password)`**:\n\n- **`hostname`**: the host name of the FTP server.\n- **`port`**: the port number of the FTP server.\n- **`username`**: the username of the FTP server.\n- **`password`**: the password of the FTP server.\n\nsubsequently, create the log file by setting the root parameter to True inside\n`create_ftp_log_file` method.\n\n**`create_ftp_log_file(file_path, filename, root)`**:\n\n- **`file_path`**: the log file's file path.\n- **`filename`**: the name of the log file.\n- **`root`**: let the log file created from the root directory.\n\nThe complete code snippet is as below\n\n```python\nfrom loris_log.ftpClient import FtpClient\n\nport = 22\nhostname = \"\"\nusername = \"\"\npassword = \"\"\n\n# establish the connection with the remote FTP server.\nclient = FtpClient(hostname, port, username, password)\n\n# then, create the log file from the root directory\nfile_path = \"testing/sample\"\nfilename = \"sample\"\nroot = False\n\nclient.create_ftp_log_file(\n    file_path, filename, root\n)\n```\n\n# Example of creating the log file for sensor's data from root directory\n\nThis demonstrates the approach to create log file from the parent directory.\n\nFirst, establising the connection to the remote FTP server via `FTPClient` method.\n\n**`FTPClient(hostname, port, username, password)`**:\n\n- **`hostname`**: the host name of the FTP server.\n- **`port`**: the port number of the FTP server.\n- **`username`**: the username of the FTP server.\n- **`password`**: the password of the FTP server.\n\nsubsequently, create the log file by setting the root parameter to True inside\n`create_ftp_log_data` method.\n\n**`create_ftp_log_data(file_path, filename, root)`**:\n\n- **`file_path`**: the log file's file path.\n- **`filename`**: the name of the log file.\n- **`root`**: let the log file created from the root directory.\n\nThe complete code snippet is as below\n\n```python\nfrom loris_log.ftpClient import FtpClient\n\nport = 22\nhostname = \"\"\nusername = \"\"\npassword = \"\"\n\n# establish the connection with the remote FTP server.\nclient = FtpClient(hostname, port, username, password)\n\n# then, create the log file from the root directory\nfile_path = \"testing/sample\"\nfilename = \"sample\"\nroot = True\n\nclient.create_ftp_log_data(\n    file_path, filename, root\n)\n```\n# Example of creating the log file for sensor's data not from root directory\n\nThis demonstrates the approach to create the log file, but not from the parent directory.\n\nFirst, establising the connection to the remote FTP server via `FTPClient` method.\n\n**`FTPClient(hostname, port, username, password)`**:\n\n- **`hostname`**: the host name of the FTP server.\n- **`port`**: the port number of the FTP server.\n- **`username`**: the username of the FTP server.\n- **`password`**: the password of the FTP server.\n\nsubsequently, create the log file by setting the root parameter to True inside\n`create_ftp_log_data` method.\n\n**`create_ftp_log_data(file_path, filename, root)`**:\n\n- **`file_path`**: the log file's file path.\n- **`filename`**: the name of the log file.\n- **`root`**: let the log file created from the root directory.\n\nThe complete code snippet is as below\n\n```python\nfrom loris_log.ftpClient import FtpClient\n\nport = 22\nhostname = \"\"\nusername = \"\"\npassword = \"\"\n\n# establish the connection with the remote FTP server.\nclient = FtpClient(hostname, port, username, password)\n\n# then, create the log file from the root directory\nfile_path = \"testing/sample\"\nfilename = \"sample\"\nroot = False\n\nclient.create_ftp_log_data(\n    file_path, filename, root\n)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Log library to establish communication with FTP server and AWS CloudWatch; as well as to publish log message to these platforms.",
    "version": "0.2.4.post1",
    "project_urls": {
        "Homepage": "https://github.com/mikelim2/python-logging"
    },
    "split_keywords": [
        "log",
        "ftp",
        "cloudwatch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b4f23713befee68857a774e02f835440bf941f73be984d80b7861e16be3d660",
                "md5": "06c4f340b9f09ab7b97b4ea10012fca2",
                "sha256": "0d64b3e0b5b0580531ecba784511b3754c5063e64de98e46d77c0bb6941a3e10"
            },
            "downloads": -1,
            "filename": "loris_log-0.2.4.post1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "06c4f340b9f09ab7b97b4ea10012fca2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 15711,
            "upload_time": "2023-10-30T07:06:50",
            "upload_time_iso_8601": "2023-10-30T07:06:50.848215Z",
            "url": "https://files.pythonhosted.org/packages/2b/4f/23713befee68857a774e02f835440bf941f73be984d80b7861e16be3d660/loris_log-0.2.4.post1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45b291a9d418558737e6623957b7e2fd1c25127367317a808458c90447c9cea6",
                "md5": "420214a75ec9cec5686f8ef2def15a4b",
                "sha256": "53e987f604c022ee52ba19d35b758b8920c69ce89cf547f4d96080086c90e38b"
            },
            "downloads": -1,
            "filename": "loris_log-0.2.4.post1.tar.gz",
            "has_sig": false,
            "md5_digest": "420214a75ec9cec5686f8ef2def15a4b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 134451,
            "upload_time": "2023-10-30T07:06:53",
            "upload_time_iso_8601": "2023-10-30T07:06:53.983620Z",
            "url": "https://files.pythonhosted.org/packages/45/b2/91a9d418558737e6623957b7e2fd1c25127367317a808458c90447c9cea6/loris_log-0.2.4.post1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-30 07:06:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mikelim2",
    "github_project": "python-logging",
    "github_not_found": true,
    "lcname": "loris-log"
}
        
Elapsed time: 0.15089s