Module sinbadflow.utils.logger

Expand source code
from enum import Enum
import logging


class LogLevel(Enum):
  '''Enum class used to determine log level'''
  INFO = 0
  WARNING = 1
  CRITICAL = 2


class Logger():
    '''Logger class used in Sinbadflow pipeline builder. Currently 'print', 'logging' and inner class 'EmptyLogger' functionality is supported.

    Args:
      method: object - selects preferred option of logging (print/logging objects supported)

    Methods:
      log(message: string, level=Level.INFO: enum) - logs the message with specific importance level

    Objects:

      class EmptyLogger - logger object with 'log' method used for testing to keep stdout empty 

    Usage example:

        lg = Logger(logging)
        lg.log('test', Logger.LogLevel.WARNING) ---> logging.warning('test')

    '''

    class EmptyLogger():
        '''EmptyLogger classs used for testing or empty logging'''
        def log(message):
            pass

    def __init__(self, method):
        self.method = method
        self.level_to_method = {
            print: {
                LogLevel.INFO: print,
                LogLevel.WARNING: print,
                LogLevel.CRITICAL: print
            },
            logging: {
                LogLevel.INFO: logging.info,
                LogLevel.WARNING: logging.warning,
                LogLevel.CRITICAL: logging.error
            },
            Logger.EmptyLogger: {
                LogLevel.INFO: Logger.EmptyLogger.log,
                LogLevel.WARNING: Logger.EmptyLogger.log,
                LogLevel.CRITICAL: Logger.EmptyLogger.log
            }
        }

    def log(self, message, level=LogLevel.INFO):
        '''Logs the message with specific importance level

        Args:
          message: string
          level: enum, LogLevel.INFO by default
        '''
        self.level_to_method[self.method][level](message)

Classes

class LogLevel (value, names=None, *, module=None, qualname=None, type=None, start=1)

Enum class used to determine log level

Expand source code
class LogLevel(Enum):
  '''Enum class used to determine log level'''
  INFO = 0
  WARNING = 1
  CRITICAL = 2

Ancestors

  • enum.Enum

Class variables

var CRITICAL
var INFO
var WARNING
class Logger (method)

Logger class used in Sinbadflow pipeline builder. Currently 'print', 'logging' and inner class 'EmptyLogger' functionality is supported.

Args

method
object - selects preferred option of logging (print/logging objects supported)

Methods

log(message: string, level=Level.INFO: enum) - logs the message with specific importance level

Objects

class EmptyLogger - logger object with 'log' method used for testing to keep stdout empty

Usage example:

lg = Logger(logging)
lg.log('test', Logger.LogLevel.WARNING) ---> logging.warning('test')
Expand source code
class Logger():
    '''Logger class used in Sinbadflow pipeline builder. Currently 'print', 'logging' and inner class 'EmptyLogger' functionality is supported.

    Args:
      method: object - selects preferred option of logging (print/logging objects supported)

    Methods:
      log(message: string, level=Level.INFO: enum) - logs the message with specific importance level

    Objects:

      class EmptyLogger - logger object with 'log' method used for testing to keep stdout empty 

    Usage example:

        lg = Logger(logging)
        lg.log('test', Logger.LogLevel.WARNING) ---> logging.warning('test')

    '''

    class EmptyLogger():
        '''EmptyLogger classs used for testing or empty logging'''
        def log(message):
            pass

    def __init__(self, method):
        self.method = method
        self.level_to_method = {
            print: {
                LogLevel.INFO: print,
                LogLevel.WARNING: print,
                LogLevel.CRITICAL: print
            },
            logging: {
                LogLevel.INFO: logging.info,
                LogLevel.WARNING: logging.warning,
                LogLevel.CRITICAL: logging.error
            },
            Logger.EmptyLogger: {
                LogLevel.INFO: Logger.EmptyLogger.log,
                LogLevel.WARNING: Logger.EmptyLogger.log,
                LogLevel.CRITICAL: Logger.EmptyLogger.log
            }
        }

    def log(self, message, level=LogLevel.INFO):
        '''Logs the message with specific importance level

        Args:
          message: string
          level: enum, LogLevel.INFO by default
        '''
        self.level_to_method[self.method][level](message)

Class variables

var EmptyLogger

EmptyLogger classs used for testing or empty logging

Methods

def log(self, message, level=LogLevel.INFO)

Logs the message with specific importance level

Args

message
string
level
enum, LogLevel.INFO by default
Expand source code
def log(self, message, level=LogLevel.INFO):
    '''Logs the message with specific importance level

    Args:
      message: string
      level: enum, LogLevel.INFO by default
    '''
    self.level_to_method[self.method][level](message)