Thực hành logging
Đoạn mã sau sẽ được chạy khi khởi động:
import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG,
format='%(levelname)s - %(message)s')
Bây giờ bạn sẽ thực hành các thao tác logging này.
Bài tập này là một phần của khóa học
Nhập môn Spark SQL bằng Python
Hướng dẫn bài tập
- Ghi log các cột của
text_dfở mức debug. - Ghi log việc
table1có được cache hay không ở mức info. - Ghi log hàng đầu tiên của
text_dfở mức warning. - Ghi log một số cột đã chọn của
text_dfở mức error.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# Log columns of text_df as debug message
____("text_df columns: %s", text_df.columns)
# Log whether table1 is cached as info message
____("table1 is cached: %s", spark.catalog.isCached(tableName="table1"))
# Log first row of text_df as warning message
____("The first row of text_df:\n %s", text_df.first())
# Log selected columns of text_df as error message
____("Selected columns: %s", text_df.select("id", "word"))