Replace prints with proper logs.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from google.cloud import storage
|
||||
import os
|
||||
import uuid
|
||||
@@ -13,7 +15,7 @@ def download_firebase_file(bucket_name, source_blob_name, destination_file_name)
|
||||
bucket = storage_client.bucket(bucket_name)
|
||||
blob = bucket.blob(source_blob_name)
|
||||
blob.download_to_filename(destination_file_name)
|
||||
print(f"File downloaded to {destination_file_name}")
|
||||
logging.info(f"File uploaded to {destination_file_name}")
|
||||
return destination_file_name
|
||||
|
||||
def upload_file_firebase(bucket_name, destination_blob_name, source_file_name):
|
||||
@@ -23,10 +25,10 @@ def upload_file_firebase(bucket_name, destination_blob_name, source_file_name):
|
||||
try:
|
||||
blob = bucket.blob(destination_blob_name)
|
||||
blob.upload_from_filename(source_file_name)
|
||||
print(f"File uploaded to {destination_blob_name}")
|
||||
logging.info(f"File uploaded to {destination_blob_name}")
|
||||
return True
|
||||
except Exception as e:
|
||||
print("Error uploading file to Google Cloud Storage:", e)
|
||||
logging.error("Error uploading file to Google Cloud Storage: " + str(e))
|
||||
return False
|
||||
|
||||
def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file_name):
|
||||
@@ -36,7 +38,7 @@ def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file
|
||||
try:
|
||||
blob = bucket.blob(destination_blob_name)
|
||||
blob.upload_from_filename(source_file_name)
|
||||
print(f"File uploaded to {destination_blob_name}")
|
||||
logging.info(f"File uploaded to {destination_blob_name}")
|
||||
|
||||
# Make the file public
|
||||
blob.make_public()
|
||||
@@ -45,7 +47,7 @@ def upload_file_firebase_get_url(bucket_name, destination_blob_name, source_file
|
||||
url = blob.public_url
|
||||
return url
|
||||
except Exception as e:
|
||||
print("Error uploading file to Google Cloud Storage:", e)
|
||||
logging.error("Error uploading file to Google Cloud Storage: " + str(e))
|
||||
return None
|
||||
|
||||
def save_to_db(collection: str, item):
|
||||
@@ -53,7 +55,7 @@ def save_to_db(collection: str, item):
|
||||
collection_ref = db.collection(collection)
|
||||
(update_time, document_ref) = collection_ref.add(item)
|
||||
if document_ref:
|
||||
print(f"Document added with ID: {document_ref.id}")
|
||||
logging.info(f"Document added with ID: {document_ref.id}")
|
||||
return (True, document_ref.id)
|
||||
else:
|
||||
return (False, None)
|
||||
@@ -67,7 +69,7 @@ def save_to_db_with_id(collection: str, item, id: str):
|
||||
# Set the data to the document
|
||||
document_ref.set(item)
|
||||
if document_ref:
|
||||
print(f"Document added with ID: {document_ref.id}")
|
||||
logging.info(f"Document added with ID: {document_ref.id}")
|
||||
return (True, document_ref.id)
|
||||
else:
|
||||
return (False, None)
|
||||
|
||||
Reference in New Issue
Block a user