-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_8_step_2_log_level.py
31 lines (26 loc) · 1.14 KB
/
lab_8_step_2_log_level.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Import logging
import logging
import json
# Set the log level in the basic configuration. This means we will capture all our log entries and not just those at Warning or above.
logging.basicConfig(filename='example.log',level=logging.DEBUG)
# This uses a json string as an input
json_string = """
{
"Input":[
{
"Text":"I am learning to code in AWS",
"SourceLanguageCode":"en",
"TargetLanguageCode":"en"
}
]
}
"""
json_input = json.loads(json_string)
# Defines two variables to store the language code from the input.
SourceLanguageCode = json_input['Input'][0]['SourceLanguageCode']
TargetLanguageCode = json_input['Input'][0]['TargetLanguageCode']
# The if statement checks to see if the language code is the same as the source code
if SourceLanguageCode == TargetLanguageCode:
logging.warning("The SourceLanguageCode is the same as the TargetLanguageCode - stopping") # This will print to the console as the default level is warning
else:
logging.info("The Source Language and Target Language codes are different - proceeding") # This will not print to the console because it is lower than warning