Skip to content

Commit

Permalink
Non json logging (#70)
Browse files Browse the repository at this point in the history
* non json logging formatter

* lower harborapi version

* harborapi version without mro issues

* pin httpx version

* remove missed print call
  • Loading branch information
peters-david authored Jan 9, 2025
1 parent 91ce127 commit e67bea6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
logger = logging.getLogger()
logger.setLevel(logging.INFO)
if json_logging:
handler = logging.StreamHandler()
formatter = jsonlogger.JsonFormatter()
handler.setFormatter(formatter)
logger.addHandler(handler)
else:
formatter = logging.Formatter()
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)


async def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def sync_projects(client, path, logger):
"""

logger.info("Syncing projects")
target_projects_string = await fill_template(client, path)
target_projects_string = await fill_template(client, path, logger)
target_projects = json.loads(target_projects_string)
current_projects = await client.get_projects(limit=None)
current_project_names = [
Expand Down
2 changes: 1 addition & 1 deletion src/retention_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def sync_retention_policies(client, path, logger):
"""

logger.info("Syncing retention policies")
retention_policies_string = await fill_template(client, path)
retention_policies_string = await fill_template(client, path, logger)
retention_policies = json.loads(retention_policies_string)
for retention_policy in retention_policies:
retention_scope = retention_policy["scope"]["ref"]
Expand Down
4 changes: 2 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_member_id(members: [ProjectMemberEntity], username: str) -> int | None:
return None


async def fill_template(client, path: str) -> str:
async def fill_template(client, path: str, logger) -> str:
"""Takes the path to a template file and returns its content with the
replaced ids
"""
Expand All @@ -78,7 +78,7 @@ async def fill_template(client, path: str) -> str:
placeholders = re.findall(
r'{{[ ]*(?:project|registry):[A-z,0-9,.,\-,_]+[ ]*}}', content
)
print(f"Found id templates: {placeholders}")
logger.info("Found id templates", extra={"placeholders": placeholders})
placeholders = [
placeholder.replace('{{', '').replace(' ', '').replace('}}', '')
for placeholder in placeholders
Expand Down

0 comments on commit e67bea6

Please sign in to comment.