Package: loris-log
PYTZ Library Country RegionThe complete list ofcountry regionat PYTZ library could refers to pytz library documentation.Python Application Logging ModuleThe centralized application logging library.Logging Data LevelFATAL: 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 GenerationPlease do use uuid4 for generating the random unique ID.importuuidfromloris_log.boto3ClientimportBoto3Client# generating the random uu_id for each calling session.id=uuid.uuid4()Otherwise use uuid5 for fixed id generation.importuuid# generating the fixed uu_id for each calling session.id=uuid.uuid5(uuid.NAMESPACE_DNS,'python.org')Log Message onto CloudWatch ExamplesConstruct the Error Log MessageThis 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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuid generatedid=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 namename="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 MessageThis 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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuidid=uuid.uuid4()# define the debug message as the string listdebug_message=["[200]","Service ok"]# define the name (string), oftenly is the IP address of remote host, or the application namename="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 MessageThis 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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuidid=uuid.uuid4()# define the fatal message as the string listfatal_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 MessageThis 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.fromloris_log.customLogimportCustomLogimportuuid# 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 CloudWatchThis 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 hereregion_name.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 theset_log_messagefunction, 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.importuuidfromloris_log.customLogimportCustomLogfromloris_log.boto3ClientimportBoto3Client# constuct the log message uses the above elaborated approach. The example# here creates a sample fatal log message.# ========================================================================# get the random uuidid=uuid.uuid4()# define the fatal message as the string listfatal_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 messagefatal_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 regionclient.set_log_message(log_group,log_stream,fatal_log,country_region)Log Message onto Remote Server Via FTP ExamplesConstruct the Debug Log MessageThis shows the example of constructing the debug log message onto the remote FTP server usingset_debug_messagefunction.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.fromloris_log.customLogimportCustomLog# randomly generated an id using uuid libraryid=uuid.uuid4()# then define the debug log message that is a listdebug_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 MessageThis shows the example of constructing the info log message onto the remmote FTP server via theset_info_messagefunction.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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuid generatedid=uuid.uuid4()# define the info log message as the string listinfo_message=["[200]","result is 0.9"]# define the name (string), oftenly is an IP address of remote host, or the application namename="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 MessageThis shows the example of constructing the error log message onto the FTP remote server via theset_error_messagefunction.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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuid generatedid=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 namename="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 MessageThis shows the example of constructing the fatal log message for CloudWatch via theset_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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuidid=uuid.uuid4()# define the fatal message as the string listfatal_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 DataThis shows the example of constructing the log message from some embedded device data via theset_ftp_log_datafunction.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 fromdatetime.datetime.now().endtime (string): The end time of an operation. Conversion fromdatetime.datetime.now().result (string): The result of the embedded device/ system/ model etc. Conversion fromdouble\ float\ long.groundtruth (string): The result of embedded device/ system/ model etc. Conversion fromdouble\ float\ long.importdatetimeimportuuidfromloris_log.customLogimportCustomLog# generate the uuidid=uuid.uuid4()# define the start timestarttime=datetime.datetime.now().strftime("%H:%M:%S")# define the end timeendtime=datetime.datetime.now().strftime("%H:%M:%S")# define the resultresult=str(32)# define the groundtruthgroundtruth=str(3)# construct the log data messagedata_log=CustomLog.set_ftp_log_data(id,starttime,endtime,result,groundtruth)Pushing Info Log Message onto Remote FTP ServerThis 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 theset_info_messagefunction.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.fromloris_log.customLogimportCustomLogimportuuid# get the random uuid generatedid=uuid.uuid4()# define the info log message as the string listinfo_message=["[200]","result is 0.9"]# define the name (string), oftenly is an IP address of remote host, or the application namename="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 serverhostname (string),port number (string),username (string), as well as thepassword (string)via theFTPClientinstancedef 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.fromloris_log.ftpClientimportFtpClienthostname=""port_num=22username=""password=""# Establish the connection to the remote FTP serverclient=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 theset_ftp_log_filemethod.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 messageregion_country (string): The log message local timezone; follows pytz timezone.# define the path for the log file, must follow the defined formatfile_path="log/testing/data"# then define the log file name and its file extensionsfilename="sample"# then define the local timezonecountry_region=""# Push the log file onto the remote FTP server. New log willclient.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 usingcreate_ftp_log_filedef 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 directoryfile_path="log_testing/data"filename="sample"root=Trueclient.create_ftp_log_file(file_path,filename,root)This shows the complete code examplefromloris_log.customLogimportCustomLogfromloris_log.ftpClientimportFtpClientimportuuid# get the random uuid generatedid=uuid.uuid4()# define the info log message as the string listinfo_message=["[200]","result is 0.9"]# define the name (string), oftenly is an IP address of remote host, or the application namename="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 hostnamehostname=""# define the FTP server port numberport_num=22# define the FTP server usernameusername=""# define the FTP server passwordpassword=""# Establish the connection to the remote FTP serverclient=FtpClient(hostname,port_num,username,password)# define the path for the log file, must follow the defined formatfile_path="log/testing/data"# then define the log file name and its file extensionsfilename="sample"# also, define the local timexonecountry_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 fileclient.create_ftp_log_file(file_path,filename,root)# Push the log file onto the remote FTP server. New log willclient.set_ftp_log_file(file_path,filename,info_log,country_region)Please usesset_error_message,set_info_message,set_fatal_message, orset_debug_messagemethod to log theerror,info,fatalordebugmessage.Example of Pushing Sensor Data to Remote FTP ServerThis 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 theset_ftp_log_datamethod.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.importdatetimeimportuuidfromloris_log.customLogimportCustomLog# generate the uuidid=uuid.uuid4()# define the start timestarttime=datetime.datetime.now().strftime("%H:%M:%S")# define the end timeendtime=datetime.datetime.now().strftime("%H:%M:%S")# define the resultresult=str(32)# define the groundtruthgroundtruth=str(3)# construct the log data messagedata_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 theFTPClientmethod.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.fromloris_log.ftpClientimportFtpClienthostname=""port_num=22username=""password=""# Establish the connection to the remote FTP serverclient=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 theset_ftp_log_datamethod.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.# define the path to the log filedirectory_path="/log_testing/data"# define the log file with its extensionfile_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 methodcreate_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.importdatetimeimportuuidfromloris_log.customLogimportCustomLogfromloris_log.ftpClientimportFtpClient# generate the uuidid=uuid.uuid4()# define the start timestarttime=datetime.datetime.now().strftime("%H:%M:%S")# define the end timeendtime=datetime.datetime.now().strftime("%H:%M:%S")# define the resultresult=str(32)# define the groundtruthgroundtruth=str(3)# construct the log data messagedata_log=CustomLog.set_ftp_log_data(id,starttime,endtime,result,groundtruth)# define FTP server hostnamehostname=""# define FTP server port numberport_num=22# define FTP server usernameusername=""# define FTP server passwordpassword=""# Establish the connection to the remote FTP serverclient=FtpClient(hostname,port_num,username,password)# define the path to the log filedirectory_path="/log_testing/data"# define the log file with its extensionfile_name="log"# define whether to start log creation from root directoryroot=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 SensorThis 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 theset_sensor_info_messagemethod 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.fromlog_loris.customLogimportCustomLogsensor_info_log=CustomLog.set_sensor_info_message("[camera-01-2300001]","[my application]",["[200]","OK"])Example of Constructing the Debug Log Message for A SensorThis 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 theset_sensor_debug_messagemethod 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:fromlog_loris.customLogimportCustomLogsensor_debug_log=CustomLog.set_sensor_debug_message("[camera-01-2300001]","[my application]",["[200]","OK"])Example of Constructing the Error Log Message for A SensorThis 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 theset_sensor_error_messagemethod 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:fromloris_log.customLogimportCustomLogsensor_error_log=CustomLog.set_sensor_error_message("[camera-01-2300001]","[my application]",["[200]","OK"])Example of Constructing the Fatal Log Message for A SensorThis 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 theset_sensor_fatal_messagemethod 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:fromloris_log.customLogimportCustomLogsensor_fatal_log=CustomLog.set_sensor_fatal_message("[camera-01-2300001]","[my application]",["[200]","OK"])Example of Publishing Sensor Info Message onto CloudWatchThe initial step requires establishing the connection onto the CloudWatch via theBoto3Clientas 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
usingset_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. ExampleAsia/Tokyo.The complete codes snippet is as below:fromloris_log.boto3ClientimportBotoClientfromloris_log.customLogimmportCustomLog# 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 sensorinfo_message=CustomLog.set_sensor_info_message("[camera-01-2300001]","[my-app]",["[200]","OK"])# Lastly, publishing the log message onto the CloudWatchlog_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 theFtpClientmethoddef 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 theset_sensor_info_messagemethod.**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 viaset_ftp_log_filemethod.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. ExampleAsia/TokyoIf the log file (.log) was never created, create one first using
the methodcreate_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:fromloris_log.ftpClientimportFtpClientfromloris_log.customLogimportCustomLoghostname=""port_num=00username=""password=""# establish connctionclient=FtpClient(hostname,port_num,username,password)# Then construct the info log message for the sensorinfo_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=Truecountry_region=""# Optional, create the file if log file not existed# Otherwise, ignore this lineclient.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 directoryThis demonstrates the approach to create log file from the parent directory.First, establising the connection to the remote FTP server viaFTPClientmethod.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 insidecreate_ftp_log_filemethod.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 belowfromloris_log.ftpClientimportFtpClientport=22hostname=""username=""password=""# establish the connection with the remote FTP server.client=FtpClient(hostname,port,username,password)# then, create the log file from the root directoryfile_path="testing/sample"filename="sample"root=Trueclient.create_ftp_log_file(file_path,filename,root)Example of creating the log file but not from root directoryThis demonstrates the approach to create the log file, but not from the parent directory.First, establising the connection to the remote FTP server viaFTPClientmethodFTPClient(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 insidecreate_ftp_log_filemethod.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 belowfromloris_log.ftpClientimportFtpClientport=22hostname=""username=""password=""# establish the connection with the remote FTP server.client=FtpClient(hostname,port,username,password)# then, create the log file from the root directoryfile_path="testing/sample"filename="sample"root=Falseclient.create_ftp_log_file(file_path,filename,root)Example of creating the log file for sensor's data from root directoryThis demonstrates the approach to create log file from the parent directory.First, establising the connection to the remote FTP server viaFTPClientmethod.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 insidecreate_ftp_log_datamethod.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 belowfromloris_log.ftpClientimportFtpClientport=22hostname=""username=""password=""# establish the connection with the remote FTP server.client=FtpClient(hostname,port,username,password)# then, create the log file from the root directoryfile_path="testing/sample"filename="sample"root=Trueclient.create_ftp_log_data(file_path,filename,root)Example of creating the log file for sensor's data not from root directoryThis demonstrates the approach to create the log file, but not from the parent directory.First, establising the connection to the remote FTP server viaFTPClientmethod.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 insidecreate_ftp_log_datamethod.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 belowfromloris_log.ftpClientimportFtpClientport=22hostname=""username=""password=""# establish the connection with the remote FTP server.client=FtpClient(hostname,port,username,password)# then, create the log file from the root directoryfile_path="testing/sample"filename="sample"root=Falseclient.create_ftp_log_data(file_path,filename,root)