Skip to content

Commit 63b5f4b

Browse files
authored
Merge pull request #28 from sgibson91/add-logging
Add logging capabilities
2 parents dc9e6e7 + f03ea50 commit 63b5f4b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

images/gcp-filestore-backups/gcp-filestore-backups.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime, timedelta
66

77
import jmespath
8+
from loguru import logger
89

910

1011
def extract_region_from_zone(zone: str):
@@ -111,7 +112,7 @@ def filter_backups_into_recent_and_old(
111112
if datetime.now() - backup["createTime"] > timedelta(days=retention_days)
112113
]
113114
if len(old_backups) > 0:
114-
print(
115+
logger.info(
115116
f"Filestore backups older than {retention_days} days have been found. They will be deleted." # noqa: E501
116117
)
117118

@@ -140,7 +141,7 @@ def create_backup_if_necessary(
140141
zone (str): The GCP zone to create the backup in, e.g. us-central1-b
141142
"""
142143
if len(backups) == 0:
143-
print(
144+
logger.info(
144145
f"There have been no recent backups of the filestore for project {project}. Creating a backup now..." # noqa: E501
145146
)
146147

@@ -168,7 +169,7 @@ def create_backup_if_necessary(
168169
]
169170
)
170171
else:
171-
print("Recent backup found.")
172+
logger.info("Recent backup found.")
172173

173174

174175
def delete_old_backups(backups: list, region: str):
@@ -192,7 +193,7 @@ def delete_old_backups(backups: list, region: str):
192193
]
193194
)
194195
else:
195-
print("No outdated backups found.")
196+
logger.info("No outdated backups found.")
196197

197198

198199
def main(args):
@@ -264,6 +265,7 @@ def main(args):
264265
)
265266

266267
args = parser.parse_args()
268+
logger.info(f"Parsed arguments: {vars(args)}")
267269

268270
while True:
269271
main(args)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
jmespath
2+
loguru

0 commit comments

Comments
 (0)