0Pricing
Web Scraping & Bots · 강의

봇의 로그 기록과 오류 처리

구조화된 로그 기록과 우아한 오류 처리를 추가해 오류를 확인하고 복구할 수 있는 견고한 간단한 봇을 만들어 보세요.

봇의 로그 기록과 오류 처리은(는) CoddyKit의 무료 Web Scraping & Bots 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Web Scraping & Bots 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Web Scraping & Bots 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Bots Need Logs

A bot runs unattended, often on a schedule. When something breaks, you are not watching. Logging leaves a trail so you can diagnose what happened after the fact.

Without logs, a silent failure can go unnoticed for days.

print() Is Not Logging

Beginners use print(), but it has no levels, no timestamps, and no easy way to redirect to a file. Python's logging module solves all of this.

print('something happened')  # no level, no time, hard to manage

Setting Up Logging

Configure logging once at startup. Set a format with a timestamp and a level, and choose where output goes.

import logging

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(message)s'
)
log = logging.getLogger('bot')
log.info('Bot started')

Log Levels

Levels let you control verbosity:

  • DEBUG detailed tracing.
  • INFO normal progress.
  • WARNING something odd but recoverable.
  • ERROR an operation failed.
  • CRITICAL the bot cannot continue.
log.debug('fetched 12 rows')
log.warning('retrying after timeout')
log.error('login failed')

Logging to a File

For unattended bots, write logs to a file so you can review them later. A rotating handler caps file size.

from logging.handlers import RotatingFileHandler

handler = RotatingFileHandler('bot.log', maxBytes=1_000_000, backupCount=3)
log.addHandler(handler)

Catching Exceptions

Wrap risky operations in try/except so one failure does not crash the whole run. Log the error with context.

try:
    submit_form(data)
except Exception as e:
    log.error('form submission failed: %s', e)

Logging Full Tracebacks

Use log.exception inside an except block to capture the full stack trace, which is invaluable for debugging.

try:
    risky()
except Exception:
    log.exception('unexpected error in risky()')

Retrying Transient Failures

Network blips are common. Catch them and retry a few times before giving up, logging each attempt.

for attempt in range(3):
    try:
        fetch()
        break
    except ConnectionError:
        log.warning('attempt %d failed, retrying', attempt + 1)
else:
    log.error('all attempts failed')

Failing Loudly

Silent failures are dangerous. For critical errors, escalate: send an alert email, write a marker file, or exit with a non-zero code so a scheduler notices.

import sys
if not data:
    log.critical('no data scraped, aborting')
    sys.exit(1)

Clean Shutdown

Always release resources even on error. A finally block (or context managers) guarantees browsers close and files flush regardless of what went wrong.

try:
    run_bot()
finally:
    driver.quit()
    log.info('bot finished')

Structured Logging Context

Attach context to each log line, such as the current URL or item id, so when you scan a long log you immediately know which record a message refers to.

log.info('scraped item %s from %s', item_id, url)

Quick Check

Test your understanding of bot logging and error handling.

Recap

You learned to make simple bots resilient: use the logging module instead of print, choose appropriate levels, log to rotating files, catch and log exceptions with tracebacks, retry transient errors, fail loudly on critical issues, and shut down cleanly.

자주 묻는 질문

“봇의 로그 기록과 오류 처리” 강의는 무료인가요?

네 — “봇의 로그 기록과 오류 처리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Web Scraping & Bots 강의 전체를 잠금 해제할 수 있습니다. Web Scraping & Bots 강의에는 총 4개의 강의가 포함되어 있습니다.

“봇의 로그 기록과 오류 처리”에서 뭘 배우나요?

구조화된 로그 기록과 우아한 오류 처리를 추가해 오류를 확인하고 복구할 수 있는 견고한 간단한 봇을 만들어 보세요. 브라우저에서 직접 실행하는 실습 코드로 Web Scraping & Bots을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Web Scraping & Bots을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Web Scraping & Bots은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“봇의 로그 기록과 오류 처리” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Web Scraping & Bots 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Web Scraping & Bots 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 봇 목표 정의
  2. 간단한 양식 제출 자동화
  3. 기본 작업 예약
  4. 봇의 로그 기록과 오류 처리
← Web Scraping & Bots(으)로 돌아가기