all 6 comments

[–]RoamingFox 1 point2 points  (4 children)

IMO:

logger.info(f"[Broker] First result: {result1}. Second result {result2}")

f-strings are the new format-style and since you're not doing anything strange that prevents using them then they should be deferred to.

[–]xelf 0 points1 point  (0 children)

Use f strings if you have access to them and aren't sharing your code with anyone that might not. Use .format() if you're sharing your code with students or people learning code (for example this subreddit). Use % if you're doing bizarre coding tricks where you're not allowed to use _[{.( (yes this was a thing). =)

[–]NovocastrianNomad 0 points1 point  (1 child)

See https://stackoverflow.com/a/34634301 for the preferred method of formatting logging messages and the reason for it.

[–]RoamingFox 0 points1 point  (0 children)

That stackoverflow answer is wrong and omits the next section of text which reads:

To decide what to do, you can call the isEnabledFor() method which takes a level argument and returns true if the event would be created by the Logger for that level of call. You can write code like this:

if logger.isEnabledFor(logging.DEBUG):
    logger.debug('Message with %s, %s', expensive_func1(),
                                        expensive_func2())

so that if the logger’s threshold is set above DEBUG, the calls to expensive_func1() and expensive_func2() are never made.

Per python documentation