cfdm.log_level

cfdm.log_level(*arg)[source]

The minimal level of seriousness of log messages which are shown.

This can be adjusted to filter out potentially-useful log messages generated by cfdm at runtime, such that any messages marked as having a severity below the level set will not be reported.

For example, when set to 'WARNING' (or equivalently 1), all messages categorised as 'DEBUG' or 'INFO' will be suppressed, and only warnings will emerge.

See https://ncas-cms.github.io/cfdm/tutorial.html#logging for a detailed breakdown on the levels and configuration possibilities.

The default level is 'WARNING' (1).

New in version (cfdm): 1.8.4

See also

configuration

Parameters
log_level: str or int or Constant, optional

The new value of the minimal log severity level. This can be specified either as a string equal (ignoring case) to the named set of log levels or identifier 'DISABLE', or an integer code corresponding to each of these, namely:

  • 'DISABLE' (0);

  • 'WARNING' (1);

  • 'INFO' (2);

  • 'DETAIL' (3);

  • 'DEBUG' (-1).

Returns
Constant

The value prior to the change, or the current value if no new value was specified (or if one was specified but was not valid). Note the string name, rather than the equivalent integer, will always be returned.

Examples

>>> cfdm.log_level()
<Constant: 'WARNING'>
>>> print(cfdm.log_level())
WARNING
>>> str(cfdm.log_level())
'WARNING'
>>> old = cfdm.log_level('INFO')
>>> cfdm.log_level()
<Constant: 'WARNING'>
>>> cfdm.log_level(old)
<Constant: 'INFO'>
>>> cfdm.log_level()
<Constant: 'WARNING'>

Use as a context manager:

>>> print(cfdm.log_level())
WARNING
>>> with cfdm.log_level('DETAIL'):
...     print(cfdm.log_level(), cfdm.log_level(-1), cfdm.log_level())
...
DETAIL DETAIL DEBUG
>>> print(cfdm.log_level())
WARNING