Skip to content

Commit

Permalink
tool: Replace print with logging.log
Browse files Browse the repository at this point in the history
This moves errors to stderr via logging module.
  • Loading branch information
Spindel committed Apr 18, 2024
1 parent 9c2b79d commit b81922d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions caramel/scripts/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import argparse
import concurrent.futures
import datetime
import logging
import sys

import transaction
from dateutil.relativedelta import relativedelta
from pyramid.settings import asbool
from sqlalchemy import create_engine

import caramel.models as models
from caramel import config
from caramel.config import bootstrap
from caramel import config, models

LOG = logging.getLogger(name="caramel.tool")


def cmdline():
Expand Down Expand Up @@ -81,9 +82,9 @@ def cmdline():


def error_out(message, exc=None):
print(message)
LOG.error(message)
if exc is not None:
print(str(exc))
LOG.error(str(exc))
sys.exit(1)


Expand Down Expand Up @@ -197,12 +198,14 @@ def csr_resign(ca, lifetime_short, lifetime_long, backdate):
try:
future.result()
except Exception as ex:
print("Future failed", str(ex))
LOG.error("Future failed: %s", ex)


def main():
"""Entrypoint of application."""
args = cmdline()
env = bootstrap(args.inifile, dburl=args.dburl)
logging.basicConfig(format="%(message)s", level=logging.WARNING)
env = config.bootstrap(args.inifile, dburl=args.dburl)
settings, closer = env["registry"].settings, env["closer"]
db_url = config.get_db_url(args, settings)
engine = create_engine(db_url)
Expand Down

0 comments on commit b81922d

Please sign in to comment.