Logging
Logging
- class DIRAC.FrameworkSystem.private.standardLogging.Logging.Logging(father=None, name='')
Bases:
object
Logging is a wrapper of the logger object from the standard “logging” library which integrates some DIRAC concepts.
It aimed at seamlessly replacing the previous gLogger implementation and thus provides the same interface.
Logging is generally used to create log records, that are then sent to pre-determined backends.
Each Logging embeds a logger of “logging”. Logging can instanciate “children” logging objects and all Logging objects inherit from the configuration of LoggingRoot, the first Logging object to be instanciated.
- class LocalSubLogger(logger, extra)
Bases:
object
This is inspired from the standard LoggingAdapter. The idea is to provide an interface which looks like a Logger, but does not implement all the features. You can basically just create it, and log messages. You cannot create subLogger from it
This is to be used for very short lived sub logger. It allows to give context information (like a jobID) without creating a new logging object, which ends up eating all the memory (see https://github.com/DIRACGrid/DIRAC/issues/5280)
- __init__(logger, extra)
- Parameters:
logger –
Logging
object on which to be basedextra – dictionary of extra information to be passed
- always(sMsg, sVarMsg='')
Always level
- debug(sMsg, sVarMsg='')
Debug level
- error(sMsg, sVarMsg='')
Error level
- exception(sMsg='', sVarMsg='', lException=False, lExcInfo=False)
Exception level
- fatal(sMsg, sVarMsg='')
Fatal level
- info(sMsg, sVarMsg='')
Info level
- notice(sMsg, sVarMsg='')
Notice level
- verbose(sMsg, sVarMsg='')
Verbose level
- warn(sMsg, sVarMsg='')
Warn
- __init__(father=None, name='')
Initialization of the Logging object. By default, ‘name’ is empty, because getChild only accepts string and the first empty string corresponds to the root logger. Example: >>> logging.getLogger(‘’) == logging.getLogger(‘root’) # root logger >>> logging.getLogger(‘root’).getChild(‘log’) == logging.getLogger(‘log’) # log child of root
- always(sMsg, sVarMsg='')
Always level
- debug(sMsg, sVarMsg='')
Debug level
- error(sMsg, sVarMsg='')
Error level
- exception(sMsg='', sVarMsg='', lException=False, lExcInfo=False)
Exception level
- fatal(sMsg, sVarMsg='')
Fatal level
- static getAllPossibleLevels()
- Returns:
a list of all levels available
- getDisplayOptions()
- Returns:
the dictionary of the display options and their values. Must not be redefined
- getLevel()
- Returns:
the name of the level
- getLocalSubLogger(subName)
Create a subLogger which is meant to have very short lifetime, (e.g. when you want to add the jobID in the name)
Warning
This is a light version of a logger, read the documentation of
LocalSubLogger
carefully- Parameters:
subName (str) – name of the child Logging
- classmethod getName()
- Returns:
“system name/component name”
- getSubLogger(subName)
Create a new Logging object, child of this Logging, if it does not exists.
Warning
For very short lived sub logger, consider
getLocalSubLogger()
instead- Parameters:
subName (str) – name of the child Logging
- getSubName()
- Returns:
the name of the logger
- info(sMsg, sVarMsg='')
Info level
- notice(sMsg, sVarMsg='')
Notice level
- registerBackend(desiredBackend, backendOptions=None, backendFilters=None)
Attach a backend to the Logging object. Convert backend name to backend class name to a Backend object and add it to the Logging object
- Parameters:
desiredBackend – a name attaching to a backend type. List of possible values: [‘stdout’, ‘stderr’, ‘file’]
backendOptions – dictionary of different backend options. Example: FileName=’/tmp/log.txt’
backendFilters – dictionary of different backend filters. Example: {‘ModuleFilter’: {‘dirac’: ‘ERROR’}}
- Returns:
Success or failure of registration
- Return type:
- registerBackends(desiredBackends, backendOptions=None)
Attach a list of backends to the Logging object. Convert backend names to backend class names to Backend objects and add them to the Logging object
- param desiredBackends:
list of different names attaching to differents backends. list of the possible values: [‘stdout’, ‘stderr’, ‘file’]
- param backendOptions:
dictionary of different backend options. Example: FileName=’/tmp/log.txt’
Deprecated: Use registerBackend() instead
- setLevel(levelName)
Check if the level name exists and set it.
- Parameters:
levelName – string representing the level to give to the logger
- Returns:
boolean representing if the setting is done or not
- showContexts(yesno=True)
Depending on the value, display or not the context of the message. Make sure to enable the headers: showHeaders(True) before
- Parameters:
yesno (bool) – determine the log record format
- showHeaders(yesno=True)
Depending on the value, display or not the prefix of the message.
- Parameters:
yesno (bool) – determine the log record format
- showStack()
Display a debug message without any content.
- Returns:
boolean, True if the message is sent, else False
- showThreadIDs(yesno=True)
Depending on the value, display or not the thread ID. Make sure to enable the headers: showHeaders(True) before
- Parameters:
yesno (bool) – determe the log record format
- showTimeStamps(yesno=True)
Depending on the value, display or not the timestamp of the message. Make sure to enable the headers: showHeaders(True) before
- Parameters:
yesno (bool) – determine the log record format
- shown(levelName)
Determine whether messages with a certain level will be displayed.
- Parameters:
levelName – string representing the level to analyse
- Returns:
boolean which give the answer
- verbose(sMsg, sVarMsg='')
Verbose level
- warn(sMsg, sVarMsg='')
Warn