Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

logging.critical

Emits a record with the critical severity for a serious application failure.

Version: Python 3.14; repository image, production runtime not attested

Syntax

logging.critical(msg, *args, **kwargs)

Emits a record with the critical severity for a serious application failure.

Logging a critical record does not stop the process. The application must separately choose whether to continue or terminate.

CRITICAL has the standard numeric level 50. The module function addresses the root logger and calls basicConfig if it has no handlers. Its normal return is None. A level threshold can still discard the record. With the given format, the sample emits CRITICAL disk full and continues.

import logging,io
out=io.StringIO()
logging.basicConfig(stream=out,level=logging.CRITICAL,format='%(levelno)d %(message)s',force=True)
logging.error('recoverable')
assert logging.critical('disk %s','full') is None
assert out.getvalue()=='50 disk full\n'

Examples

import logging
from io import StringIO

out = StringIO()
logging.basicConfig(stream=out, format="%(levelname)s %(message)s", force=True)
logging.critical("disk %s", "full")
print(out.getvalue().strip())
print("continued")

Result

CRITICAL disk full
continued

CRITICAL has the standard numeric level 50. The module function addresses the root logger and calls basicConfig if it has no handlers. Its normal return is None. A level threshold can still discard the record. With the given format, the sample emits CRITICAL disk full and continues.

Sources