Botlar için Günlük Kaydı ve Hata İşleme
Yapılandırılmış günlük kaydı ve zarif hata işleme ekleyerek hataların görünür ve telafi edilebilir olmasını sağlayan dayanıklı basit botlar oluşturun.
Botlar için Günlük Kaydı ve Hata İşleme, CoddyKit'te ücretsiz bir Web Scraping & Bots dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Web Scraping & Bots öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Web Scraping & Bots kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
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 manageSetting 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:
DEBUGdetailed tracing.INFOnormal progress.WARNINGsomething odd but recoverable.ERRORan operation failed.CRITICALthe 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.
Yapay zeka eğitmeniyle Python öğren — ücretsiz
Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.
- Kurslar
- 12
- Dersler
- 48
Sıkça Sorulan Sorular
“Botlar için Günlük Kaydı ve Hata İşleme” dersi ücretsiz mi?
Evet — “Botlar için Günlük Kaydı ve Hata İşleme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Web Scraping & Bots kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Web Scraping & Bots kursu toplamda 4 dersten oluşur.
“Botlar için Günlük Kaydı ve Hata İşleme” dersinde ne öğreneceğim?
Yapılandırılmış günlük kaydı ve zarif hata işleme ekleyerek hataların görünür ve telafi edilebilir olmasını sağlayan dayanıklı basit botlar oluşturun. Web Scraping & Bots ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Web Scraping & Bots öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Web Scraping & Bots, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.
“Botlar için Günlük Kaydı ve Hata İşleme” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Web Scraping & Bots dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Web Scraping & Bots dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Bot Hedeflerini Tanımlama
- Basit Form Gönderimlerini Otomatikleştirme
- Temel Görevleri Zamanlama
- Botlar için Günlük Kaydı ve Hata İşleme