Example #1
0
    def __init__(self,
                 endpoint,
                 capacity=1000,
                 flushLevel=logging.ERROR,
                 threadCount=1,
                 logger=None):
        """
        Initializes PulseHandler using the REST API endpoint, buffer capacity,
        buffer flush level and thread count.

        :param endpoint: The REST API endpoint for the Pulse Log Collector
        :type endpoint: str
        :param capacity: Number of records to buffer before flushing.
                         Defaults to 1000.
        :type capacity: int
        :param flushLevel: Log level at which to to flush the buffer.
        :type flushLevel: Log Level
        :param threadCount: Number of threads to handle post requests.
        :type threadCount: int
        :param logger: :class:`logging.Logger` object for debug logging. If none
                       is provided, a StreamHandler will be created to log to
                       sys.stdout. It is recommended that you provide a
                       logger if you plan to use more than one instance of this
                       class.
        :type logger: logging.Logger
        :rtype: PulseHandler
        """
        PulseBatcher.__init__(self, endpoint, capacity, threadCount, logger)
        MemoryHandler.__init__(self, capacity, flushLevel)
        # Cleanup when Python terminates
        atexit.register(self.close)
Example #2
0
    def __init__(self, when='h', interval=1, backupCount=0):
        """
        Constructor for logging formatter.
        """
        # Formatting string
        format_str = '%(asctime)s - %(levelname)s'
        if TvbProfile.current.cluster.IN_OPERATION_EXECUTION_PROCESS:
            log_file = self.CLUSTER_NODES_LOG_FILE
            if TvbProfile.current.cluster.IS_RUNNING_ON_CLUSTER_NODE:
                node_name = TvbProfile.current.cluster.CLUSTER_NODE_NAME
                if node_name is not None:
                    format_str += ' [node:' + str(node_name) + '] '
            else:
                format_str += ' [proc:' + str(os.getpid()) + '] '
        else:
            log_file = self.WEB_LOG_FILE

        format_str += ' - %(name)s - %(message)s'

        rotating_file_handler = SimpleTimedRotatingFileHandler(log_file, when, interval, backupCount)
        rotating_file_handler.setFormatter(logging.Formatter(format_str))

        MemoryHandler.__init__(self, capacity=self.BUFFER_CAPACITY, target=rotating_file_handler)
        
        
        
        
Example #3
0
 def __init__(self,
              capacity,
              mailhost,
              fromaddr,
              toaddrs,
              subject,
              credentials=None,
              secure=None,
              timeout=5.0):
     MemoryHandler.__init__(self,
                            capacity,
                            flushLevel=logging.INFO,
                            target=None)
     if isinstance(mailhost, (list, tuple)):
         self.mailhost, self.mailport = mailhost
     else:
         self.mailhost, self.mailport = mailhost, None
     if isinstance(credentials, (list, tuple)):
         self.username, self.password = credentials
     else:
         self.username = None
     self.fromaddr = fromaddr
     if isinstance(toaddrs, str):
         toaddrs = [toaddrs]
     self.toaddrs = toaddrs
     self.subject = subject
     self.secure = secure
     self.timeout = timeout
    def __init__(self, when='h', interval=1, backupCount=0):
        """
        Constructor for logging formatter.
        """
        # Formatting string
        format_str = '%(asctime)s - %(levelname)s'
        if TvbProfile.current.cluster.IN_OPERATION_EXECUTION_PROCESS:
            log_file = self.CLUSTER_NODES_LOG_FILE
            if TvbProfile.current.cluster.IS_RUNNING_ON_CLUSTER_NODE:
                node_name = TvbProfile.current.cluster.CLUSTER_NODE_NAME
                if node_name is not None:
                    format_str += ' [node:' + str(node_name) + '] '
            else:
                format_str += ' [proc:' + str(os.getpid()) + '] '
        else:
            log_file = self.WEB_LOG_FILE

        format_str += ' - %(name)s - %(message)s'

        rotating_file_handler = SimpleTimedRotatingFileHandler(log_file, when, interval, backupCount)
        rotating_file_handler.setFormatter(logging.Formatter(format_str))

        MemoryHandler.__init__(self, capacity=self.BUFFER_CAPACITY, target=rotating_file_handler)
        
        
        
        
Example #5
0
 def __init__(self, capacity, mail_subject):
     MemoryHandler.__init__(self,
                            capacity,
                            flushLevel=logging.ERROR,
                            target=None)
     self.mail_subject = mail_subject
     self.flushed_buffers = []
Example #6
0
 def __init__(self, level=logging.NOTSET, tag=None):
     MemoryHandler.__init__(self, capacity=400)
     if tag is not None:
         self.tag = tag
     self.level = level
     if py32:
         self.addFilter(self._filter)
     else:
         self.addFilter(FilterCallback(self._filter))
Example #7
0
    def __init__(self,
                 capacity,
                 mailhost,
                 toaddrs,
                 subject=None,
                 flushLevel=ERROR,
                 *,
                 credentials=None,
                 fromaddr=None,
                 secure=None,
                 mailport=None,
                 timeout=5.0):
        flushLevel = validate_log_level_int(flushLevel)

        if isinstance(credentials, str):
            credentials = (
                credentials,
                getpass(
                    "Please enter a password for {}: ".format(credentials)),
            )

        if fromaddr is None:
            if not isinstance(credentials,
                              (list, tuple)) or len(credentials) != 2:
                raise ValueError(
                    "you must supply either fromaddr or credentials=(uername, password); "
                    "fromaddr is None but credentials = {}".format(
                        credentials))
            fromaddr = credentials[0]

        if isinstance(toaddrs, str):
            toaddrs = [toaddrs]
        elif not toaddrs:
            raise ValueError(
                "you must supply toaddrs, either a single email address or a list thereof"
            )

        if mailport is not None:
            # SMTPHandler uses a tuple for this
            mailhost = (mailhost, mailport)
        elif not isinstance(mailhost, (list, tuple)) or len(mailhost) != 2:
            raise ValueError(
                "If mailport is not explicitly passed, mailhost must be a (host, port) tuple; got {}"
                .format(mailhost))

        MemoryHandler.__init__(self, capacity, flushLevel=flushLevel)
        SMTPHandler.__init__(
            self,
            mailhost=mailhost,
            fromaddr=fromaddr,
            toaddrs=toaddrs,
            subject=subject,
            credentials=credentials,
            secure=secure,
            timeout=timeout,
        )
Example #8
0
 def __init__(self,
              filename,
              capacity,
              flushLevel,
              flushInterval,
              target=None,
              **kwargs):
     MemoryHandler.__init__(
         self, capacity, flushLevel, target
         or make_handler(filename, capacity=1, **kwargs))
     self.__flushInterval = flushInterval
     self.__lastFlushTime = time.time()
     self.__condition = threading.Condition()
     self.__flusher = None
    def __init__(self,
                 capacity,
                 flushLevel=logging.ERROR,
                 database='log',
                 collection='log',
                 create_collection=False,
                 collection_kwargs={},
                 **kwargs):
        """Initialise handler.

            Args:
                capacity: Maximum number of log messages buffered.
                flushLevel: The buffer will be flushed when a message with a level
                    equal or higher to :obj:`flushLevel` is emitted.
                database (str): Database name.
                collection (str): Collection name.
                create_collection (bool): If True it tries to create a new collection
                    with the arguments specified in :obj:`collection_kwargs`.
                collection_args (dict): Dictionary with the arguments to pass to
                :obj:`create_collection` method. Check
                    http://api.mongodb.com/python/current/api/pymongo/database.html#pymongo.database.Database.create_collection

            kwargs are passed directly to :obj:`MongoClient` constructor. Check
                http://api.mongodb.com/python/current/api/pymongo/mongo_client.html#pymongo.mongo_client.MongoClient
        """

        MemoryHandler.__init__(self, capacity, flushLevel=flushLevel)

        self.client = None
        self.database = database
        self.collection = collection
        self.kwargs = kwargs

        self._connect(**kwargs)

        if create_collection:
            self._create_collection(collection_kwargs, **kwargs)
Example #10
0
 def __init__(self, target):
     MemoryHandler.__init__(self, 100000, target=target)
     self.setLevel(logging.ERROR)
Example #11
0
 def __init__(self, capacity=1000000, flushLevel=CRITICAL):
     nh = NullHandler()
     MemoryHandler.__init__(self, capacity,
                            flushLevel=flushLevel, target=nh)
Example #12
0
 def __init__(self, target):
     MemoryHandler.__init__(self, 100000, target=target)
     self.setLevel(logging.ERROR)
Example #13
0
 def __init__(self, flushInterval, **kwargs):
     MemoryHandler.__init__(self, **kwargs)
     self.__flushInterval = flushInterval
     self.__lastFlushTime = time.time()
     self.__condition = threading.Condition()
     self.__flusher = None
Example #14
0
File: ilog.py Project: opsteev/iUTF
 def __init__(self, capacity, flushLevel=logging.ERROR, target=None):
     MemoryHandler.__init__(self, capacity, flushLevel=flushLevel, target=target)
Example #15
0
 def __init__(self, capacity=1000000, flushLevel=logging.CRITICAL):
     nh = logging.NullHandler()
     MemoryHandler.__init__(self, capacity,
                            flushLevel=flushLevel, target=nh)