เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ฝึกใช้งาน Logging

โค้ดต่อไปนี้ถูกรันตั้งแต่เริ่มต้น:

import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG,
                    format='%(levelname)s - %(message)s')

ตอนนี้จะได้ฝึกใช้งานการบันทึก log แต่ละประเภท

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Spark SQL in Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • บันทึกคอลัมน์ของ text_df เป็น debug message
  • บันทึกสถานะว่า table1 ถูก cache ไว้หรือไม่ เป็น info message
  • บันทึกแถวแรกของ text_df เป็น warning message
  • บันทึกคอลัมน์ที่เลือกจาก text_df เป็น error message

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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"))
แก้ไขและรันโค้ด