Version: 9.12.0
KERNEL_PY.kernel.logger.Logger Class Reference

This class formats and displays log messages in Salome environment. More...

Inheritance diagram for KERNEL_PY.kernel.logger.Logger:

Public Member Functions

def __init__ (self, keyword="KEY", level=salome.kernel.logconfig.loggingLevel, color=None, sourceFileName=None)
 
def showDebug (self)
 Log all messages, including DEBUG level messages (equivalent to setLevel(logging.DEBUG)). More...
 
def setLogFile (self, logFilename)
 Define a log file to record the log messages (in addition to the standard output). More...
 
def setColor (self, color)
 Set the color of log messages on color-capable terminals. More...
 
def closeLogFile (self)
 Close the log file. More...
 
def hideDebug (self)
 Hide DEBUG level messages (equivalent to setLevel(logging.INFO)). More...
 

Private Attributes

 _baseFormatString
 
 _baseFormatter
 
 _stdoutStream
 
 _stdoutHandler
 
 _fileHandler
 

Detailed Description

This class formats and displays log messages in Salome environment.

It inherits logging.Logger class defined in logging module from Python library, so all methods from logging.Logger can be used here. The format of the traces is: LEVEL[keyword] : Message

,where LEVEL is the level of the message (DEBUG, INFO, etc.), keyword is the name of the logger, and Message is the message to log.

When creating a new Logger object, the parameter keyword defines the name of the logger, level defines the logging level (default is logging.DEBUG if KERNEL module is configured with –enable-debug option or logging.WARNING otherwise), and color defines the color of the log messages for this logger (log messages will appear in color only when displayed on color - capable ASCII terminals). See module salome.kernel.termcolor for the color constants.

By default, log messages will be displayed only on standard output. They can also be recorded in a file (see method setLogFile()). For now, the CORBA-based logging facility can not be used through this class.

A source filename sourceFileName can be defined. If this argument is specified, then the keyword is modified to the basename of the sourceFileName

Basic usage::

from salome.kernel.logger import Logger
log = Logger("Test")
log.debug("Debug message")
log.info("Information message")
log.warning("Warning message")
log.error("Error message")
log.critical("Fatal error message")
Definition: SALOME_Logger_Server.hxx:61


This class formats and displays log messages in Salome environment. It
inherits :class:`Logger<logging.Logger>` class defined in :mod:`logging`
module from Python library, so all methods from :class:`logging.Logger`
can be used here. The format of the traces is:

LEVEL    [keyword] : Message

where `LEVEL` is the level of the message (`DEBUG`, `INFO`, etc.),
`keyword` is the name of the logger, and `Message` is the message to log.

When creating a new Logger object, the parameter `keyword` defines the
name of the logger, `level` defines the logging level (default is
:const:`logging.DEBUG` if KERNEL module is configured with --enable-debug
option or :const:`logging.WARNING` otherwise), and `color` defines the color
of the log messages for this logger (log messages will appear in color
only when displayed on color-capable ASCII terminals). See module
:mod:`salome.kernel.termcolor` for the color constants.

By default, log messages will be displayed only on standard output. They
can also be recorded in a file (see method :meth:`setLogFile`). For now,
the CORBA-based logging facility can not be used through this class.

A source filename `sourceFileName` can be defined. If this argument is
specified, then the `keyword` is modified to the basename of the `sourceFileName`

Basic usage::

    from salome.kernel.logger import Logger
    log = Logger("Test")
    log.debug("Debug message")
    log.info("Information message")
    log.warning("Warning message")
    log.error("Error message")
    log.critical("Fatal error message")

Constructor & Destructor Documentation

◆ __init__()

def KERNEL_PY.kernel.logger.Logger.__init__ (   self,
  keyword = "KEY",
  level = salome.kernel.logconfig.loggingLevel,
  color = None,
  sourceFileName = None 
)

Member Function Documentation

◆ closeLogFile()

def KERNEL_PY.kernel.logger.Logger.closeLogFile (   self)

◆ hideDebug()

def KERNEL_PY.kernel.logger.Logger.hideDebug (   self)

Hide DEBUG level messages (equivalent to setLevel(logging.INFO)).

Hide DEBUG level messages (equivalent to ``setLevel(logging.INFO)``).

◆ setColor()

def KERNEL_PY.kernel.logger.Logger.setColor (   self,
  color 
)

Set the color of log messages on color-capable terminals.

If color is None, the default color will be used.

Set the color of log messages on color-capable terminals. If `color`
is :const:`None`, the default color will be used.

References logger.Logger._baseFormatString, KERNEL_PY.kernel.logger.Logger._baseFormatString, logger.Logger._baseFormatter, KERNEL_PY.kernel.logger.Logger._baseFormatter, logger.Logger._stdoutHandler, KERNEL_PY.kernel.logger.Logger._stdoutHandler, logger.Logger._stdoutStream, KERNEL_PY.kernel.logger.Logger._stdoutStream, termcolor.canDisplayColor(), and termcolor.getControlSequence().

◆ setLogFile()

def KERNEL_PY.kernel.logger.Logger.setLogFile (   self,
  logFilename 
)

Define a log file to record the log messages (in addition to the standard output).

Define a log file to record the log messages (in addition to the
standard output).

References logger.Logger._baseFormatter, KERNEL_PY.kernel.logger.Logger._baseFormatter, logger.Logger._fileHandler, KERNEL_PY.kernel.logger.Logger._fileHandler, logger.Logger.closeLogFile(), and KERNEL_PY.kernel.logger.Logger.closeLogFile().

◆ showDebug()

def KERNEL_PY.kernel.logger.Logger.showDebug (   self)

Log all messages, including DEBUG level messages (equivalent to setLevel(logging.DEBUG)).

Log all messages, including DEBUG level messages (equivalent to
``setLevel(logging.DEBUG)``).

Field Documentation

◆ _baseFormatString

KERNEL_PY.kernel.logger.Logger._baseFormatString
private

◆ _baseFormatter

◆ _fileHandler

◆ _stdoutHandler

KERNEL_PY.kernel.logger.Logger._stdoutHandler
private

◆ _stdoutStream

KERNEL_PY.kernel.logger.Logger._stdoutStream
private