Miscellaneous

Miscellaneous#

Logging#

This library features numerous console loggers, with an option to redirect the output to a file.

Logger name

Level

Description

cterasdk

NOTSET

Package Logger

cterasdk.edge

INFO

Logger for CTERA Edge and Drive App

cterasdk.core

INFO

Logger for CTERA Portal

cterasdk.common

INFO

Common Infrastructure Logger

cterasdk.metadata.connector

INFO

Notification Service Logger

cterasdk.http

ERROR

Transport Layer Logger

cterasdk.http.trace

ERROR

Transport Layer Tracing

cterasdk.crypto

ERROR

Cryptography Logger

cterasdk.filesystem

ERROR

Local File System Logger

List the available loggers:

import logging
import cterasdk.logging

print({name: logging.getLevelName(logging.getLogger(name).level) for name in logging.root.manager.loggerDict})

To update the log level of a logger:

import logging
import cterasdk.logging

logging.getLogger('cterasdk.metadata.connector').setLevel(logging.DEBUG)  # Enables 'DEBUG'

Redirecting log output to a file:

set cterasdk.log=cterasdk.log  # Redirect output to 'cterasdk.log' in the current directory

set cterasdk.log=C:/users/username/Desktop/cterasdk.log  # Redirect output to an alternate location
export cterasdk.log="cterasdk.log"

export cterasdk.log="/home/username/cterasdk.log"

Serialization#

This library features JSON and XML serialization, in alignment with the CTERA API schema.

cterasdk.convert.serializers.toxmlstr(obj, pretty_print=False)

Convert a Python object to an XML string

Parameters:
  • obj (object) – the Python object

  • pretty_print (bool) – whether to format the XML string, defaults to False

Returns:

XML string of the object

Return type:

str

user = Object()
user.name = 'alice'
user.firstName = 'Alice'
user.lastName = 'Wonderland'
user.email = 'alice@adventures.com'
user.password = 'Passw0rd1!'
print(toxmlstr(user))
print(toxmlstr(user, True))
cterasdk.convert.serializers.tojsonstr(obj, pretty_print=True, no_log=True)

Convert a Python object to a JSON string.

Parameters:
  • obj (object) – the Python object

  • pretty_print (bool) – Whether to format the JSON string, defaults to True

  • no_log (book) – Hide sensitive values in the log messages

Returns:

JSON string of the object

Return type:

str

user = Object()
user.name = 'alice'
user.firstName = 'Alice'
user.lastName = 'Wonderland'
user.email = 'alice@adventures.com'
user.password = 'Passw0rd1!'
print(tojsonstr(user))
{
     "lastName": "Wonderland",
     "password": "Passw0rd1!",
     "name": "alice",
     "firstName": "Alice",
     "email": "alice@adventures.com"
}
print(tojsonstr(user, False))
{"lastName": "Wonderland", "password": "Passw0rd1!", "name": "alice", "firstName": "Alice", "email": "alice@adventures.com"}