Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Logging into QR Code Generator #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 39 additions & 20 deletions QR_code_generator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
import qrcode

# Enter url of any website here.
input_URL = "https://www.google.com/"

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=15,
border=4,
)

qr.add_data(input_URL)
qr.make(fit=True)

# convert into image
img = qr.make_image(fill_color="red", back_color="white")
img.save("url_qrcode.png")

print(qr.data_list)
import qrcode
import logging
from logging.handlers import RotatingFileHandler

# Set up logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[RotatingFileHandler('qr_code_generator.log', maxBytes=5000, backupCount=2),
logging.StreamHandler()])

logger = logging.getLogger(__name__)

try:
logger.info('Starting QR code generation')

# Enter url of any website here.
input_URL = "https://www.google.com/"

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=15,
border=4,
)

qr.add_data(input_URL)
qr.make(fit=True)

# convert into image
img = qr.make_image(fill_color="red", back_color="white")
img.save("url_qrcode.png")

logger.info('QR code generated and saved successfully')
except Exception as e:
logger.error('An error occurred while generating the QR code: %s', e)
finally:
logger.info('QR code generation process completed')

print(qr.data_list)