Miscellaneous¶
Logging¶
The library includes a built-in console logger. The logger’s configuration is controlled by the config.Logging.get()
class object.
Redirecting the log to a file¶
You can redirect the cterasdk log to a file by setting the environment variable CTERASDK_LOG_FILE
Disabling the Logger¶
The logger is enabled by default. To disable the logger, run:
config.Logging.get().disable()
Changing the Log Level¶
The default logging level is set to logging.INFO
. To change the log level, run:
config.Logging.get().setLevel(logging.ERROR) # will log severity >= error
config.Logging.get().setLevel(logging.WARNING) # will log severity >= warning
Log Levels¶
The available log levels are:
Level Numeric Value CRITICAL 50 ERROR 40 WARNING 30 INFO 20 DEBUG 10
Formatting¶
The following formatting functions are included in this library:
-
cterasdk.convert.format.
tojsonstr
(obj, pretty_print=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
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"}
-
cterasdk.convert.format.
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))