Loguru: backtrace=False, but loguru is still showing tracebacks on exceptions

Created on 2 Jun 2019  路  3Comments  路  Source: Delgan/loguru

logger.add("/var/log/protectwise_bootstrap.log", backtrace=False, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}")

backtrace=False, but loguru is still showing tracebacks on exceptions

image

question

Most helpful comment

Hi.

I guess you have two configured handlers: the first one logs messages to sys.stderr (this is the default handler automatically added), the second one logs messages to "protectwise_bootstrap.log" (the handler you manually added).

The backtrace properties of handlers are independent of each others. The default handler use backtrace=True. So, even if you add a new handler with logger.add(..., backtrace=False), the default one is not modified and will display full traceback.

You can either set LOGURU_BACKTRACE=NO for development, or explicitly add a sys.stderr handler with backtrace=False:

logger.remove()  # Remove default handler (and all others)
logger.add(sys.stderr, backtrace=False)
logger.add("protectwise_bootstrap.log", backtrace=False, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}")

Alternatively, using configure():

# Default handler (and all others) is automatically removed while using '.configure()'
logger.configure(handlers=[
    {"sink": sys.stderr, "backtrace": False},
    {"sink": "protectwise_bootstrap.log", "backtrace": False, "format": "{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}"}
])

All 3 comments

Setting the env variable "export LOGURU_BACKTRACE=NO" seems to quiet the backtraces, but "backtrace=False" doesn't seem to turn them off. Python 3.6.8

Hi.

I guess you have two configured handlers: the first one logs messages to sys.stderr (this is the default handler automatically added), the second one logs messages to "protectwise_bootstrap.log" (the handler you manually added).

The backtrace properties of handlers are independent of each others. The default handler use backtrace=True. So, even if you add a new handler with logger.add(..., backtrace=False), the default one is not modified and will display full traceback.

You can either set LOGURU_BACKTRACE=NO for development, or explicitly add a sys.stderr handler with backtrace=False:

logger.remove()  # Remove default handler (and all others)
logger.add(sys.stderr, backtrace=False)
logger.add("protectwise_bootstrap.log", backtrace=False, format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}")

Alternatively, using configure():

# Default handler (and all others) is automatically removed while using '.configure()'
logger.configure(handlers=[
    {"sink": sys.stderr, "backtrace": False},
    {"sink": "protectwise_bootstrap.log", "backtrace": False, "format": "{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}"}
])

Thanks for your help. Really really lovely loggly module.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filantus picture filantus  路  5Comments

rightx2 picture rightx2  路  3Comments

BarryThrill picture BarryThrill  路  6Comments

heckad picture heckad  路  4Comments

af6140 picture af6140  路  5Comments